From 7679f1567651a343fa1b7e4b45d857623b768198 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Thu, 22 Aug 2024 14:05:31 +0200 Subject: [PATCH] hashlib: shake it up --- kernel/hashlib.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/kernel/hashlib.h b/kernel/hashlib.h index 6b880f3a6..0d7431ab7 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -24,11 +24,6 @@ namespace hashlib { const int hashtable_size_trigger = 2; const int hashtable_size_factor = 3; -// The XOR version of DJB2 -inline unsigned int mkhash(unsigned int a, unsigned int b) { - return ((a << 5) + a) ^ b; -} - // traditionally 5381 is used as starting value for the djb2 hash const unsigned int mkhash_init = 5381; @@ -52,6 +47,15 @@ inline unsigned int mkhash_xorshift(unsigned int a) { return a; } +static int fudge = 123456; + +// The XOR version of DJB2 +inline unsigned int mkhash(unsigned int a, unsigned int b) { + unsigned int hash = ((a << 5) + a) ^ b; + hash = fudge ^ mkhash_xorshift(hash); + return hash; +} + template struct hash_ops { static inline bool cmp(const T &a, const T &b) { return a == b;