Use the better hash multiplier for __generic_hash
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 27 Sep 2017 21:20:57 +0000 (17:20 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 29 Sep 2017 14:00:03 +0000 (10:00 -0400)
I added Linux's hash.h a while back, but didn't update __generic_hash,
which was using the hardcoded GOLDEN_RATIO_PRIME_32.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/src/hashtable.c

index eff77cb..1465f2a 100644 (file)
@@ -14,6 +14,8 @@
 #include <string.h>
 #include <slab.h>
 #include <kmalloc.h>
+#include <hash.h>
+#include <arch/types.h>
 
 /*
 Credit for primes table: Aaron Krowne
@@ -48,10 +50,7 @@ void hashtable_init(void)
 /* Common hash/equals functions.  Don't call these directly. */
 size_t __generic_hash(void *k)
 {
-       /* 0x9e370001UL used by Linux (32 bit)
-        * (prime approx to the golden ratio to the max integer, IAW Knuth)
-        */
-       return (size_t)k * 0x9e370001UL;
+       return hash_long((unsigned long)k, BITS_PER_LONG);
 }
 
 ssize_t __generic_eq(void *k1, void *k2)