diff options
| author | Tyge Løvset <[email protected]> | 2021-11-23 07:07:41 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-11-23 07:07:41 +0100 |
| commit | 083b37734c8cdfa285dcf2c665e172244dc23313 (patch) | |
| tree | 7fad389a30690e2a7fefdf0403432b3046872a9f /include | |
| parent | ddeb0603e1ce90cee843e59708ce80c24589d14d (diff) | |
| download | STC-modified-083b37734c8cdfa285dcf2c665e172244dc23313.tar.gz STC-modified-083b37734c8cdfa285dcf2c665e172244dc23313.zip | |
BUGFIX: c_default_hash32() was buggy in ccommon.h - fixed.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/ccommon.h | 10 | ||||
| -rw-r--r-- | include/stc/template.h | 6 |
2 files changed, 11 insertions, 5 deletions
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
|
