From: Lennart Poettering Date: Fri, 7 Oct 2011 19:00:48 +0000 (+0200) Subject: hashmap: use different version of DJB's hash algorithm that uses shifting instead... X-Git-Tag: v37~26 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7dfe96eebc1cde5d6b23d7879087ea9102943d7d;p=systemd hashmap: use different version of DJB's hash algorithm that uses shifting instead of multiplication --- diff --git a/src/hashmap.c b/src/hashmap.c index 0d89da46..95ea45da 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; }