Using a non-stupid hash function is EXTREMELY important

This commit is contained in:
Tony Garnock-Jones 2015-06-30 16:56:29 -04:00
parent 4fda08adc0
commit 08f2400e49
1 changed files with 19 additions and 32 deletions

View File

@ -10,31 +10,31 @@
typedef uint32_t tt_hash_t; typedef uint32_t tt_hash_t;
/* /\* Customized special-purpose fasthash variation *\/ */ /* Customized special-purpose fasthash variation */
/* #define mix(h) ({ \ */ #define mix(h) ({ \
/* (h) ^= (h) >> 23; \ */ (h) ^= (h) >> 23; \
/* (h) *= 0x2127599bf4325c37ULL; \ */ (h) *= 0x2127599bf4325c37ULL; \
/* (h) ^= (h) >> 47; }) */ (h) ^= (h) >> 47; })
/* static inline uint64_t fasthash_4_ints(uint32_t v1, uint32_t v2, uint32_t v3, uint32_t v4) { */ static inline uint64_t fasthash_4_ints(uint32_t v1, uint32_t v2, uint32_t v3, uint32_t v4) {
/* const uint64_t m = 0x880355f21e6d1965ULL; */ const uint64_t m = 0x880355f21e6d1965ULL;
/* uint64_t h = (16 * m); */ uint64_t h = (16 * m);
/* uint64_t v; */ uint64_t v;
/* v = (((uint64_t) v2) << 32) | v1; */ v = (((uint64_t) v2) << 32) | v1;
/* h ^= mix(v); */ h ^= mix(v);
/* h *= m; */ h *= m;
/* v = (((uint64_t) v4) << 32) | v3; */ v = (((uint64_t) v4) << 32) | v3;
/* h ^= mix(v); */ h ^= mix(v);
/* h *= m; */ h *= m;
/* return mix(h); */ return mix(h);
/* } */ }
static inline tt_hash_t hash(uint32_t tag, static inline tt_hash_t hash(uint32_t tag,
uint32_t index, uint32_t index,
tt_node_ptr_t a, tt_node_ptr_t a,
tt_node_ptr_t b) tt_node_ptr_t b)
{ {
/* uint64_t x = fasthash_4_ints(tag, index, a, b); */ uint64_t x = fasthash_4_ints(tag, index, a, b);
/* return x - (x >> 32); */ return x - (x >> 32);
/* uint32_t keyblock[4] = { tag, */ /* uint32_t keyblock[4] = { tag, */
/* index, */ /* index, */
@ -42,19 +42,6 @@ static inline tt_hash_t hash(uint32_t tag,
/* b }; */ /* b }; */
/* assert(sizeof(keyblock) == 4 * sizeof(uint32_t)); */ /* assert(sizeof(keyblock) == 4 * sizeof(uint32_t)); */
/* return (tt_hash_t) fasthash32(keyblock, sizeof(keyblock), 0); */ /* return (tt_hash_t) fasthash32(keyblock, sizeof(keyblock), 0); */
/* uint64_t x = tag; */
/* x = (x << 8) ^ index; */
/* x = (x << 8) ^ a; */
/* x = (x << 8) ^ b; */
/* return x - (x >> 32); */
uint64_t x = index * 11;
x *= 11;
x ^= a;
x *= 11;
x ^= b * tag;
return x - (x >> 32);
} }
static inline tt_hash_t tt_hash_node(tt_arena_t *a, tt_node_ptr_t p) { static inline tt_hash_t tt_hash_node(tt_arena_t *a, tt_node_ptr_t p) {