You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the implementations for Set and Map use vectors rather than hash tables, which makes them not ideal, due to Value not implementing Hash. This is in part due to JS values having multiple kinds of (even strict) equality, whereas there can only be one Hash implementation for a given type.
This could be solved, though, with wrapper structs over Value that provide a Hash implementation for each kind of equality1. This wrapper might also have to contain a pre-computed hash, if only for primitives with a heap data, since we won't have access to the agent inside the Hash implementation.
While this could be implementable right now, there are things that would ease that:
See if we can ensure that, for primitive values with a heap data, two identical values always map to the same index. I.e, we don't allocate a new HeapNumber or HeapBigInt if an equal one already exists.
In general, make sure that (except for NaN and positive/negative zero), structural equality of Value maps to equality of JS values.
Implement Hash for BaseIndex and for all wrappers over one.
Footnotes
Well, each kind of equality that forms an equivalence relation. There can't be a hash for triple-equals because NaN !== NaN, but there can be one for SameValue and SameValueZero. ↩
The text was updated successfully, but these errors were encountered:
I've been kind of thinking that we might either want to do one of:
Never store floats and doubles in HashMaps and just say "that's dumb and you should feel bad". This lets us hash values directly. Floats and doubles would just do a linear search, boohoo.
Always precalculate the hash of each Value at insertion time and then insert into HashMap<ValueHash, u32> where the u32 value points to an entry in a next-door ParallelVec<(Value, Value)> that is a key-value parallel vector (basically whatwe have now).
Never store floats and doubles in HashMaps and just say "that's dumb and you should feel bad". This lets us hash values directly. Floats and doubles would just do a linear search, boohoo.
For floats, the only values that are a problem are NaN, and only because they make equality not an equivalence relation. But since for regular JS values we're collapsing NaNs either way, we can override PartialEq and Hash so they do treat f32NaNs as equal, and so they hash f32.to_bits().
Currently the implementations for
Set
andMap
use vectors rather than hash tables, which makes them not ideal, due toValue
not implementingHash
. This is in part due to JS values having multiple kinds of (even strict) equality, whereas there can only be oneHash
implementation for a given type.This could be solved, though, with wrapper structs over
Value
that provide aHash
implementation for each kind of equality1. This wrapper might also have to contain a pre-computed hash, if only for primitives with a heap data, since we won't have access to the agent inside theHash
implementation.While this could be implementable right now, there are things that would ease that:
SmallInteger
a wrapper overSmallBigInt
, not vice versa #288 and Consider adding a wrapper overf32
for Value #289.HeapNumber
orHeapBigInt
if an equal one already exists.NaN
and positive/negative zero), structural equality ofValue
maps to equality of JS values.Hash
forBaseIndex
and for all wrappers over one.Footnotes
Well, each kind of equality that forms an equivalence relation. There can't be a hash for triple-equals because
NaN !== NaN
, but there can be one forSameValue
andSameValueZero
. ↩The text was updated successfully, but these errors were encountered: