1 //-----------------------------------------------------------------------------
2 // MurmurHash2, by Austin Appleby
4 // Note - This code makes a few assumptions about how your machine behaves -
6 // 1. We can read a 4-byte value from any address without crashing
9 // And it has a few limitations -
11 // 1. It will not work incrementally.
12 // 2. It will not produce the same results on little-endian and big-endian
15 static inline unsigned int murmur32 (const char *key, int len)
17 // 'm' and 'r' are mixing constants generated offline.
18 // They're not really 'magic', they just happen to work well.
20 const unsigned int m = 0x5bd1e995;
23 // Initialize the hash to a 'random' value
26 // Mix 4 bytes at a time into the hash
28 const unsigned char *data = (const unsigned char *)key;
32 uint32_t k = *(uint32_t *)data;
45 // Handle the last few bytes of the input array
49 case 3: h ^= data[2] << 16;
50 case 2: h ^= data[1] << 8;
55 // Do a few final mixes of the hash to ensure the last few
56 // bytes are well-incorporated.
65 static inline unsigned int murmur32_8b (uint64_t key)
67 return murmur32((char *)&key, 8);