aboutsummaryrefslogtreecommitdiff
path: root/util/hash.h
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2022-10-30 19:30:29 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2022-10-30 19:30:29 -0500
commit20e52f326cdf1b6c2ca9b2c0b5be07637d9196d2 (patch)
tree1d957cfd5ca8b9ccd0a91fa5d5415599edd241d1 /util/hash.h
downloadqidx-20e52f326cdf1b6c2ca9b2c0b5be07637d9196d2.tar.xz
qidx-20e52f326cdf1b6c2ca9b2c0b5be07637d9196d2.zip
Initial commit
Diffstat (limited to 'util/hash.h')
-rw-r--r--util/hash.h27
1 files changed, 27 insertions, 0 deletions
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 <stdint.h>
+#include <stddef.h>
+#include <string.h>
+
+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 */