SealedCreates a map holding each mapping of entries in order, later pairs replacing earlier ones
for equal keys; empty when entries is omitted, undefined or null. Every item is checked
before anything is stored.
Time: O(m) average for m items, plus the key or equivalence calls.
Creates an empty map with the given options. An object that is not iterable is read as the
options, so new HashMap({ a: 1 }) is an empty map (the unknown property a is ignored).
Time: O(1).
key or equivalence.
Marks instances of this class so instanceof recognises them across copies of the package.
Its key is not exported, so the getter is not called directly. Time: O(1).
Marks maps so isMapCollection recognises them across copies of the package. Its key is not
exported, so the getter is not called directly. Time: O(1).
'HashMap', for Object.prototype.toString. Time: O(1).
A number that changes when a mapping is added or removed or a value is written (even the same value), and never on a read or on a call that changes nothing. Its exact values are unspecified. Time: O(1).
The number of mappings. Time: O(1).
The value-equality protocol; delegates to equals. Time: as equals.
The value-equality protocol: an order-independent combination of the mappings' hashes, the
same for equal maps that use the same key function, the same equivalence, or neither.
Values are unspecified. Time: O(n) plus the hash calls.
Node's inspect hook: HashMap(1) { 'a' => 1 } in console.log. Time: as toString.
Returns a live iterator over a new [key, value] array per mapping, in insertion order, as
entries() does: deleted mappings not yet reached are skipped, added ones are visited, and
clear() ends it. new Map(hashMap) copies the map this way.
Time: O(1) to create; O(1) per step.
A new iterator.
Maps key to fn(currentValueOrUndefined, key, map), or removes the mapping when the result
is undefined, and returns the result. A stored undefined reaches fn as undefined, just
as absence does; use has to tell them apart.
Time: as set, plus the call.
The result of fn.
When key is present, maps it to fn(value, key, map), or removes the mapping when the
result is undefined, and returns the result; otherwise returns undefined without calling
fn.
Time: as set, plus the call.
The result of fn, or undefined.
Returns whether some value is SameValueZero-equal to value.
Time: O(n).
The value to look for.
true when a mapping has that value.
Removes the mapping of key and returns whether there was one.
Time: as set.
The key.
true when a mapping was removed.
Returns a live view of the mappings as entries. An entry is a member when its key is present
with an equal value; removing it removes the mapping; add throws
UnsupportedOperationError. Each call returns a new view.
Time: O(1).
A new view.
Returns whether other is a map of the same size in which every key of this map is present
with a value equal under equals, and which has no key this map lacks — whatever the order,
and the same both ways round. Native Map, sets, lists and plain objects are never equal to
it.
Time: O(n) average, plus the lookups on both maps and the protocol methods.
Any value.
true when other is an equal map.
Calls action(value, key, map) for each mapping in insertion order, with this set to
thisArg, as native Map does. Mappings deleted before they are reached are skipped;
mappings added during the loop are visited.
Time: O(n) plus the calls.
Called with each value, its key and the map.
OptionalthisArg: unknown
The this value for action.
Returns the value mapped to a key equal to key, or undefined when there is none. Use has
or getOrDefault to tell a stored undefined from absence.
Time: O(1) average, plus one key or hash call and the equals calls.
The key to look up (-0 is read as 0).
The value, or undefined.
Returns the value of key when present; otherwise maps key to value and returns value,
as native Map.prototype.getOrInsert does.
Time: as set.
The mapped value.
Returns the value of key when present, without calling fn; otherwise calls fn(key), maps
key to its result and returns it, as native Map.prototype.getOrInsertComputed does. If
fn inserted the key itself, that mapping's value is overwritten in place; fn may change
the map without an error.
Time: as set, plus the call.
The mapped value.
Returns whether a key equal to key is present.
Time: as get.
The key to look for.
true when the key is present.
Returns a live iterator over the keys in insertion order.
Time: O(1) to create; O(1) per step.
A new iterator.
Returns a live view of the keys, under this map's key equality. Removing a key removes its
mapping; add throws UnsupportedOperationError. Each call returns a new view.
Time: O(1).
A new view.
Maps key to value when it is absent (even when value is undefined); otherwise to
fn(old, value, key, map), removing the mapping when that result is undefined. Returns the
stored value, or undefined when the mapping was removed.
Time: as set, plus the call.
The stored value, or undefined.
Maps key to value, as set does, and returns the previous value, or undefined when the
key was absent.
Time: as set.
The previous value, or undefined.
Sets every mapping of entries in order, later ones replacing earlier ones for equal keys. The
whole argument is read and checked first, so map.putAll(map) is safe; mappings set before a
key or hash error stay.
Time: O(m) average for m items, plus the calls.
Replaces the value of key only when the key is present, and returns the previous value, or
undefined.
Time: as set.
The previous value, or undefined.
Replaces each value with fn(value, key, map), in iteration order. Values replaced before an
error stay.
Time: O(n) plus the calls.
Maps key to value and returns the map, so calls chain. When an equal key is present, its
stored key object and position are kept and only the value is replaced.
Time: O(1) average, plus one key or hash call and the equals calls.
The map.
Returns a live view of the values, compared with SameValueZero. delete(v) removes the first
mapping with that value; removeAll, retainAll and removeIf every matching mapping; add
throws UnsupportedOperationError. The view equals only itself. Each call returns a new view.
Time: O(1).
A new view.
Returns a live iterator over the values in insertion order.
Time: O(1) to create; O(1) per step.
A new iterator.
Static[hasStaticfrom
A map that behaves like native
Map— insertion order, SameValueZero keys (NaNis one key,-0is stored as0),setreturning the map, live iteration — and adds keys compared by value on request, structuralequals, read-modify-write helpers (getOrDefault,compute,merge,replaceAll) and livekeySet(),entrySet()andvalueCollection()views.Give a
keyfunction to treat keys with the same derived key as one key, or anequivalence(such asvalueEquivalence) to decide key equality by itsequalsandhash. The original key objects are stored and returned.nullandundefinedare allowed as keys and values.Iteration is live, as with native
Map: mappings deleted before they are reached are skipped, mappings added during iteration are visited, and nothing throwsConcurrentModificationError. Writing a value is not a structural change. Changing a key's derived key or hash while it is in the map leaves lookups for it unspecified; the mapping can still be removed through a view's cursor,removeIf,removeAll,retainAll, orclear.Two maps are equal when they have the same size and each maps every key of the other to an equal value, in any order. Construction input must be
[key, value]arrays of length 2 or map entries. The class is not designed to be subclassed.Example