- introduce bitset

- add hash_block()
This commit is contained in:
Rongsong Shen 2026-02-13 11:01:23 +08:00
parent 2cf636e607
commit 48ea4a0205
8 changed files with 607 additions and 6 deletions

View file

@ -651,13 +651,29 @@ uint32_t hash64(uint64_t x)
return hash4(a, b, c, d);
}
#define RUN_HASH(hc, c) (((hc) << 5) + (hc) + (c))
uint32_t hash_block(char* buf, size_t len)
{
uint32_t hc = 5381;
int i;
for (i = 0; i < len; i++) {
int c = (int)buf[i];
hc = RUN_HASH(hc, c);
}
return hc;
}
uint32_t hash_string(const char* key)
{
uint32_t hc = 5381;
int c;
while ((c = *key++)) {
hc = ((hc << 5) + hc) + c;
hc = RUN_HASH(hc, c);
}
return hc;