LinkedHashMap
Defined in: src/map/LinkedHashMap.ts:59
A HashMap whose entries are also linked in a doubly linked list, giving a predictable iteration order and
the SequencedMap operations. The order is insertion order by default (putting an existing key again keeps
its place), or access order when constructed with accessOrder = true (every get, getOrDefault, put,
putIfAbsent, replace, compute* or merge hit moves the key to the end, which is a structural change for open
iterators). null and undefined keys and values are allowed. Lookups and updates are O(1) expected; first/last
access and polling are O(1).
Override LinkedHashMap.removeEldestEntry, or use LinkedHashMap.lru, to build an LRU cache.
Extends
Section titled “Extends”HashMap<K,V>
Type Parameters
Section titled “Type Parameters”K
V
Implements
Section titled “Implements”SequencedMap<K,V>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new LinkedHashMap<
K,V>():LinkedHashMap<K,V>
Defined in: src/map/LinkedHashMap.ts:76
Creates an empty insertion-ordered map.
Returns
Section titled “Returns”LinkedHashMap<K, V>
Overrides
Section titled “Overrides”Constructor
Section titled “Constructor”new LinkedHashMap<
K,V>(initialCapacity,loadFactor?,accessOrder?):LinkedHashMap<K,V>
Defined in: src/map/LinkedHashMap.ts:82
Creates an empty map. initialCapacity and loadFactor are validated sizing hints only; accessOrder = true
selects access order instead of insertion order.
Parameters
Section titled “Parameters”initialCapacity
Section titled “initialCapacity”number
loadFactor?
Section titled “loadFactor?”number
accessOrder?
Section titled “accessOrder?”boolean
Returns
Section titled “Returns”LinkedHashMap<K, V>
Throws
Section titled “Throws”IllegalArgumentException if initialCapacity is negative or NaN, or loadFactor is not positive
Overrides
Section titled “Overrides”Constructor
Section titled “Constructor”new LinkedHashMap<
K,V>(map):LinkedHashMap<K,V>
Defined in: src/map/LinkedHashMap.ts:87
Creates an insertion-ordered map with the mappings of map, in map’s iteration order.
Parameters
Section titled “Parameters”Map<K, V>
Returns
Section titled “Returns”LinkedHashMap<K, V>
Throws
Section titled “Throws”NullPointerException if map is null or undefined
Overrides
Section titled “Overrides”Properties
Section titled “Properties”accessOrder
Section titled “accessOrder”
readonlyaccessOrder:boolean
Defined in: src/map/LinkedHashMap.ts:65
true if the map iterates in access order (least recently used first), false for insertion order.
modCount
Section titled “modCount”modCount:
number=0
Defined in: src/map/HashMap.ts:144
Structural modification count (new key, removal, clear); iterators compare against it.
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”[INSPECT]()
Section titled “[INSPECT]()”[INSPECT]():
string
Defined in: src/abstract/AbstractMap.ts:187
Node’s util.inspect hook: console.log prints the toString() form.
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”[iterator]()
Section titled “[iterator]()”[iterator]():
IterableIterator<[K,V]>
Defined in: src/map/LinkedHashMap.ts:323
Returns a fail-fast iterator over the mappings as [key, value] pairs, in insertion or access order.
Returns
Section titled “Returns”IterableIterator<[K, V]>
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”clear()
Section titled “clear()”clear():
void
Defined in: src/map/LinkedHashMap.ts:273
Removes all mappings.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”clone()
Section titled “clone()”clone():
LinkedHashMap<K,V>
Defined in: src/map/LinkedHashMap.ts:125
Shallow copy of the same runtime class, in the same order and mode; the copy evicts nothing while copying.
Returns
Section titled “Returns”LinkedHashMap<K, V>
Overrides
Section titled “Overrides”compute()
Section titled “compute()”compute(
key,fn):V|null
Defined in: src/map/HashMap.ts:728
Stores fn(key, current), where current is the mapped value or null; a null/undefined result removes the
mapping (or leaves the key absent). O(1) expected plus the cost of fn.
Parameters
Section titled “Parameters”K
(key, value) => V | null | undefined
Returns
Section titled “Returns”V | null
the new value, or null if there is now no mapping
Throws
Section titled “Throws”NullPointerException if fn is null
Throws
Section titled “Throws”ConcurrentModificationException if fn structurally modifies this map
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”computeIfAbsent()
Section titled “computeIfAbsent()”computeIfAbsent(
key,fn):V|null
Defined in: src/map/HashMap.ts:682
If key is absent or mapped to null, stores fn(key) unless that is null/undefined (then nothing is
stored). O(1) expected plus the cost of fn.
Parameters
Section titled “Parameters”K
(key) => V | null | undefined
Returns
Section titled “Returns”V | null
the existing non-null value, the newly stored value, or null
Throws
Section titled “Throws”NullPointerException if fn is null
Throws
Section titled “Throws”ConcurrentModificationException if fn structurally modifies this map
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”computeIfPresent()
Section titled “computeIfPresent()”computeIfPresent(
key,fn):V|null
Defined in: src/map/HashMap.ts:705
If key has a non-null value, replaces it with fn(key, value); a null/undefined result removes the mapping.
O(1) expected plus the cost of fn.
Parameters
Section titled “Parameters”K
(key, value) => V | null | undefined
Returns
Section titled “Returns”V | null
the new value, or null if the key was absent or has been removed
Throws
Section titled “Throws”NullPointerException if fn is null
Throws
Section titled “Throws”ConcurrentModificationException if fn structurally modifies this map
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”containsKey()
Section titled “containsKey()”containsKey(
key):boolean
Defined in: src/map/HashMap.ts:419
Returns true if this map has a mapping for key, even if it maps to null. O(1) expected.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”containsValue()
Section titled “containsValue()”containsValue(
value):boolean
Defined in: src/map/LinkedHashMap.ts:267
Returns true if one or more keys map to a value equal to value. O(n), walking the list.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”entrySet()
Section titled “entrySet()”entrySet():
SequencedSet<MapEntry<K,V>>
Defined in: src/map/LinkedHashMap.ts:318
Returns a live view of the mappings in this map’s order; same as sequencedEntrySet(). Its entries are the map’s
own nodes, so setValue writes through; it does not support add (UnsupportedOperationException).
Returns
Section titled “Returns”SequencedSet<MapEntry<K, V>>
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”equals()
Section titled “equals()”equals(
o):boolean
Defined in: src/abstract/AbstractMap.ts:158
Returns true if o is a Map with the same mappings (any Map implementation). A
ClassCastException or NullPointerException from o’s lookups counts as “not equal”.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”firstEntry()
Section titled “firstEntry()”firstEntry():
MapEntry<K,V> |null
Defined in: src/map/LinkedHashMap.ts:366
Returns the first (eldest) entry as an immutable snapshot, or null if this map is empty. O(1); it does not count
as an access.
Returns
Section titled “Returns”MapEntry<K, V> | null
Implementation of
Section titled “Implementation of”forEach()
Section titled “forEach()”forEach(
action):void
Defined in: src/map/LinkedHashMap.ts:289
Calls action for each mapping, in insertion or access order.
Parameters
Section titled “Parameters”action
Section titled “action”(key, value) => void
Returns
Section titled “Returns”void
Throws
Section titled “Throws”NullPointerException if action is null
Throws
Section titled “Throws”ConcurrentModificationException if action structurally modifies this map
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”get(
key):V|null
Defined in: src/map/LinkedHashMap.ts:252
Returns the value mapped to key, or null if there is none (or the key maps to null). O(1) expected. In access
order a hit moves the key to the end, a structural change for open iterators.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”V | null
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”getNode()
Section titled “getNode()”getNode(
key):HashNode<K,V> |undefined
Defined in: src/map/HashMap.ts:280
Returns the node for key, or undefined. Fires no hook.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”HashNode<K, V> | undefined
Inherited from
Section titled “Inherited from”getOrDefault()
Section titled “getOrDefault()”Call Signature
Section titled “Call Signature”getOrDefault(
key,defaultValue):V
Defined in: src/map/HashMap.ts:596
Returns the value mapped to key, or defaultValue if there is no mapping. A key mapped to null returns null.
O(1) expected.
Parameters
Section titled “Parameters”unknown
defaultValue
Section titled “defaultValue”V
Returns
Section titled “Returns”V
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”getOrDefault(
key,defaultValue):V|null
Defined in: src/map/HashMap.ts:601
Returns the value mapped to key, or defaultValue (here possibly null) if there is no mapping. O(1) expected.
Parameters
Section titled “Parameters”unknown
defaultValue
Section titled “defaultValue”V | null
Returns
Section titled “Returns”V | null
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”hashCode()
Section titled “hashCode()”hashCode():
number
Defined in: src/map/HashMap.ts:584
Returns the sum over all entries of hash(key) ^ hash(value), in 32-bit arithmetic. O(n).
Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”isEmpty()
Section titled “isEmpty()”isEmpty():
boolean
Defined in: src/map/HashMap.ts:396
Returns true if this map has no mappings. O(1).
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”keySet()
Section titled “keySet()”keySet():
SequencedSet<K>
Defined in: src/map/LinkedHashMap.ts:302
Returns a live view of the keys in this map’s order; same as sequencedKeySet(). Removing from it removes the
mapping; it does not support add (UnsupportedOperationException).
Returns
Section titled “Returns”SequencedSet<K>
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”lastEntry()
Section titled “lastEntry()”lastEntry():
MapEntry<K,V> |null
Defined in: src/map/LinkedHashMap.ts:375
Returns the last (youngest) entry as an immutable snapshot, or null if this map is empty. O(1); it does not count
as an access.
Returns
Section titled “Returns”MapEntry<K, V> | null
Implementation of
Section titled “Implementation of”merge()
Section titled “merge()”merge(
key,value,fn):V|null
Defined in: src/map/HashMap.ts:750
If key is absent or mapped to null, maps it to value; otherwise stores fn(oldValue, value), and a
null/undefined result removes the mapping. O(1) expected plus the cost of fn.
Parameters
Section titled “Parameters”K
V
(oldValue, value) => V | null | undefined
Returns
Section titled “Returns”V | null
the new value, or null if the mapping was removed
Throws
Section titled “Throws”NullPointerException if value or fn is null
Throws
Section titled “Throws”ConcurrentModificationException if fn structurally modifies this map
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”pollFirstEntry()
Section titled “pollFirstEntry()”pollFirstEntry():
MapEntry<K,V> |null
Defined in: src/map/LinkedHashMap.ts:381
Removes and returns the first (eldest) entry as an immutable snapshot, or null if this map is empty. O(1).
Returns
Section titled “Returns”MapEntry<K, V> | null
Implementation of
Section titled “Implementation of”pollLastEntry()
Section titled “pollLastEntry()”pollLastEntry():
MapEntry<K,V> |null
Defined in: src/map/LinkedHashMap.ts:389
Removes and returns the last (youngest) entry as an immutable snapshot, or null if this map is empty. O(1).
Returns
Section titled “Returns”MapEntry<K, V> | null
Implementation of
Section titled “Implementation of”put(
key,value):V|null
Defined in: src/map/HashMap.ts:447
Maps key to value, replacing any previous value. O(1) expected. null and undefined keys and values are
allowed.
Parameters
Section titled “Parameters”K
V
Returns
Section titled “Returns”V | null
the previous value, or null if there was no mapping
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”putAll()
Section titled “putAll()”putAll(
m):void
Defined in: src/map/HashMap.ts:518
Copies every mapping of m into this map, as put would. O(m) expected for m mappings; putting a map into itself
does nothing.
Parameters
Section titled “Parameters”Map<K, V>
Returns
Section titled “Returns”void
Throws
Section titled “Throws”NullPointerException if m is null
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”putFirst()
Section titled “putFirst()”putFirst(
key,value):V|null
Defined in: src/map/LinkedHashMap.ts:401
Maps key to value and moves the mapping to the front, in either order mode. A new key may be evicted at once by
LinkedHashMap.removeEldestEntry.
Parameters
Section titled “Parameters”K
V
Returns
Section titled “Returns”V | null
the previous value, or null if there was no mapping
Implementation of
Section titled “Implementation of”putIfAbsent()
Section titled “putIfAbsent()”putIfAbsent(
key,value):V|null
Defined in: src/map/HashMap.ts:636
Maps key to value if it is absent or mapped to null. O(1) expected.
Parameters
Section titled “Parameters”K
V
Returns
Section titled “Returns”V | null
the current value if it was non-null (and nothing changed), otherwise null
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”putLast()
Section titled “putLast()”putLast(
key,value):V|null
Defined in: src/map/LinkedHashMap.ts:409
Maps key to value and moves the mapping to the end, in either order mode.
Parameters
Section titled “Parameters”K
V
Returns
Section titled “Returns”V | null
the previous value, or null if there was no mapping
Implementation of
Section titled “Implementation of”remove()
Section titled “remove()”Call Signature
Section titled “Call Signature”remove(
key):V|null
Defined in: src/map/HashMap.ts:496
Removes the mapping for key, if present. O(1) expected.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”V | null
the removed value, or null if there was no mapping
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”remove(
key,value):boolean
Defined in: src/map/HashMap.ts:501
Removes the mapping for key only if it is currently mapped to a value equal to value. O(1) expected.
Parameters
Section titled “Parameters”unknown
unknown
Returns
Section titled “Returns”boolean
true if the mapping was removed
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”removeNode()
Section titled “removeNode()”removeNode(
node):void
Defined in: src/map/HashMap.ts:342
Removes exactly this node (by identity), then calls HashMap.afterNodeRemoval.
Parameters
Section titled “Parameters”HashNode<K, V>
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”replace()
Section titled “replace()”Call Signature
Section titled “Call Signature”replace(
key,value):V|null
Defined in: src/map/HashMap.ts:653
Replaces the value for key only if key currently has a mapping (even to null). O(1) expected.
Parameters
Section titled “Parameters”K
V
Returns
Section titled “Returns”V | null
the previous value, or null if there was no mapping
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”replace(
key,oldValue,newValue):boolean
Defined in: src/map/HashMap.ts:659
Replaces the value for key with newValue only if it is currently mapped to a value equal to oldValue. O(1)
expected.
Parameters
Section titled “Parameters”K
oldValue
Section titled “oldValue”V
newValue
Section titled “newValue”V
Returns
Section titled “Returns”boolean
true if the value was replaced
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”replaceAll()
Section titled “replaceAll()”replaceAll(
fn):void
Defined in: src/map/HashMap.ts:625
Replaces each value with fn(key, value), in iteration order. This is not a structural change.
Parameters
Section titled “Parameters”(key, value) => V
Returns
Section titled “Returns”void
Throws
Section titled “Throws”NullPointerException if fn is null
Throws
Section titled “Throws”ConcurrentModificationException if fn structurally modifies this map
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”reversed()
Section titled “reversed()”reversed():
SequencedMap<K,V>
Defined in: src/map/LinkedHashMap.ts:358
Returns a live reverse-ordered view: changes through either side are visible in the other. Writes go to this map: a
new key put through the view still lands at this map’s end, and putFirst/putLast on the view put at this map’s
end/front.
Returns
Section titled “Returns”SequencedMap<K, V>
Implementation of
Section titled “Implementation of”sequencedEntrySet()
Section titled “sequencedEntrySet()”sequencedEntrySet():
SequencedSet<MapEntry<K,V>>
Defined in: src/map/LinkedHashMap.ts:349
Returns a live, sequenced view of the mappings in this map’s order. Its entries are the map’s own nodes, so
setValue writes through; adding throws UnsupportedOperationException.
Returns
Section titled “Returns”SequencedSet<MapEntry<K, V>>
Implementation of
Section titled “Implementation of”SequencedMap.sequencedEntrySet
sequencedKeySet()
Section titled “sequencedKeySet()”sequencedKeySet():
SequencedSet<K>
Defined in: src/map/LinkedHashMap.ts:333
Returns a live, sequenced view of the keys in this map’s order. Removal (including removeFirst/removeLast)
writes through; add, addFirst and addLast throw UnsupportedOperationException.
Returns
Section titled “Returns”SequencedSet<K>
Implementation of
Section titled “Implementation of”sequencedValues()
Section titled “sequencedValues()”sequencedValues():
SequencedCollection<V>
Defined in: src/map/LinkedHashMap.ts:341
Returns a live, sequenced view of the values in this map’s order. Removal writes through; adding throws UnsupportedOperationException.
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”size()
Section titled “size()”size():
number
Defined in: src/map/HashMap.ts:391
Returns the number of mappings. O(1).
Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”toString()
Section titled “toString()”toString():
string
Defined in: src/abstract/AbstractMap.ts:191
Returns {k1=v1, k2=v2} in entry-set order; a key or value that is this map prints as (this Map).
Returns
Section titled “Returns”string
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”values()
Section titled “values()”values():
SequencedCollection<V>
Defined in: src/map/LinkedHashMap.ts:310
Returns a live view of the values in this map’s order; same as sequencedValues(). Removing from it removes the
mapping; it does not support add (UnsupportedOperationException).
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”
staticlru<K,V>(maxSize):LinkedHashMap<K,V>
Defined in: src/map/LinkedHashMap.ts:108
Returns an empty access-ordered map that evicts its least recently used entry whenever an insertion takes it
above maxSize entries: a ready-made LRU cache.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”maxSize
Section titled “maxSize”number
Returns
Section titled “Returns”LinkedHashMap<K, V>
Throws
Section titled “Throws”IllegalArgumentException if maxSize is less than 1 or NaN
newHashMap()
Section titled “newHashMap()”
staticnewHashMap<K,V>(numMappings):HashMap<K,V>
Defined in: src/map/HashMap.ts:180
Returns an empty map intended for numMappings mappings (a sizing hint only).
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”numMappings
Section titled “numMappings”number
Returns
Section titled “Returns”HashMap<K, V>
Throws
Section titled “Throws”IllegalArgumentException if numMappings is negative or NaN
Inherited from
Section titled “Inherited from”newLinkedHashMap()
Section titled “newLinkedHashMap()”
staticnewLinkedHashMap<K,V>(numMappings):LinkedHashMap<K,V>
Defined in: src/map/LinkedHashMap.ts:119
Returns an empty insertion-ordered map intended for numMappings mappings (a sizing hint only).
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”numMappings
Section titled “numMappings”number
Returns
Section titled “Returns”LinkedHashMap<K, V>
Throws
Section titled “Throws”IllegalArgumentException if numMappings is negative or NaN
staticof<K,V>(…pairs):LinkedHashMap<K,V>
Defined in: src/map/LinkedHashMap.ts:97
Returns a new insertion-ordered map of the given [key, value] pairs; a repeated key keeps its first position.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”…[K, V][]
Returns
Section titled “Returns”LinkedHashMap<K, V>