the-algorithm/twml/libtwml/include/twml/utilities.h
Leon Banik ca2cc4c12f
Update utilities.h
Fix and optimize mixDiscreteIdAndValue() and mixStringIdAndValue() functions
2023-04-01 17:57:31 +02:00

22 lines
477 B
C++

#pragma once
#include <cstdint>
#include <cstring>
namespace twml {
inline int64_t mixDiscreteIdAndValue(int64_t key, int64_t value) {
key ^= ((17LL + value) * 2654435761LL);
return key;
}
inline int64_t mixStringIdAndValue(int64_t key, int32_t str_len, const uint8_t* str) {
const uint8_t* end = str + str_len;
while (str != end) {
key = (key * 31) + *str++;
}
return key;
}
} // namespace twml