| 68 | // 64-bit hash for 64-bit platforms |
| 69 | |
| 70 | Y_NO_INLINE ui64 MurmurHash64(const void* key, size_t len, ui64 seed) noexcept { |
| 71 | const ui64 m = ULL(0xc6a4a7935bd1e995); |
| 72 | const int r = 47; |
| 73 | |
| 74 | ui64 h = seed ^ (len * m); |
| 75 | TUnalignedMemoryIterator<ui64> iter(key, len); |
| 76 | |
| 77 | while (!iter.AtEnd()) { |
| 78 | ui64 k = iter.Next(); |
| 79 | |
| 80 | k *= m; |
| 81 | k ^= k >> r; |
| 82 | k *= m; |
| 83 | |
| 84 | h ^= k; |
| 85 | h *= m; |
| 86 | } |
| 87 | |
| 88 | const unsigned char* data2 = iter.Last(); |
| 89 | |
| 90 | switch (iter.Left()) { |
| 91 | case 7: |
| 92 | h ^= ui64(data2[6]) << 48; |
| 93 | [[fallthrough]]; |
| 94 | |
| 95 | case 6: |
| 96 | h ^= ui64(data2[5]) << 40; |
| 97 | [[fallthrough]]; |
| 98 | |
| 99 | case 5: |
| 100 | h ^= ui64(data2[4]) << 32; |
| 101 | [[fallthrough]]; |
| 102 | |
| 103 | case 4: |
| 104 | h ^= ui64(data2[3]) << 24; |
| 105 | [[fallthrough]]; |
| 106 | |
| 107 | case 3: |
| 108 | h ^= ui64(data2[2]) << 16; |
| 109 | [[fallthrough]]; |
| 110 | |
| 111 | case 2: |
| 112 | h ^= ui64(data2[1]) << 8; |
| 113 | [[fallthrough]]; |
| 114 | |
| 115 | case 1: |
| 116 | h ^= ui64(data2[0]); |
| 117 | h *= m; |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | h ^= h >> r; |
| 122 | h *= m; |
| 123 | h ^= h >> r; |
| 124 | |
| 125 | return h; |
| 126 | } |
| 127 | } // namespace NMurmurPrivate |