mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-12-22 10:11:52 +01:00
Merge ca2cc4c12f
into 72eda9a24f
This commit is contained in:
commit
3b02af76eb
@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace twml {
|
||||
|
||||
inline int64_t mixDiscreteIdAndValue(int64_t key, int64_t value) {
|
||||
@ -8,11 +11,11 @@ inline int64_t mixDiscreteIdAndValue(int64_t key, int64_t value) {
|
||||
}
|
||||
|
||||
inline int64_t mixStringIdAndValue(int64_t key, int32_t str_len, const uint8_t* str) {
|
||||
int32_t hash = 0;
|
||||
for (int32_t i = 0; i < str_len; i++) {
|
||||
hash = (31 * hash) + (int32_t)str[i];
|
||||
const uint8_t* end = str + str_len;
|
||||
while (str != end) {
|
||||
key = (key * 31) + *str++;
|
||||
}
|
||||
return key ^ hash;
|
||||
return key;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace twml
|
||||
|
Loading…
Reference in New Issue
Block a user