Fix hash functions for keys whose size is not divisible by 4.
This commit is contained in:
parent
d1ec010660
commit
0ed0cc6f9c
1 changed files with 3 additions and 1 deletions
|
@ -27,10 +27,12 @@
|
||||||
static uint32_t hash_function(const void *p, size_t len) {
|
static uint32_t hash_function(const void *p, size_t len) {
|
||||||
const uint8_t *q = p;
|
const uint8_t *q = p;
|
||||||
uint32_t hash = 0;
|
uint32_t hash = 0;
|
||||||
while(len > 0) {
|
while(true) {
|
||||||
for(int i = len > 4 ? 4 : len; --i;)
|
for(int i = len > 4 ? 4 : len; --i;)
|
||||||
hash += q[i] << (8 * i);
|
hash += q[i] << (8 * i);
|
||||||
hash *= 0x9e370001UL; // Golden ratio prime.
|
hash *= 0x9e370001UL; // Golden ratio prime.
|
||||||
|
if(len <= 4)
|
||||||
|
break;
|
||||||
len -= 4;
|
len -= 4;
|
||||||
}
|
}
|
||||||
return hash;
|
return hash;
|
||||||
|
|
Loading…
Reference in a new issue