Created
May 11, 2023 20:29
-
-
Save Reedbeta/d2b1fead04bc904c8b2e831be1d21a04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Derived from: https://github.com/Cyan4973/xxHash | |
// Specialized version of XXH64 for 64-bit inputs | |
constexpr uint64_t XXH_PRIME64_1 = 0x9E3779B185EBCA87ULL; | |
constexpr uint64_t XXH_PRIME64_2 = 0xC2B2AE3D27D4EB4FULL; | |
constexpr uint64_t XXH_PRIME64_3 = 0x165667B19E3779F9ULL; | |
constexpr uint64_t XXH_PRIME64_4 = 0x85EBCA77C2B2AE63ULL; | |
constexpr uint64_t XXH_PRIME64_5 = 0x27D4EB2F165667C5ULL; | |
inline uint64_t XXH64_round(uint64_t acc, uint64_t input) | |
{ | |
acc += input * XXH_PRIME64_2; | |
acc = std::rotl(acc, 31); | |
acc *= XXH_PRIME64_1; | |
return acc; | |
} | |
inline uint64_t XXH64_avalanche(uint64_t h64) | |
{ | |
h64 ^= h64 >> 33; | |
h64 *= XXH_PRIME64_2; | |
h64 ^= h64 >> 29; | |
h64 *= XXH_PRIME64_3; | |
h64 ^= h64 >> 32; | |
return h64; | |
} | |
inline uint64_t XXH64(uint64_t input, uint64_t seed = 0) | |
{ | |
uint64_t h64 = seed + XXH_PRIME64_5 + 8; | |
uint64_t const k1 = XXH64_round(0, input); | |
h64 ^= k1; | |
h64 = std::rotl(h64, 27) * XXH_PRIME64_1 + XXH_PRIME64_4; | |
return XXH64_avalanche(h64); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment