move djbhash into general availability as h_djbhash
This commit is contained in:
parent
b959bcb5c7
commit
e7a388d1c7
3 changed files with 12 additions and 10 deletions
|
|
@ -3,14 +3,6 @@
|
||||||
#include "../internal.h"
|
#include "../internal.h"
|
||||||
#include "../parsers/parser_internal.h"
|
#include "../parsers/parser_internal.h"
|
||||||
|
|
||||||
static uint32_t djbhash(const uint8_t *buf, size_t len) {
|
|
||||||
uint32_t hash = 5381;
|
|
||||||
while (len--) {
|
|
||||||
hash = hash * 33 + *buf++;
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
// short-hand for constructing HCachedResult's
|
// short-hand for constructing HCachedResult's
|
||||||
static HCachedResult *cached_result(const HParseState *state, HParseResult *result) {
|
static HCachedResult *cached_result(const HParseState *state, HParseResult *result) {
|
||||||
HCachedResult *ret = a_new(HCachedResult, 1);
|
HCachedResult *ret = a_new(HCachedResult, 1);
|
||||||
|
|
@ -214,7 +206,7 @@ void h_packrat_free(HParser *parser) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t cache_key_hash(const void* key) {
|
static uint32_t cache_key_hash(const void* key) {
|
||||||
return djbhash(key, sizeof(HParserCacheKey));
|
return h_djbhash(key, sizeof(HParserCacheKey));
|
||||||
}
|
}
|
||||||
static bool cache_key_equal(const void* key1, const void* key2) {
|
static bool cache_key_equal(const void* key1, const void* key2) {
|
||||||
return memcmp(key1, key2, sizeof(HParserCacheKey)) == 0;
|
return memcmp(key1, key2, sizeof(HParserCacheKey)) == 0;
|
||||||
|
|
|
||||||
|
|
@ -329,6 +329,15 @@ bool h_eq_ptr(const void *p, const void *q) {
|
||||||
}
|
}
|
||||||
|
|
||||||
HHashValue h_hash_ptr(const void *p) {
|
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;
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -276,6 +276,7 @@ bool h_hashset_equal(const HHashSet *a, const HHashSet *b);
|
||||||
|
|
||||||
bool h_eq_ptr(const void *p, const void *q);
|
bool h_eq_ptr(const void *p, const void *q);
|
||||||
HHashValue h_hash_ptr(const void *p);
|
HHashValue h_hash_ptr(const void *p);
|
||||||
|
uint32_t h_djbhash(const uint8_t *buf, size_t len);
|
||||||
|
|
||||||
typedef struct HCFSequence_ HCFSequence;
|
typedef struct HCFSequence_ HCFSequence;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue