2 "Murmur" hash provided by Austin, tanjent@gmail.com
3 http://murmurhash.googlepages.com/
5 Note - This code makes a few assumptions about how your machine behaves -
7 1. We can read a 4-byte value from any address without crashing
10 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 Updated to murmur2 hash - BP
18 #include <libhashkit/common.h>
20 uint32_t hashkit_murmur(const char *key
, size_t length
, void *context
)
23 'm' and 'r' are mixing constants generated offline. They're not
24 really 'magic', they just happen to work well.
27 const unsigned int m
= 0x5bd1e995;
28 const uint32_t seed
= (0xdeadbeef * (uint32_t)length
);
32 // Initialize the hash to a 'random' value
34 uint32_t h
= seed
^ (uint32_t)length
;
36 // Mix 4 bytes at a time into the hash
38 const unsigned char * data
= (const unsigned char *)key
;
43 unsigned int k
= *(unsigned int *)data
;
56 // Handle the last few bytes of the input array
60 case 3: h
^= ((uint32_t)data
[2]) << 16;
61 case 2: h
^= ((uint32_t)data
[1]) << 8;
68 Do a few final mixes of the hash to ensure the last few bytes are