From 7dfe96eebc1cde5d6b23d7879087ea9102943d7d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 7 Oct 2011 21:00:48 +0200 Subject: hashmap: use different version of DJB's hash algorithm that uses shifting instead of multiplication --- src/hashmap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/hashmap.c b/src/hashmap.c index 0d89da461..95ea45da4 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; } -- cgit v1.2.3