diff options
| author | Tyge Løvset <[email protected]> | 2021-11-08 22:11:01 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-11-08 22:11:01 +0100 |
| commit | d8fbc9c48ac3702bcf74ff7f32de40007884f6fd (patch) | |
| tree | d5e0276868291a8098529c3a12fe0099626d4bc3 | |
| parent | ff31ebc51932daf3fb3986b967fa27fe3a499c52 (diff) | |
| download | STC-modified-d8fbc9c48ac3702bcf74ff7f32de40007884f6fd.tar.gz STC-modified-d8fbc9c48ac3702bcf74ff7f32de40007884f6fd.zip | |
Last update on hash for now.
| -rw-r--r-- | include/stc/ccommon.h | 12 |
1 files 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;
}
|
