diff options
author | Simon Howard | 2007-06-16 16:02:46 +0000 |
---|---|---|
committer | Simon Howard | 2007-06-16 16:02:46 +0000 |
commit | c447a5da8c8087d94867560764b59f03d0e70b1d (patch) | |
tree | 8d2b6c3673aad804dd5c20764807ff194b8d178a | |
parent | a32623bfd5563cc087992023d75d8f45fdfbc10b (diff) | |
download | chocolate-doom-c447a5da8c8087d94867560764b59f03d0e70b1d.tar.gz chocolate-doom-c447a5da8c8087d94867560764b59f03d0e70b1d.tar.bz2 chocolate-doom-c447a5da8c8087d94867560764b59f03d0e70b1d.zip |
Switch to djb2 hash function and shut up compiler warnings
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 908
-rw-r--r-- | src/w_wad.c | 28 |
1 files 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; } // |