feat: re-implemented hash function with multiplication hash
parent
96323d7abc
commit
bb201d5085
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue