From: Michael Poole Date: Sat, 9 Oct 2004 13:46:43 +0000 (+0000) Subject: Fix indexing of table for new hash function. X-Git-Url: http://git.pk910.de/?a=commitdiff_plain;h=a98560e36a49dc7fc0da82f516c9a33a7c8878fe;p=ircu2.10.12-pk.git Fix indexing of table for new hash function. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1237 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- diff --git a/ChangeLog b/ChangeLog index 24bf3e7..3636598 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-10-09 Michael Poole + + * 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 * ircd/hash.c: Replace the old hash function with one based on diff --git a/ircd/hash.c b/ircd/hash.c index 7d33502..03a54ad 100644 --- a/ircd/hash.c +++ b/ircd/hash.c @@ -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; }