mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-12-22 18:21:51 +01:00
Compare commits
2 Commits
3b02af76eb
...
17b7850b6c
Author | SHA1 | Date | |
---|---|---|---|
|
17b7850b6c | ||
|
ca2cc4c12f |
@ -1,18 +1,21 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifdef __cplusplus
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace twml {
|
namespace twml {
|
||||||
|
|
||||||
inline int64_t mixDiscreteIdAndValue(int64_t key, int64_t value) {
|
inline int64_t mixDiscreteIdAndValue(int64_t key, int64_t value) {
|
||||||
key ^= ((17LL + value) * 2654435761LL);
|
key ^= ((17LL + value) * 2654435761LL);
|
||||||
return key;
|
return key;
|
||||||
}
|
|
||||||
|
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
return key ^ hash;
|
|
||||||
}
|
inline int64_t mixStringIdAndValue(int64_t key, int32_t str_len, const uint8_t* str) {
|
||||||
}
|
const uint8_t* end = str + str_len;
|
||||||
#endif
|
while (str != end) {
|
||||||
|
key = (key * 31) + *str++;
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace twml
|
||||||
|
Loading…
Reference in New Issue
Block a user