From b46359c11b879d610997eb1e9069e943e19c4244 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sun, 21 Jun 2026 12:38:06 +0200 Subject: lib: Add MurmurHash3 hash_mix64 for hash tables Adds a (non-cryptographic) MurmurHash3 fmix64 finalizer for hashing an integer key to a table index, replacing the MD5-based bucket hashing in the pft. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/lib/hash.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/lib/hash.c') diff --git a/src/lib/hash.c b/src/lib/hash.c index 9b26a552..903474df 100644 --- a/src/lib/hash.c +++ b/src/lib/hash.c @@ -74,8 +74,10 @@ uint16_t hash_len(enum hash_algo algo) { if (algo == HASH_CRC8) return CRC8_HASH_LEN; + if (algo == HASH_CRC16) return CRC16_HASH_LEN; + if (algo == HASH_CRC64) return CRC64_HASH_LEN; #ifdef HAVE_LIBGCRYPT @@ -164,3 +166,14 @@ void str_hash(enum hash_algo algo, { return mem_hash(algo, dst, (const uint8_t *) str, strlen(str)); } + +uint64_t hash_mix64(uint64_t key) +{ + key ^= key >> 33; + key *= 0xff51afd7ed558ccdULL; + key ^= key >> 33; + key *= 0xc4ceb9fe1a85ec53ULL; + key ^= key >> 33; + + return key; +} -- cgit v1.2.3