----------------------------------------------------------------------------- MurmurHash3 x86 32-bit ----------------------------------------------------------------------------- Based on the public‐domain implementation by Austin Appleby: https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp
| 20 | // Based on the public‐domain implementation by Austin Appleby: |
| 21 | // https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp |
| 22 | static inline u32 MurmurHash3_x86_32(const void *key, fl::size len, |
| 23 | u32 seed = 0) { |
| 24 | |
| 25 | FL_DISABLE_WARNING_PUSH; |
| 26 | FL_DISABLE_WARNING_IMPLICIT_FALLTHROUGH; |
| 27 | |
| 28 | const fl::u8 *data = static_cast<const fl::u8 *>(key); |
| 29 | const int nblocks = int(len / 4); |
| 30 | |
| 31 | u32 h1 = seed; |
| 32 | const u32 c1 = 0xcc9e2d51; |
| 33 | const u32 c2 = 0x1b873593; |
| 34 | |
| 35 | // body |
| 36 | const u32 *blocks = reinterpret_cast<const u32 *>(data); // ok reinterpret cast |
| 37 | for (int i = 0; i < nblocks; ++i) { |
| 38 | u32 k1 = blocks[i]; |
| 39 | k1 *= c1; |
| 40 | k1 = (k1 << 15) | (k1 >> 17); |
| 41 | k1 *= c2; |
| 42 | |
| 43 | h1 ^= k1; |
| 44 | h1 = (h1 << 13) | (h1 >> 19); |
| 45 | h1 = h1 * 5 + 0xe6546b64; |
| 46 | } |
| 47 | |
| 48 | // tail |
| 49 | const fl::u8 *tail = data + (nblocks * 4); |
| 50 | u32 k1 = 0; |
| 51 | switch (len & 3) { |
| 52 | case 3: |
| 53 | k1 ^= u32(tail[2]) << 16; |
| 54 | case 2: |
| 55 | k1 ^= u32(tail[1]) << 8; |
| 56 | case 1: |
| 57 | k1 ^= u32(tail[0]); |
| 58 | k1 *= c1; |
| 59 | k1 = (k1 << 15) | (k1 >> 17); |
| 60 | k1 *= c2; |
| 61 | h1 ^= k1; |
| 62 | } |
| 63 | |
| 64 | // finalization |
| 65 | h1 ^= u32(len); |
| 66 | // fmix32 |
| 67 | h1 ^= h1 >> 16; |
| 68 | h1 *= 0x85ebca6b; |
| 69 | h1 ^= h1 >> 13; |
| 70 | h1 *= 0xc2b2ae35; |
| 71 | h1 ^= h1 >> 16; |
| 72 | |
| 73 | return h1; |
| 74 | |
| 75 | FL_DISABLE_WARNING_POP; |
| 76 | } |
| 77 | |
| 78 | //----------------------------------------------------------------------------- |
| 79 | // Fast, cheap 32-bit integer hash (Thomas Wang) |
no test coverage detected