From 083b37734c8cdfa285dcf2c665e172244dc23313 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 23 Nov 2021 07:07:41 +0100 Subject: BUGFIX: c_default_hash32() was buggy in ccommon.h - fixed. --- include/stc/ccommon.h | 10 +++++----- include/stc/template.h | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 0680dc2c..f71660b8 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -123,12 +123,12 @@ STC_INLINE uint64_t c_strhash(const char *s) { if (h) while ((c = *s++)) h = (h << 10) - h + c; return _c_rotl(h, 26) ^ h; } -// len = 2,4,6,...: +// len >= 1 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 _c_rotl(h, 24) ^ h; + const uint8_t *x = (const uint8_t*) key; + uint64_t h = *x++; + while (--len) h = (h << 10) - h + *x++; + return _c_rotl(h, 26) ^ h; } #define c_default_hash32(data, len_is_4) \ ((*(const uint32_t*)data * 0xc6a4a7935bd1e99d) >> 15) diff --git a/include/stc/template.h b/include/stc/template.h index 28c6879a..19ff97f2 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -116,6 +116,9 @@ #define i_tag i_key #endif #if !defined i_keyfrom && defined i_keydel + #ifdef STC_DEBUG + #error i_keydel defined, but not i_keyfrom. + #endif #define i_keyfrom c_no_clone #elif !defined i_keyfrom #define i_keyfrom c_default_fromraw @@ -143,6 +146,9 @@ #define i_tag i_val #endif #if !defined i_valfrom && defined i_valdel + #ifdef STC_DEBUG + #error i_del/i_valdel defined, but not i_valfrom. + #endif #define i_valfrom c_no_clone #elif !defined i_valfrom #define i_valfrom c_default_fromraw -- cgit v1.2.3