From 9bb9a815ae49a23ffa7499ab779cbc8c79f57d56 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 4 Jan 2022 21:03:43 +0100 Subject: Fixed csview hash func. --- include/stc/ccommon.h | 2 +- include/stc/csview.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index dd2401a9..60e12433 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -121,8 +121,8 @@ 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 >= 1 STC_INLINE uint64_t c_default_hash(const void* key, size_t len) { + if (!len) return 1; const uint8_t *x = (const uint8_t*) key; uint64_t h = *x++; while (--len) h = (h << 10) - h + *x++; diff --git a/include/stc/csview.h b/include/stc/csview.h index 0995e698..d6492649 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -118,7 +118,7 @@ STC_INLINE int csview_cmp(const csview* x, const csview* y) { const int c = memcmp(x->str, y->str, m); return c ? c : x->size - y->size; } -#define csview_hash(xp, dummy) c_strhash((xp)->str) +#define csview_hash(xp, dummy) c_default_hash((xp)->str, (xp)->size) #define csview_eq(xp, yp) (!csview_cmp(xp, yp)) /* -------------------------- IMPLEMENTATION ------------------------- */ -- cgit v1.2.3