From d8fbc9c48ac3702bcf74ff7f32de40007884f6fd Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Mon, 8 Nov 2021 22:11:01 +0100 Subject: Last update on hash for now. --- include/stc/ccommon.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index f0e4cb2a..ea0a9d50 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -116,15 +116,15 @@ #define _c_rotl(x, k) (x << (k) | x >> (8*sizeof(x) - (k))) STC_INLINE uint64_t c_strhash(const char *s) { - int c; uint64_t h = (uint64_t)*s++ << 26; - if (h) while ((c = *s++)) h = ((h << 5) - h) + c; - return h; + int c; uint64_t h = *s++; + if (h) while ((c = *s++)) h = (h << 10) - h + c; + return _c_rotl(h, 26) ^ h; } -// len >= 2 and multiple of 16: +// len = 2,4,6,...: STC_INLINE uint64_t c_default_hash(const void* key, size_t len) { const uint16_t *x = (const uint16_t*) key; - uint64_t h = *x++; h += h << 11; - while ((len -= 2)) h ^= (h << 9) + *x++; + uint64_t h = *x++; h += h << 14; + while ((len -= 2)) h = (h << 10) - h + *x++; return h; } -- cgit v1.2.3