mirror of
https://github.com/janet-lang/janet
synced 2024-06-25 22:53:16 +00:00
Revert to better performing number hash.
This commit is contained in:
parent
a2c837a99c
commit
0d46352ff4
|
@ -268,14 +268,13 @@ int32_t janet_hash(Janet x) {
|
||||||
if (isnan(num) || isinf(num) || num == 0) {
|
if (isnan(num) || isinf(num) || num == 0) {
|
||||||
hash = 0;
|
hash = 0;
|
||||||
} else {
|
} else {
|
||||||
int e = 0;
|
hash = (int32_t)num;
|
||||||
double rest = frexp(num, &e);
|
hash = ((hash >> 16) ^ hash) * 0x45d9f3b;
|
||||||
int64_t intrest = (int64_t)(rest * JANET_INTMAX_DOUBLE);
|
hash = ((hash >> 16) ^ hash) * 0x45d9f3b;
|
||||||
uint32_t accum = (uint32_t)((intrest >> 22) ^ intrest);
|
hash = (hash >> 16) ^ hash;
|
||||||
accum ^= 0x9e3779b9 + (accum << 3) + (accum >> 2);
|
|
||||||
accum += (int32_t)(e);
|
uint32_t lo = (uint32_t)(janet_u64(x) & 0xFFFFFFFF);
|
||||||
accum ^= 0x9e3779b9 + (accum << 3) + (accum >> 2);
|
hash ^= lo + 0x9e3779b9 + (hash<<6) + (hash>>2);
|
||||||
hash = (int32_t) accum;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user