1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-29 03:19:54 +00:00

More improvements to hashing for #889

This commit is contained in:
Calvin Rose 2021-12-06 17:23:00 -06:00
parent e8ad311d84
commit f9891a5c04
2 changed files with 3 additions and 2 deletions

View File

@ -225,7 +225,8 @@ int32_t janet_string_calchash(const uint8_t *str, int32_t len) {
#endif #endif
uint32_t janet_hash_mix(uint32_t input, uint32_t more) { uint32_t janet_hash_mix(uint32_t input, uint32_t more) {
return input ^ ((more * 2119589369u) + 0x9e3779b9 + (input << 6) + (input >> 2)); uint32_t mix1 = (more + 0x9e3779b9 + (input << 6) + (input >> 2));
return input ^ (0x9e3779b9 + (mix1 << 6) + (mix1 >> 2));
} }
/* Computes hash of an array of values */ /* Computes hash of an array of values */

View File

@ -324,7 +324,7 @@ 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)); hash = (int32_t)((hi ^ (lo >> 3)) * 2654435769u);
break; break;
} }
case JANET_ABSTRACT: { case JANET_ABSTRACT: {