Fix indexing of table for new hash function.
authorMichael Poole <mdpoole@troilus.org>
Sat, 9 Oct 2004 13:46:43 +0000 (13:46 +0000)
committerMichael Poole <mdpoole@troilus.org>
Sat, 9 Oct 2004 13:46:43 +0000 (13:46 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1237 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
ircd/hash.c

index 24bf3e710b6dceb34d6bbd963bbb50d7c190b82e..3636598ce2f2c51b4bfb8e49223ccb0ebd827a9e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2004-10-09  Michael Poole <mdpoole@troilus.org>
+
+       * ircd/hash.c: Fix thinko in hash function: It is not indexed
+       simply by character value, so we cannot just remap the values
+       by case.
+
 2004-10-05  Michael Poole <mdpoole@troilus.org>
 
        * ircd/hash.c: Replace the old hash function with one based on
index 7d335022e7e9ee13137cedf6fafc4e8e015b5b2e..03a54adaf519a6128afe0b379cdfade3fc0a4cad 100644 (file)
@@ -69,20 +69,14 @@ void init_hash(void)
     crc32hash[ii] = rand;
   }
 
-  /* Now reorder the hash table.  To make it case-insensitive, skip
-   * upper-case letters, and have lower-case letters write to the
-   * corresponding upper-case character.
-   */
+  /* Now reorder the hash table. */
   for (ii = 0, rand = 0; ii < 256; ii++)
   {
-    char ch = ii + CHAR_MIN;
-    if (ch != ToLower(ch))
-      continue;
     if (!rand)
       rand = ircrandom();
     poly = ii + rand % (256 - ii);
     jj = crc32hash[ii];
-    crc32hash[ToUpper(ch) - CHAR_MIN] = crc32hash[ii] = crc32hash[poly];
+    crc32hash[ii] = crc32hash[poly];
     crc32hash[poly] = jj;
     rand >>= 8;
   }
@@ -97,9 +91,9 @@ typedef unsigned int HASHREGS;
  */
 static HASHREGS strhash(const char *n)
 {
-  HASHREGS hash = crc32hash[*n++ & 255];
+  HASHREGS hash = crc32hash[ToLower(*n++) & 255];
   while (*n)
-    hash = (hash >> 8) ^ crc32hash[(hash ^ *n++) & 255];
+    hash = (hash >> 8) ^ crc32hash[(hash ^ ToLower(*n++)) & 255];
   return hash % HASHSIZE;
 }