From c9e2a9c68fbf0b9e14d67f8c56117ca89a48c9bd Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Fri, 1 Mar 2019 07:50:06 +0000 Subject: [PATCH] switched the default hash function to sdbm hash --- moo/lib/utl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/moo/lib/utl.c b/moo/lib/utl.c index eac4405..f518202 100644 --- a/moo/lib/utl.c +++ b/moo/lib/utl.c @@ -222,7 +222,12 @@ moo_oow_t moo_hash_bytes (const moo_oob_t* ptr, moo_oow_t len) const moo_uint8_t* bp, * be; bp = ptr; be = bp + len; - while (bp < be) h = h * 31 + *bp++; + + /* this hash doesn't produce good distribution */ + /*while (bp < be) h = h * 31 + *bp++; */ + + /* SDBM hash is know to produce good overall distribution for many different data sets */ + while (bp < be) h = (h << 6) + (h << 16) - h + *bp++; /* constrain the hash value to be representable in a small integer * for convenience sake */