SealedCreates a map holding each mapping of entries, set one by one in order with the options'
access moves and evictions; empty when entries is omitted, undefined or null. Every item
and option is checked before anything is stored; options are never taken from entries.
Time: O(m) average for m items, plus the key or equivalence calls.
TypeError when entries is neither iterable nor null/undefined, an item is not an
array of length 2 or a map entry, options is not an object, both key and equivalence
are given, key is not a function, equivalence lacks an equals or hash function,
accessOrder is not a boolean, maxSize is not a number or onEvict is not a function.
Creates an empty map with the given options. An object that is not iterable is read as the options.
Time: O(1).
key or equivalence, accessOrder, maxSize, onEvict.
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).
Marks sequenced maps across copies of the package. Its key is not exported, so the getter is not called directly. Time: O(1).
'LinkedHashMap', for Object.prototype.toString. Time: O(1).
A number that changes when a mapping is added, removed or moved or a value is written (even the same value) — in access order also when a read moves a mapping — and never 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 as an equal HashMap with the same key function, the same equivalence, or neither.
Values are unspecified. Time: O(n) plus the hash calls.
Node's inspect hook: LinkedHashMap(1) { 'a' => 1 } in console.log. Time: as toString.
Returns a live iterator over a new [key, value] array per mapping, in order, as entries()
does. new Map(linkedHashMap) copies the map this way.
Time: O(1) to create (in access order without key or equivalence, the first call that
needs linked records costs O(n), once); O(1) per step, amortised over the steps and the
changes made while it is open.
A new iterator.
Maps key to fn(currentValueOrUndefined, key, map), or removes the mapping when the result
is undefined, and returns the result. Writing a present key is an access.
Time: as set, plus the call; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).
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. Writing the value is an access.
Time: as set, plus the call; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).
The result of fn, or undefined.
Returns whether some value is SameValueZero-equal to value. Never moves a mapping.
Time: O(n).
The value to look for.
true when a mapping has that value.
Returns a new LinkedHashMap with the same mappings, order and options — key or
equivalence, accessOrder, maxSize and the same onEvict function — independent of this
one. Stored keys and hashes are copied; no user function is called.
Time: O(n).
The copy.
Removes the mapping of key and returns whether there was one. onEvict is not called.
Time: as set.
The key.
true when a mapping was removed.
Returns a live iterator over a new [key, value] array per mapping, in order.
Time: O(1) to create (in access order without key or equivalence, the first call that
needs linked records costs O(n), once); O(1) per step, amortised over the steps and the
changes made while it is open.
A new iterator.
Returns a live view of the mappings as entries, in this map's order, with this map's ends. An
entry is a member when its key is present with an equal value; removing it removes the
mapping; adding throws UnsupportedOperationError. Each call returns a new view.
Time: O(1). A call through the view other than size, isEmpty and has (in access order
without key or equivalence, other than size and isEmpty) needs linked order: the first
such call on the map costs O(n), once, and the view's ends cost what the map's cost, amortised.
A new view, tagged LinkedHashMapEntrySet.
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. Never moves a mapping of either map.
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 order, with this set to thisArg, as
native Map does. Mappings deleted before they are reached are skipped; mappings added at the
end 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. In access
order, a present mapping moves to the end.
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 mapped to key when the key is present (even when that value is
undefined), and fallback otherwise. In access order, a present mapping moves to the end.
Time: as get; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).
The mapped value, or fallback.
Returns the value of key when present (in access order, moving it to the end); otherwise maps
key to value at the end and returns value, as native Map.prototype.getOrInsert does.
Time: as set; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).
The mapped value.
Returns the value of key when present (in access order, moving it to the end), without
calling fn; otherwise calls fn(key), maps key to its result and returns it. If fn
inserted the key itself, that mapping's value is overwritten in place, as an access.
Time: as set, plus the call; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).
The mapped value.
Returns whether a key equal to key is present. Never moves a mapping.
Time: as get.
The key to look for.
true when the key is present.
Returns a live iterator over the keys in order.
Time: O(1) to create (in access order without key or equivalence, the first call that
needs linked records costs O(n), once); O(1) per step, amortised over the steps and the
changes made while it is open.
A new iterator.
Returns a live view of the keys in this map's order, under its key equality, with this map's
ends. Removing a key removes its mapping; add, addFirst and addLast throw
UnsupportedOperationError. Each call returns a new view.
Time: O(1). A call through the view other than size, isEmpty and has (in access order
without key or equivalence, other than size and isEmpty) needs linked order: the first
such call on the map costs O(n), once, and the view's ends cost what the map's cost, amortised.
A new view, tagged LinkedHashMapKeySet.
Maps key to value at the end when it is absent; 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. Writing a present key is an access.
Time: as set, plus the call; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).
The stored value, or undefined.
Removes the first mapping and returns its entry, or returns undefined when the map is empty.
The entry still reads its value; setValue on it throws IllegalStateError until the key is
set again. No user function is called and onEvict is not.
Time: O(1) amortised average.
The entry of the removed mapping, or undefined.
Removes the last mapping and returns its entry, or returns undefined when the map is empty.
No user function is called and onEvict is not.
Time: O(1) amortised average (the first call that needs linked order costs O(n), once).
The entry of the removed mapping, or undefined.
Maps key to value, as set does, and returns the previous value, or undefined when the
key was absent.
Time: as set; O(1) amortised average with accessOrder, maxSize and onEvict (the first call that needs linked records costs O(n), once).
The previous value, or undefined.
Sets every mapping of entries in order, each as one set with its access move and eviction.
The whole argument is read and checked first, so map.putAll(map) is safe; evictions are
reported to onEvict once, after the last pair.
Time: O(m) average for m items, plus the calls; O(m) amortised average with maxSize or in access order (the first call that needs linked records costs O(n), once).
Maps key to value at the front: inserts the mapping there when the key is absent, or moves
the present mapping there (keeping its stored key) and writes its value. Not an access. With
maxSize, a new key can evict from the front, never itself.
Time: O(1) amortised average, plus one key or hash call and the equals calls (the first
call that needs linked order costs O(n), once).
The map.
Maps key to value at the end: inserts the mapping there when the key is absent, or moves
the present mapping there (keeping its stored key) and writes its value. Not an access.
Time: O(1) amortised average, plus one key or hash call and the equals calls (the first
call that needs linked order costs O(n), once).
The map.
Replaces the value of key only when the key is present (in access order, moving it to the
end), and returns the previous value, or undefined.
Time: as set; O(1) amortised average in access order (the first call that needs linked records costs O(n), once).
The previous value, or undefined.
Replaces each value with fn(value, key, map), in order. Never moves a mapping. Values
replaced before an error stay.
Time: O(n) plus the calls.
Returns a live view of this map in the opposite order, tagged ReversedLinkedHashMap. Changes
through either show in both; its ends are this map's ends swapped, and a key it inserts goes to
its end, this map's front. Access moves and evictions act on this map as usual. Reversing the
view returns this map.
Time: O(1). Every call through the view needs linked order: the first such call on the map costs O(n), once, and the view's operations cost what the map's cost, amortised.
The reversed view.
Maps key to value and returns the map, so calls chain. A new key goes to the end; a
present key keeps its stored key object and its position (in access order it moves to the
end) and only the value is replaced. With maxSize, a new key can evict from the front.
Time: O(1) average, plus one key or hash call and the equals calls; O(1) amortised
average with maxSize.
The map.
Returns a live view of the values in this map's order, compared with SameValueZero, with this
map's ends. delete(v) removes the first mapping with that value; removeAll, retainAll
and removeIf every matching mapping; adding throws UnsupportedOperationError. The view
equals only itself. Each call returns a new view.
Time: O(1). A call through the view other than size, isEmpty and has (in access order
without key or equivalence, other than size and isEmpty) needs linked order: the first
such call on the map costs O(n), once, and the view's ends cost what the map's cost, amortised.
A new view, tagged LinkedHashMapValues.
Returns a live iterator over the values in order.
Time: O(1) to create (in access order without key or equivalence, the first call that
needs linked records costs O(n), once); O(1) per step, amortised over the steps and the
changes made while it is open.
A new iterator.
Static[hasReturns whether value is a LinkedHashMap, including one created by another copy of the
library with the same major version. Its reversed view is not one.
Time: O(1).
The value on the left of instanceof.
true when value is a LinkedHashMap.
StaticfromReturns a new map of the mappings of entries, set one by one in order with the options'
access moves and evictions. Every item and option is checked before anything is stored.
Time: O(m) average for m items, plus the key or equivalence calls.
A new map.
A map that behaves like native
MapandHashMap— insertion order, SameValueZero keys (NaNis one key,-0is stored as0),setreturning the map and keeping a present key where it is, live iteration, keys compared by value on request — and can also be read and changed at both ends:firstEntryandlastEntry,pollFirstEntryandpollLastEntry,putFirstandputLast, which insert an absent key at that end or move the present mapping there, and a livereversed()view. Each takes O(1) amortised (average for those that look up or remove).A map without the
key,equivalenceoraccessOrderoption keeps its mappings in a nativeMapuntil the first call that needs linked order:putFirst,putLastof a present key,lastEntry,pollLastEntry, any call throughreversed(), or any call throughkeySet(),entrySet()orvalueCollection()other thansize,isEmptyandhas. That call costs O(n), once; this is why the ends,putFirst,putLast, and the inserting methods of a map withmaxSize(each eviction) are amortised.A map with
accessOrder: trueand neitherkeynorequivalencekeeps its mappings in a compact form until the first call on it other thanget,has,set,put(unless bothmaxSizeandonEvictare given),delete,size,isEmptyandclear: any other method, iteration, an entry, or a call throughreversed()or a view other thansizeandisEmpty. That call costs O(n), once, which is why those other operations are amortised for such a map. A map built with entries, or made bycopy, starts in the linked form.With
accessOrder: true, every read or write of a present key (get,getOrDefault,set,put,replace,getOrInsert,getOrInsertComputed,compute,computeIfPresent,merge, andputAll, the constructor andfromfor keys already present) moves its mapping to the end, so the first mapping is the least recently used.has, iteration, the views, the ends, entries,replaceAll,equals, hashing and printing never move anything. WithmaxSize, inserting a new key past the bound removes mappings from the front, never the one just inserted, andonEvict(value, key, map)is told about each after the call that evicted it; together they make an LRU cache.Iteration is live, as with native
Map: mappings deleted before they are reached are skipped, mappings inserted at the end the loop is heading to are visited, those inserted at the end it started from are not, and nothing throwsConcurrentModificationError.putFirstandputLastact as a delete followed by an insertion at the new end. A move made by an access never makes an open loop return a mapping twice — on a forward loop an unvisited mapping is visited once at its new place, on a loop overreversed()it is skipped — sofor (const k of map.keys()) map.get(k)ends; such a forward loop keeps a record of the mappings it returned until it is dropped.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 the ends, 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. ALinkedHashMapis not aHashMap(instanceof HashMapisfalse); both are maps. The class is not designed to be subclassed.Example