- introduce bitset
- add hash_block()
This commit is contained in:
parent
2cf636e607
commit
48ea4a0205
8 changed files with 607 additions and 6 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue