-
Notifications
You must be signed in to change notification settings - Fork 71
Description
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:
- Making sure that it's impossible to represent two same values with different discriminants. See Consider making
SmallIntegera wrapper overSmallBigInt, not vice versa #288 and Consider adding a wrapper overf32for Value #289. - 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
HeapNumberorHeapBigIntif an equal one already exists. - In general, make sure that (except for
NaNand positive/negative zero), structural equality ofValuemaps to equality of JS values. - Implement
HashforBaseIndexand 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 forSameValueandSameValueZero. ↩