summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-01-04 21:03:43 +0100
committerTyge Løvset <[email protected]>2022-01-04 21:03:43 +0100
commit9bb9a815ae49a23ffa7499ab779cbc8c79f57d56 (patch)
tree57aa9b78c12a66a613eb5979c2ae599f49c98790 /include
parentc8c82d3a333201010b1c0cf8aad804e721aec94e (diff)
downloadSTC-modified-9bb9a815ae49a23ffa7499ab779cbc8c79f57d56.tar.gz
STC-modified-9bb9a815ae49a23ffa7499ab779cbc8c79f57d56.zip
Fixed csview hash func.
Diffstat (limited to 'include')
-rw-r--r--include/stc/ccommon.h2
-rw-r--r--include/stc/csview.h2
2 files changed, 2 insertions, 2 deletions
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 ------------------------- */