chiark / gitweb /
hashmap: use different version of DJB's hash algorithm that uses shifting instead...
[elogind.git] / 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;
 }