From bb201d5085cfb2e54ebad9a0bf22347a5251f7a2 Mon Sep 17 00:00:00 2001 From: Sara Date: Fri, 4 Oct 2024 11:11:45 +0200 Subject: [PATCH] feat: re-implemented hash function with multiplication hash --- strutil.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strutil.c b/strutil.c index c02490f..4c9ef4d 100644 --- a/strutil.c +++ b/strutil.c @@ -2,10 +2,10 @@ #include "string.h" uintptr_t strnhash(const char* s, size_t n) { - static const size_t shift = sizeof(uintptr_t) * 8 - 4; uintptr_t hash = 0; + static size_t const a = 33; for(size_t i = 0; i < n; ++i) { - hash = ((hash << 4) | s[i]) ^ (((uintptr_t)0xF << shift) & hash); + hash = ((hash*a) + s[i]); } return hash; }