summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-09-17 12:14:10 +0200
committerTyge Løvset <[email protected]>2020-09-17 12:14:10 +0200
commit92edcbf8da88b1e59c7724f2875e9e9df3383cb1 (patch)
treec97a08a2202305ceae34ee2c3c661e1a4bcd7129
parent01426f1e82b60d319c3319391b43d84a8e613970 (diff)
downloadSTC-modified-92edcbf8da88b1e59c7724f2875e9e9df3383cb1.tar.gz
STC-modified-92edcbf8da88b1e59c7724f2875e9e9df3383cb1.zip
Fixed default hash16 and hash32.
-rw-r--r--examples/benchmark.c4
-rw-r--r--stc/cmap.h8
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<typename C> 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