MultiMap
Defined in: packages/data/src/multimap/multi-map.ts:23
A key associated with many values, backed by a Map of arrays.
This is a list multimap: a key may hold the same value more than once,
and the values of a key keep their insertion order. That is the more
primitive of the two shapes — a set-multimap can be built over this one,
whereas recovering duplicates from a set-multimap is impossible. add never
deduplicates; use hasEntry first if a key must hold a value only once.
count() is the total number of (key, value) entries across every key: a
key holding three values contributes three. keyCount() is the number of
distinct keys.
Time complexity: O(1) for add, has, countFor and keyCount; O(1) for
delete of a whole key; O(k) for hasEntry/deleteEntry in the number of
values held under that key. Keys and values are compared by SameValueZero.
Type Parameters
Section titled “Type Parameters”K
The key type.
V
The value type.
Implements
Section titled “Implements”IMultimap<K,V>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MultiMap<
K,V>(iterable?):MultiMap<K,V>
Defined in: packages/data/src/multimap/multi-map.ts:29
Parameters
Section titled “Parameters”iterable?
Section titled “iterable?”Iterable<readonly [K, V], any, any>
Returns
Section titled “Returns”MultiMap<K, V>
Methods
Section titled “Methods”[iterator]()
Section titled “[iterator]()”[iterator]():
Iterator<readonly [K,V]>
Defined in: packages/data/src/multimap/multi-map.ts:37
Returns
Section titled “Returns”Iterator<readonly [K, V]>
Implementation of
Section titled “Implementation of”add(
key,value):void
Defined in: packages/data/src/multimap/multi-map.ts:65
O(1). Appends even when key already holds value.
Parameters
Section titled “Parameters”K
V
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”addAll()
Section titled “addAll()”addAll(
key,values):void
Defined in: packages/data/src/multimap/multi-map.ts:78
O(m) in the number of values.
Parameters
Section titled “Parameters”K
values
Section titled “values”Iterable<V>
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”clear()
Section titled “clear()”clear():
void
Defined in: packages/data/src/multimap/multi-map.ts:46
Removes all elements from the collection.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”count()
Section titled “count()”count():
number
Defined in: packages/data/src/multimap/multi-map.ts:42
The total number of (key, value) entries, not the number of keys.
Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”countFor()
Section titled “countFor()”countFor(
key):number
Defined in: packages/data/src/multimap/multi-map.ts:156
O(1).
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”delete()
Section titled “delete()”delete(
key):number
Defined in: packages/data/src/multimap/multi-map.ts:113
Removes key and every value under it. O(1).
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”number
How many entries were removed.
Implementation of
Section titled “Implementation of”deleteEntry()
Section titled “deleteEntry()”deleteEntry(
key,value):boolean
Defined in: packages/data/src/multimap/multi-map.ts:132
Removes one occurrence of value under key — the first, since values
keep their insertion order. O(k).
Parameters
Section titled “Parameters”K
V
Returns
Section titled “Returns”boolean
true if an entry was removed.
Implementation of
Section titled “Implementation of”entries()
Section titled “entries()”entries():
IterableIterator<readonly [K,V]>
Defined in: packages/data/src/multimap/multi-map.ts:171
Every (key, value) pair, grouped by key.
Returns
Section titled “Returns”IterableIterator<readonly [K, V]>
Implementation of
Section titled “Implementation of”get(
key):IterableIterator<V>
Defined in: packages/data/src/multimap/multi-map.ts:52
The values held under key, in insertion order. Empty when absent.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”IterableIterator<V>
Implementation of
Section titled “Implementation of”has(
key):boolean
Defined in: packages/data/src/multimap/multi-map.ts:99
O(1). Whether key holds at least one value.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”hasEntry()
Section titled “hasEntry()”hasEntry(
key,value):boolean
Defined in: packages/data/src/multimap/multi-map.ts:104
O(k) in the number of values held under key.
Parameters
Section titled “Parameters”K
V
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”keyCount()
Section titled “keyCount()”keyCount():
number
Defined in: packages/data/src/multimap/multi-map.ts:161
The number of distinct keys. O(1).
Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”keys()
Section titled “keys()”keys():
IterableIterator<K>
Defined in: packages/data/src/multimap/multi-map.ts:166
Each distinct key once, in first-insertion order.
Returns
Section titled “Returns”IterableIterator<K>