]> err.no Git - systemd/commitdiff
hashmap: use different version of DJB's hash algorithm that uses shifting instead...
authorLennart Poettering <lennart@poettering.net>
Fri, 7 Oct 2011 19:00:48 +0000 (21:00 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 7 Oct 2011 19:00:48 +0000 (21:00 +0200)
src/hashmap.c

index 0d89da461406b30b022b0760289acd20e457b217..95ea45da4893662d42b569f16914acf6ec4101e9 100644 (file)
@@ -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;
 }