Skip to content

Commit

Permalink
hashlib: shake it up
Browse files Browse the repository at this point in the history
  • Loading branch information
widlarizer committed Sep 3, 2024
1 parent 0744fac commit 7679f15
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions kernel/hashlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<typename T> struct hash_ops {
static inline bool cmp(const T &a, const T &b) {
return a == b;
Expand Down

0 comments on commit 7679f15

Please sign in to comment.