summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-02-26 13:48:58 +0100
committerTyge Løvset <[email protected]>2021-02-26 13:48:58 +0100
commitdc6b7f9517b81da984a4c795213861e8ea61ce20 (patch)
tree2c0e80b760fcadf4457d60d4089f5741978ea7b8
parentfc1f2403e813e9850eecacd5580831f733417a12 (diff)
downloadSTC-modified-dc6b7f9517b81da984a4c795213861e8ea61ce20.tar.gz
STC-modified-dc6b7f9517b81da984a4c795213861e8ea61ce20.zip
Some improvements in hash functions.
-rw-r--r--stc/cmap.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/stc/cmap.h b/stc/cmap.h
index 0252e14e..d5fae750 100644
--- a/stc/cmap.h
+++ b/stc/cmap.h
@@ -339,9 +339,9 @@ typedef struct {size_t idx; uint32_t hx;} chash_bucket_t;
STC_API uint64_t c_default_hash(const void *data, size_t len);
STC_INLINE uint64_t c_default_hash32(const void* data, size_t ignored)
- {return *(const uint32_t *)data * 2654435769u;}
+ {return *(const uint32_t *)data * 0xc6a4a7935bd1e99d;}
STC_INLINE uint64_t c_default_hash64(const void* data, size_t ignored)
- {return *(const uint64_t *)data * 11400714819323198485ull;}
+ {return *(const uint64_t *)data * 0xc6a4a7935bd1e99d;}
/* -------------------------- IMPLEMENTATION ------------------------- */
@@ -481,10 +481,10 @@ enum {chash_HASH = 0x7f, chash_USED = 0x80};
}
STC_DEF uint64_t c_default_hash(const void *key, size_t len) {
- const uint64_t m = 0xc6a4a7935bd1e995;
+ const uint64_t m = 0xb5ad4eceda1ce2a9;
uint64_t k, h = m + len;
const uint8_t *p = (const uint8_t *)key, *end = p + (len & ~7ull);
- for (; p != end; p += 8) {memcpy(&k, p, 8); h ^= k*m;}
+ for (; p != end; p += 8) {memcpy(&k, p, 8); h ^= m*k;}
switch (len & 7) {
case 7: h ^= (uint64_t) p[6] << 48;
case 6: h ^= (uint64_t) p[5] << 40;