summaryrefslogtreecommitdiffhomepage
path: root/include/stc/ccommon.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/stc/ccommon.h')
-rw-r--r--include/stc/ccommon.h18
1 files changed, 10 insertions, 8 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index d7351611..56dd501e 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -117,19 +117,21 @@ 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;
}
+
STC_INLINE uint64_t c_default_hash(const void* key, size_t len) {
- if (!len) return 1;
+ uint64_t u8, h = 1;
+ uint32_t u4;
const uint8_t *x = (const uint8_t*) key;
- uint64_t h = *x++;
+ for (size_t n = len >> 3; n--; )
+ memcpy(&u8, x, 8), x += 8, h += u8*0xc6a4a7935bd1e99d;
+ switch (len &= 7) {
+ case 0: return h;
+ case 4: memcpy(&u4, x, 4); return h + u4*0xc6a4a7935bd1e99d;
+ }
+ h += *x++;
while (--len) h = (h << 10) - h + *x++;
return _c_ROTL(h, 26) ^ h;
}
-STC_INLINE uint64_t c_hash32(const void* key, size_t n) {
- return *(uint32_t *)key*0xc6a4a7935bd1e99d;
-}
-STC_INLINE uint64_t c_hash64(const void* key, size_t n) {
- return *(uint64_t *)key*0xc6a4a7935bd1e99d;
-}
STC_INLINE char* c_strnstrn(const char *s, const char *needle, size_t slen, const size_t nlen) {
if (!nlen) return (char *)s;