move djbhash into general availability as h_djbhash

This commit is contained in:
Sven M. Hallberg 2013-06-06 13:01:54 +02:00
parent b959bcb5c7
commit e7a388d1c7
3 changed files with 12 additions and 10 deletions

View file

@ -329,6 +329,15 @@ bool h_eq_ptr(const void *p, const void *q) {
}
HHashValue h_hash_ptr(const void *p) {
// XXX just djbhash it
// XXX just djbhash it? it does make the benchmark ~7% slower.
//return h_djbhash((const uint8_t *)&p, sizeof(void *));
return (uintptr_t)p >> 4;
}
uint32_t h_djbhash(const uint8_t *buf, size_t len) {
uint32_t hash = 5381;
while (len--) {
hash = hash * 33 + *buf++;
}
return hash;
}