From 20e52f326cdf1b6c2ca9b2c0b5be07637d9196d2 Mon Sep 17 00:00:00 2001 From: flu0r1ne Date: Sun, 30 Oct 2022 19:30:29 -0500 Subject: Initial commit --- util/hash.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 util/hash.h (limited to 'util/hash.h') diff --git a/util/hash.h b/util/hash.h new file mode 100644 index 0000000..0c6a546 --- /dev/null +++ b/util/hash.h @@ -0,0 +1,27 @@ +#ifndef UTIL_HASH_H +#define UTIL_HASH_H + +#include +#include +#include + +uint64_t murmur_hash_64a(void const * key, int len, unsigned int seed); + +static inline uint64_t murmur_hash_str_64s(char const * str, unsigned int seed) { + return murmur_hash_64a(str, strlen(str), seed); +} + +static inline uint64_t murmur64(uint64_t h) { + h ^= h >> 33; + h *= 0xff51afd7ed558ccdLLU; + h ^= h >> 33; + h *= 0xc4ceb9fe1a85ec53LLU; + h ^= h >> 33; + return h; +} + +static inline size_t murmur64_range(uint64_t h, size_t n) { + return murmur64(h) % n; +} + +#endif /* ifndef UTIL_HASH_H */ -- cgit v1.2.3