mirror of
https://github.com/janet-lang/janet
synced 2024-11-25 01:37:19 +00:00
Improve hashing of numbers
Using an integer hash (https://stackoverflow.com/a/12996028/60617) on the number casted to int32 combined with lower bits of the number.
This commit is contained in:
parent
c76e0ae685
commit
2ec12fe06f
@ -260,6 +260,16 @@ int32_t janet_hash(Janet x) {
|
||||
break;
|
||||
case JANET_STRUCT:
|
||||
hash = janet_struct_hash(janet_unwrap_struct(x));
|
||||
break;
|
||||
case JANET_NUMBER:
|
||||
hash = (int32_t)janet_unwrap_number(x);
|
||||
hash = ((hash >> 16) ^ hash) * 0x45d9f3b;
|
||||
hash = ((hash >> 16) ^ hash) * 0x45d9f3b;
|
||||
hash = (hash >> 16) ^ hash;
|
||||
|
||||
uint32_t lo = (uint32_t)(janet_u64(x) & 0xFFFFFFFF);
|
||||
hash ^= lo + 0x9e3779b9 + (hash<<6) + (hash>>2);
|
||||
|
||||
break;
|
||||
case JANET_ABSTRACT: {
|
||||
JanetAbstract xx = janet_unwrap_abstract(x);
|
||||
|
Loading…
Reference in New Issue
Block a user