1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
6 * MurmurHash3 is a hash implementation that was written by Austin Appleby, and
7 * is placed in the public domain. The author hereby disclaims copyright to this
11 #ifndef ECOLI_MURMURHASH_H_
12 #define ECOLI_MURMURHASH_H_
17 static inline uint32_t ec_murmurhash_rotl32(uint32_t x, int8_t r)
19 return (x << r) | (x >> (32 - r));
22 /** Add 32-bit to the hash */
23 static inline uint32_t ec_murmurhash3_add32(uint32_t h, uint32_t data)
26 data = ec_murmurhash_rotl32(data, 15);
32 /** Intermediate mix */
33 static inline uint32_t ec_murmurhash3_mix32(uint32_t h)
35 h = ec_murmurhash_rotl32(h,13);
36 h = h * 5 +0xe6546b64;
40 /** Final mix: force all bits of a hash block to avalanche */
41 static inline uint32_t ec_murmurhash3_fmix32(uint32_t h)
53 * Calculate a 32-bit murmurhash3
56 * The key (the unaligned variable-length array of bytes).
58 * The length of the key, counting by bytes.
60 * Can be any 4-byte value initialization value.
64 uint32_t ec_murmurhash3(const void *key, int len, uint32_t seed);
66 #endif /* ECOLI_MURMURHASH_H_ */