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 */
10 #include "murmurhash2.h"
13 murmurhash2(const unsigned char * key
, int len
, uint32_t seed
)
15 // 'm' and 'r' are mixing constants generated offline.
16 // They're not really 'magic', they just happen to work well.
18 const uint32_t m
= 0x5bd1e995;
21 // Initialize the hash to a 'random' value
23 uint32_t h
= seed
^ len
;
25 // Mix 4 bytes at a time into the hash
27 const unsigned char *data
= key
;
33 memcpy(&k
, data
, sizeof(k
));
46 // Handle the last few bytes of the input array
50 case 3: h
^= data
[2] << 16;
51 case 2: h
^= data
[1] << 8;
56 // Do a few final mixes of the hash to ensure the last few
57 // bytes are well-incorporated.