summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-10-07 21:00:48 +0200
committerLennart Poettering <lennart@poettering.net>2011-10-07 21:00:48 +0200
commit7dfe96eebc1cde5d6b23d7879087ea9102943d7d (patch)
treefe8cfef91f3d244cdc56f6529bf78134ea4f362f /src
parent340047e95de331278fabc5515d089219dd1e6c6d (diff)
hashmap: use different version of DJB's hash algorithm that uses shifting instead of multiplication
Diffstat (limited to 'src')
-rw-r--r--src/hashmap.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/hashmap.c b/src/hashmap.c
index 0d89da4614..95ea45da48 100644
--- a/src/hashmap.c
+++ b/src/hashmap.c
@@ -124,11 +124,13 @@ __attribute__((destructor)) static void cleanup_pool(void) {
#endif
unsigned string_hash_func(const void *p) {
- unsigned hash = 0;
- const char *c;
+ unsigned hash = 5381;
+ const signed char *c;
+
+ /* DJB's hash function */
for (c = p; *c; c++)
- hash = 31 * hash + (unsigned) *c;
+ hash = (hash << 5) + hash + (unsigned) *c;
return hash;
}