summaryrefslogtreecommitdiff
path: root/insert_string.c
diff options
context:
space:
mode:
authorNathan Moinvaziri <nathan@nathanm.com>2020-04-30 21:05:05 -0700
committerHans Kristian Rosbach <hk-github@circlestorm.org>2020-05-24 14:32:26 +0200
commit07207681ed29d6cc7528df9d5cf8f587c6199a1c (patch)
tree85f008dc8b81a40258e346d20068246d53ce57a2 /insert_string.c
parent600dcc301259f006af5e7141ae9b7129d24f23ef (diff)
Simplify generic hash function using knuth's multiplicative hash.
Diffstat (limited to 'insert_string.c')
-rw-r--r--insert_string.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/insert_string.c b/insert_string.c
index e9efd51..774d18a 100644
--- a/insert_string.c
+++ b/insert_string.c
@@ -15,16 +15,8 @@
* previous key instead of complete recalculation each time.
*/
-#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
-# define UPDATE_HASH(s, h, val) \
- h = (3483 * ((val) & 0xff) +\
- 23081 * (((val) >> 8) & 0xff) +\
- 6954 * (((val) >> 16) & 0xff) +\
- 20947 * (((val) >> 24) & 0xff));
-#else
-# define UPDATE_HASH(s, h, val)\
- h = (s->ins_h = ((s->ins_h << s->hash_shift) ^ ((val) >> ((MIN_MATCH - 1) * 8))) & s->hash_mask)
-#endif
+#define UPDATE_HASH(s, h, val) \
+ h = ((val * 2654435761U) >> (32 - s->hash_bits));
#define INSERT_STRING insert_string_c
#define QUICK_INSERT_STRING quick_insert_string_c