diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-12-22 19:59:12 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-12-22 21:12:25 +0100 |
commit | 9bf3b53533cdc9b95c921b71da755401f223f765 (patch) | |
tree | 812e99b25cc09f5d5d3b130d25a02754283ff7a7 /src/journal/catalog.c | |
parent | 14f862a508ee64466fa8b3f036797d472f4d03ed (diff) |
shared: switch our hash table implementation over to SipHash
SipHash appears to be the new gold standard for hashing smaller strings
for hashtables these days, so let's make use of it.
Diffstat (limited to 'src/journal/catalog.c')
-rw-r--r-- | src/journal/catalog.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/src/journal/catalog.c b/src/journal/catalog.c index e3a3354ab7..2823232cbf 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -39,6 +39,7 @@ #include "conf-files.h" #include "mkdir.h" #include "catalog.h" +#include "siphash24.h" const char * const catalog_file_dirs[] = { "/usr/local/lib/systemd/catalog/", @@ -63,28 +64,21 @@ typedef struct CatalogItem { le64_t offset; } CatalogItem; -unsigned catalog_hash_func(const void *p) { +unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) { const CatalogItem *i = p; + uint64_t u; + size_t l, sz; + void *v; - assert_cc(sizeof(unsigned) == sizeof(uint8_t)*4); - - return (((unsigned) i->id.bytes[0] << 24) | - ((unsigned) i->id.bytes[1] << 16) | - ((unsigned) i->id.bytes[2] << 8) | - ((unsigned) i->id.bytes[3])) ^ - (((unsigned) i->id.bytes[4] << 24) | - ((unsigned) i->id.bytes[5] << 16) | - ((unsigned) i->id.bytes[6] << 8) | - ((unsigned) i->id.bytes[7])) ^ - (((unsigned) i->id.bytes[8] << 24) | - ((unsigned) i->id.bytes[9] << 16) | - ((unsigned) i->id.bytes[10] << 8) | - ((unsigned) i->id.bytes[11])) ^ - (((unsigned) i->id.bytes[12] << 24) | - ((unsigned) i->id.bytes[13] << 16) | - ((unsigned) i->id.bytes[14] << 8) | - ((unsigned) i->id.bytes[15])) ^ - string_hash_func(i->language); + l = strlen(i->language); + sz = sizeof(i->id) + l; + v = alloca(sz); + + memcpy(mempcpy(v, &i->id, sizeof(i->id)), i->language, l); + + siphash24((uint8_t*) &u, v, sz, hash_key); + + return (unsigned long) u; } int catalog_compare_func(const void *a, const void *b) { |