From b61d2a84d852c9ef08e252d79c5f5feb48826271 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 15 Nov 2003 10:41:41 +0000 Subject: [PATCH] A better function for hashing integers (the old multiplier was completely bogus as it didn't fit in a 32-bit integer) and also a new function for hashing pointers. --- lib/hashfunc.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/hashfunc.h b/lib/hashfunc.h index 14133220..cc799476 100644 --- a/lib/hashfunc.h +++ b/lib/hashfunc.h @@ -33,6 +33,13 @@ uns hash_block(const byte *str, uns len) CONST; uns hash_string_nocase(const byte *str) CONST; -static inline uns CONST hash_int(uns x) { return 6442450967*x; } +/* + * We hash integers by multiplying by a reasonably large prime with + * few ones in its binary form (to gave the compiler the possibility + * of using shifts and adds on architectures where multiplication + * instructions are slow). + */ +static inline uns CONST hash_int(uns x) { return 0x01008041*x; } +static inline uns CONST hash_pointer(void *x) { return hash_int((uns)x); } #endif -- 2.39.2