1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-05 08:16:16 +00:00

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.
This commit is contained in:
Calvin Rose 2021-12-07 08:24:04 -06:00
parent 1c937ad960
commit 92fdd07ca3

View File

@ -324,7 +324,8 @@ int32_t janet_hash(Janet x) {
as.d = janet_unwrap_number(x); as.d = janet_unwrap_number(x);
uint32_t lo = (uint32_t)(as.u & 0xFFFFFFFF); uint32_t lo = (uint32_t)(as.u & 0xFFFFFFFF);
uint32_t hi = (uint32_t)(as.u >> 32); 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; break;
} }
case JANET_ABSTRACT: { case JANET_ABSTRACT: {