From c447a5da8c8087d94867560764b59f03d0e70b1d Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 16 Jun 2007 16:02:46 +0000 Subject: Switch to djb2 hash function and shut up compiler warnings Subversion-branch: /trunk/chocolate-doom Subversion-revision: 908 --- src/w_wad.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 892086d7..598794c4 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -98,25 +98,21 @@ static void ExtractFileBase(char *path, char *dest) } // Hash function used for lump names. -// Must be mod'ed with table size. -// Can be used for any 8-character names. -// by Lee Killough unsigned int W_LumpNameHash(const char *s) { - unsigned int hash; - - ((hash = toupper(s[0]), s[1]) && - (hash = hash*3+toupper(s[1]), s[2]) && - (hash = hash*2+toupper(s[2]), s[3]) && - (hash = hash*2+toupper(s[3]), s[4]) && - (hash = hash*2+toupper(s[4]), s[5]) && - (hash = hash*2+toupper(s[5]), s[6]) && - (hash = hash*2+toupper(s[6]), - hash = hash*2+toupper(s[7])) - ); - - return hash; + // This is the djb2 string hash function, modded to work on strings + // that have a maximum length of 8. + + unsigned int result = 5381; + unsigned int i; + + for (i=0; i < 8 && s[i] != '\0'; ++i) + { + result = ((result << 5) ^ result ) ^ toupper(s[i]); + } + + return result; } // -- cgit v1.2.3