1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
6 * @defgroup murmurhash Murmurhash
9 * @brief Hash calculation using murmurhash algorithm
11 * MurmurHash3 is a hash implementation that was written by Austin Appleby, and
12 * is placed in the public domain. The author hereby disclaims copyright to this
16 #ifndef ECOLI_MURMURHASH_H_
17 #define ECOLI_MURMURHASH_H_
22 static inline uint32_t ec_murmurhash_rotl32(uint32_t x, int8_t r)
24 return (x << r) | (x >> (32 - r));
27 /** Add 32-bit to the hash */
28 static inline uint32_t ec_murmurhash3_add32(uint32_t h, uint32_t data)
31 data = ec_murmurhash_rotl32(data, 15);
37 /** Intermediate mix */
38 static inline uint32_t ec_murmurhash3_mix32(uint32_t h)
40 h = ec_murmurhash_rotl32(h,13);
41 h = h * 5 +0xe6546b64;
45 /** Final mix: force all bits of a hash block to avalanche */
46 static inline uint32_t ec_murmurhash3_fmix32(uint32_t h)
58 * Calculate a 32-bit murmurhash3
61 * The key (the unaligned variable-length array of bytes).
63 * The length of the key, counting by bytes.
65 * Can be any 4-byte value initialization value.
69 uint32_t ec_murmurhash3(const void *key, int len, uint32_t seed);
71 #endif /* ECOLI_MURMURHASH_H_ */