From 92fdd07ca38525507f405f4f2c0068225675258c Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Tue, 7 Dec 2021 08:24:04 -0600 Subject: [PATCH] Address #889 - Switch high and low bits of part of number hash (Knuth's multiplicative hash) Also make sure we weren't throwing away 3 bits of entropy. --- src/core/value.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/value.c b/src/core/value.c index 38fae844..e1a82f32 100644 --- a/src/core/value.c +++ b/src/core/value.c @@ -324,7 +324,8 @@ int32_t janet_hash(Janet x) { as.d = janet_unwrap_number(x); uint32_t lo = (uint32_t)(as.u & 0xFFFFFFFF); uint32_t hi = (uint32_t)(as.u >> 32); - hash = (int32_t)((hi ^ (lo >> 3)) * 2654435769u); + uint32_t hilo = (hi ^ lo) * 2654435769u; + hash = (int32_t)((hilo << 16) | ((hilo >> 16) & 0xFFFF)); break; } case JANET_ABSTRACT: {