3 * https://sites.google.com/site/murmurhash/
5 * MurmurHash3 was written by Austin Appleby, and is placed in the public
6 * domain. The author hereby disclaims copyright to this source code.
8 * Eric Wong trivially ported this to C for Ruby tdb (32-bit version only)
12 #define FORCE_INLINE __attribute__((always_inline))
14 static inline uint32_t rotl32(uint32_t x
, int8_t r
)
16 return (x
<< r
) | (x
>> (32 - r
));
19 #define ROTL32(x,y) rotl32(x,y)
21 #define BIG_CONSTANT(x) (x##LLU)
23 /* ----------------------------------------------------------------------------
24 * Block read - if your platform needs to do endian-swapping or can only
25 * handle aligned reads, do the conversion here
28 static FORCE_INLINE
uint32_t getblock(const uint32_t * p
, int i
)
33 /* ----------------------------------------------------------------------------
34 * Finalization mix - force all bits of a hash block to avalanche
37 static FORCE_INLINE
uint32_t fmix(uint32_t h
)
48 unsigned int rbtdb_murmur3a(TDB_DATA
* key
)
50 const uint8_t *data
= key
->dptr
;
51 int len
= (int)key
->dsize
;
52 const int nblocks
= len
/ 4;
53 static const uint32_t seed
;
57 static const uint32_t c1
= 0xcc9e2d51;
58 static const uint32_t c2
= 0x1b873593;
61 const uint32_t *blocks
= (const uint32_t *)(data
+ nblocks
* 4);
63 for (i
= -nblocks
; i
; i
++) {
64 uint32_t k1
= getblock(blocks
, i
);
72 h1
= h1
* 5 + 0xe6546b64;
77 const uint8_t *tail
= (const uint8_t *)(data
+ nblocks
* 4);