summaryrefslogtreecommitdiff
path: root/src/w_wad.c
diff options
context:
space:
mode:
authorSimon Howard2007-06-16 16:02:46 +0000
committerSimon Howard2007-06-16 16:02:46 +0000
commitc447a5da8c8087d94867560764b59f03d0e70b1d (patch)
tree8d2b6c3673aad804dd5c20764807ff194b8d178a /src/w_wad.c
parenta32623bfd5563cc087992023d75d8f45fdfbc10b (diff)
downloadchocolate-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
Diffstat (limited to 'src/w_wad.c')
-rw-r--r--src/w_wad.c28
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;
}
//