diff options
| author | Tyge Løvset <[email protected]> | 2021-11-09 08:24:48 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-11-09 08:24:48 +0100 |
| commit | bc69c8f5edee0bf17685ed78c5b3637552ca19af (patch) | |
| tree | 389482a839ecfbe49528e78f7afc72640feaf5a4 | |
| parent | d8fbc9c48ac3702bcf74ff7f32de40007884f6fd (diff) | |
| download | STC-modified-bc69c8f5edee0bf17685ed78c5b3637552ca19af.tar.gz STC-modified-bc69c8f5edee0bf17685ed78c5b3637552ca19af.zip | |
Added final rotl to default_hash
| -rw-r--r-- | include/stc/ccommon.h | 7 |
1 files changed, 3 insertions, 4 deletions
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) \
|
