From 92edcbf8da88b1e59c7724f2875e9e9df3383cb1 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 17 Sep 2020 12:14:10 +0200 Subject: Fixed default hash16 and hash32. --- examples/benchmark.c | 4 ++-- stc/cmap.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/benchmark.c b/examples/benchmark.c index 969cf3cc..7b0e1fa5 100644 --- a/examples/benchmark.c +++ b/examples/benchmark.c @@ -18,11 +18,11 @@ template inline void destroy_me(C& c) { C().swap(c); } // Visual Studio: compile with -TP to force C++: cl -TP -EHsc -O2 benchmark.c static inline uint32_t fibonacci_hash(const void* data, size_t len) { - return ((*(const uint64_t *) data) * 11400714819323198485llu) >> 24; + return (uint32_t) (((*(const uint64_t *) data) * 11400714819323198485llu) >> 24); } // cmap and khash template expansion -typedef_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash); +typedef_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash); // c_default_hash16); KHASH_MAP_INIT_INT64(ii, int64_t) diff --git a/stc/cmap.h b/stc/cmap.h index ab2abf45..e725d264 100644 --- a/stc/cmap.h +++ b/stc/cmap.h @@ -443,15 +443,15 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; STC_API uint32_t c_default_hash16(const void *data, size_t len) { const volatile uint16_t *key = (const uint16_t *) data; - uint64_t x = 0xc613fc15u; - while (len -= 2) x = ((*key++ + x) * 2654435769ull) >> 13; + uint64_t x = *key++ * 0xc613fc15u; + while (len -= 2) x = (*key++ + x) * 2654435769ull; return (uint32_t) x; } STC_API uint32_t c_default_hash32(const void* data, size_t len) { const volatile uint32_t *key = (const uint32_t *) data; uint64_t x = *key++ * 2654435769ull; - while (len -= 4) x ^= *key++ * 2654435769ull; - return (uint32_t) (x >> 24); + while (len -= 4) x = (*key++ + x) * 2654435769ull; + return (uint32_t) x; } #else -- cgit v1.2.3