diff options
| author | gingerBill <bill@gingerbill.org> | 2020-05-27 18:23:37 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-05-27 18:23:37 +0100 |
| commit | 1a0614b0d7f4b6010d79ac0a402d3c4c1f389529 (patch) | |
| tree | aeee6f81470fe8f9ed0d918008272ed081a099bd /src/murmurhash3.cpp | |
| parent | 876820789e9dedaa6198c4cd145702485e3bd21c (diff) | |
Improve performance of tokenization and parsing
Diffstat (limited to 'src/murmurhash3.cpp')
| -rw-r--r-- | src/murmurhash3.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/murmurhash3.cpp b/src/murmurhash3.cpp index ff51cf733..7465fac18 100644 --- a/src/murmurhash3.cpp +++ b/src/murmurhash3.cpp @@ -223,3 +223,36 @@ void MurmurHash3_x86_128(void const *key, isize len, u32 seed, void *out) { // } + + +gb_internal gb_inline u32 murmur_32_scramble(u32 k) { + k *= 0xcc9e2d51; + k = (k << 15) | (k >> 17); + k *= 0x1b873593; + return k; +} + +u32 murmur3_32(u8 const *key, isize len, u32 seed) { + u32 h = seed; + u32 k; + for (size_t i = len >> 2; i; i--) { + memcpy(&k, key, sizeof(u32)); + key += sizeof(u32); + h ^= murmur_32_scramble(k); + h = (h << 13) | (h >> 19); + h = h * 5 + 0xe6546b64; + } + k = 0; + for (size_t i = len & 3; i; i--) { + k <<= 8; + k |= key[i - 1]; + } + h ^= murmur_32_scramble(k); + h ^= len; + h ^= h >> 16; + h *= 0x85ebca6b; + h ^= h >> 13; + h *= 0xc2b2ae35; + h ^= h >> 16; + return h; +} |