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
1 changed files with 2 additions and 1 deletions

View File

@ -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: {