Committer  : entrope
CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Commit time: 2004-10-09 13:46:54 UTC

Modified files:
     ircd/hash.c ChangeLog

Log message:

Fix indexing of table for new hash function.

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.482 ircu2.10/ChangeLog:1.483
--- ircu2.10/ChangeLog:1.482    Tue Oct  5 19:28:05 2004
+++ ircu2.10/ChangeLog  Sat Oct  9 06:46:43 2004
@@ -1,3 +1,9 @@
+2004-10-09  Michael Poole <[EMAIL PROTECTED]>
+
+       * 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 <[EMAIL PROTECTED]>
 
        * ircd/hash.c: Replace the old hash function with one based on
Index: ircu2.10/ircd/hash.c
diff -u ircu2.10/ircd/hash.c:1.11 ircu2.10/ircd/hash.c:1.12
--- ircu2.10/ircd/hash.c:1.11   Tue Oct  5 19:28:07 2004
+++ ircu2.10/ircd/hash.c        Sat Oct  9 06:46:43 2004
@@ -41,7 +41,7 @@
 
 /** @file
  * @brief Hash table management.
- * @version $Id: hash.c,v 1.11 2004/10/06 02:28:07 entrope Exp $
+ * @version $Id: hash.c,v 1.12 2004/10/09 13:46:43 entrope Exp $
  *
  * This file used to use some very complicated hash function.  Now it
  * uses CRC-32, but effectively remaps each input byte according to a
@@ -69,20 +69,14 @@
     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 @@
  */
 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;
 }
 
----------------------- End of diff -----------------------

Reply via email to