summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-10-04 00:22:41 +0200
committerTom Gundersen <teg@jklm.no>2015-10-05 18:22:10 +0200
commitb826ab586c9e0a9c0d438a75c28cf3a8ab485929 (patch)
tree198d9f30b924468fc7d7dbf5fe9f05ce73809269 /src/shared
parent57217c8f2a2dea07b41ecf05000172ce77a90466 (diff)
hashmap: refactor hash_func
All our hash functions are based on siphash24(), factor out siphash_init() and siphash24_finalize() and pass the siphash state to the hash functions rather than the hash key. This simplifies the hash functions, and in particular makes composition simpler as calling siphash24_compress() repeatedly on separate chunks of input has the same effect as first concatenating the input and then calling siphash23_compress() on the result.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/dns-domain.c7
-rw-r--r--src/shared/dns-domain.h2
2 files changed, 3 insertions, 6 deletions
diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c
index 6dc04d51e4..1517443736 100644
--- a/src/shared/dns-domain.c
+++ b/src/shared/dns-domain.c
@@ -379,9 +379,8 @@ int dns_name_concat(const char *a, const char *b, char **_ret) {
return 0;
}
-unsigned long dns_name_hash_func(const void *s, const uint8_t hash_key[HASH_KEY_SIZE]) {
+void dns_name_hash_func(const void *s, struct siphash *state) {
const char *p = s;
- unsigned long ul = hash_key[0];
int r;
assert(p);
@@ -403,10 +402,8 @@ unsigned long dns_name_hash_func(const void *s, const uint8_t hash_key[HASH_KEY_
label[r] = 0;
ascii_strlower(label);
- ul = ul * hash_key[1] + ul + string_hash_func(label, hash_key);
+ string_hash_func(label, state);
}
-
- return ul;
}
int dns_name_compare_func(const void *a, const void *b) {
diff --git a/src/shared/dns-domain.h b/src/shared/dns-domain.h
index 8e73d9c20f..1f0d242c18 100644
--- a/src/shared/dns-domain.h
+++ b/src/shared/dns-domain.h
@@ -54,7 +54,7 @@ static inline int dns_name_is_valid(const char *s) {
return 1;
}
-unsigned long dns_name_hash_func(const void *s, const uint8_t hash_key[HASH_KEY_SIZE]);
+void dns_name_hash_func(const void *s, struct siphash *state);
int dns_name_compare_func(const void *a, const void *b);
extern const struct hash_ops dns_name_hash_ops;