]> mj.ucw.cz Git - libucw.git/commitdiff
Replaced the hash function. Damn it!
authorMartin Mares <mj@ucw.cz>
Thu, 13 Jul 2000 20:17:30 +0000 (20:17 +0000)
committerMartin Mares <mj@ucw.cz>
Thu, 13 Jul 2000 20:17:30 +0000 (20:17 +0000)
lib/db.c

index 6276e40ba34773f2073ab57395e20b7b8c6a92d8..8ccd3533f70d22db332fd58b0f18f3c757a14f9d 100644 (file)
--- a/lib/db.c
+++ b/lib/db.c
@@ -146,16 +146,13 @@ static u32
 sdbm_hash(byte *key, uns keylen)
 {
   /*
-   *  This is the same hash function as GDBM uses.
-   *  It seems to work well.
+   *  This used to be the same hash function as GDBM uses,
+   *  but it turned out that it tends to give the same results
+   *  on similar keys. Damn it.
    */
-  u32 value;
-  uns index;
-
-  /* Set the initial value from key. */
-  value = 0x238F13AF * keylen;
-  for (index = 0; index < keylen; index++)
-    value = value + (key[index] << (index*5 % 24));
+  u32 value = 0x238F13AF * keylen;
+  while (keylen--)
+    value = 37*value + *key++;
   return (1103515243 * value + 12345);
 }