1 //-----------------------------------------------------------------------------
2 // MurmurHash2 was written by Austin Appleby, and is placed in the public
3 // domain. The author hereby disclaims copyright to this source code.
5 /* Obtained from https://github.com/aappleby/smhasher */
9 #include "murmurhash2.h"
12 murmurhash2(const void * key, int len, uint32_t seed)
14 // 'm' and 'r' are mixing constants generated offline.
15 // They're not really 'magic', they just happen to work well.
17 const uint32_t m = 0x5bd1e995;
20 // Initialize the hash to a 'random' value
22 uint32_t h = seed ^ len;
24 // Mix 4 bytes at a time into the hash
26 const unsigned char *data = (const unsigned char *)key;
30 uint32_t k = *(uint32_t*)data;
43 // Handle the last few bytes of the input array
47 case 3: h ^= data[2] << 16;
48 case 2: h ^= data[1] << 8;
53 // Do a few final mixes of the hash to ensure the last few
54 // bytes are well-incorporated.