From bc69c8f5edee0bf17685ed78c5b3637552ca19af Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 9 Nov 2021 08:24:48 +0100 Subject: Added final rotl to default_hash --- include/stc/ccommon.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index ea0a9d50..4f97344c 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -113,6 +113,8 @@ #define c_default_del(ptr) ((void) (ptr)) +/* Generic algorithms */ + #define _c_rotl(x, k) (x << (k) | x >> (8*sizeof(x) - (k))) STC_INLINE uint64_t c_strhash(const char *s) { @@ -125,16 +127,13 @@ 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 << 14; while ((len -= 2)) h = (h << 10) - h + *x++; - return h; + return _c_rotl(h, 24) ^ h; } - #define c_default_hash32(data, len_is_4) \ ((*(const uint32_t*)data * 0xc6a4a7935bd1e99d) >> 15) #define c_default_hash64(data, len_is_8) \ (*(const uint64_t *)data * 0xc6a4a7935bd1e99d) -/* Generic algorithms */ - #define c_foreach(...) c_MACRO_OVERLOAD(c_foreach, __VA_ARGS__) #define c_foreach_3(it, CX, cnt) \ for (CX##_iter it = CX##_begin(&cnt), it##_end_ = CX##_end(&cnt) \ -- cgit v1.2.3