From bdcbf12246cf6ee52fb1a606ffb2595b70932f8d Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 20 Oct 2024 19:59:26 +0200 Subject: [PATCH] add small quickncasehash function --- src/doomdef.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/doomdef.h b/src/doomdef.h index 046cd6897..875621a92 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -522,6 +522,22 @@ extern boolean capslock; // i_system.c, replace getchar() once the keyboard has been appropriated INT32 I_GetKey(void); +/* http://www.cse.yorku.ca/~oz/hash.html */ +static inline +UINT32 quickncasehash (const char *p, size_t n) +{ + size_t i = 0; + UINT32 x = 5381; + + while (i < n && p[i]) + { + x = (x * 33) ^ tolower(p[i]); + i++; + } + + return x; +} + #ifndef min // Double-Check with WATTCP-32's cdefs.h #define min(x, y) (((x) < (y)) ? (x) : (y)) #endif