interface BiMultiMapBase<K,V,Tp>
undocumented
Companion namespace: BiMultiMapBase
Extends: FastIterable<T>
Implemented by: BiMultiMapBase.NonEmpty<K,V,Tp>, BiMultiMapEmpty<K,V,Tp>
Type parameters
| Name | Constraints | Default | Description |
|---|---|---|---|
| K | undocumented | ||
| V | undocumented | ||
| Tp | BiMultiMapBase.Types | BiMultiMapBase.Types | undocumented |
Properties
context
Returns the context associated to this collection instance.
contextcontext associated to this collection instance.Definition
readonly context: WithKeyValue<Tp, K, V>['context'];
isEmpty
Returns false since this collection is known to be non-empty.
isEmptykeySize
Returns the number of keys
keySizekeyValueMultiMap
Returns the MultiMap representation of the key to value mapping.
keyValueMultiMapDefinition
readonly keyValueMultiMap: WithKeyValue<Tp, K, V>['keyValueMultiMap'];
HashBiMultiMap.of([1, 10], [1, 20]).keyValueMap.toArray()
// => [[1, [10, 20]]
size
Returns the number of entries
sizevalueKeyMultiMap
Returns the MultiMap representation of the value to key mapping.
valueKeyMultiMapDefinition
readonly valueKeyMultiMap: WithKeyValue<Tp, K, V>['valueKeyMultiMap'];
HashBiMultiMap.of([10, 1], [20, 1]).valueKeyMap.toArray()
// => [[1, [10, 20]]
Methods
[Symbol.iterator]
Returns a FastIterator instance used to iterate over the values of this Iterable.
[Symbol.iterator]FastIterator instance used to iterate over the values of this Iterable.add
Returns the collection with the given key associated to the given value.
addkey associated to the given value.Definition
add(key: K, value: V): WithKeyValue<Tp, K, V>['nonEmpty'];
Parameters
| Name | Type | Description |
|---|---|---|
key | K | the entry key to add |
value | V | the entry value to add |
HashBiMultiMap.of([1, 1], [2, 2]).add(1, 2).toArray()
// => [[1, 1], [1, 2], [2, 2]]
addEntries
Returns the collection with the entries from the given StreamSource entries added.
addEntriesStreamSource entries added.Definitions
addEntries(entries: StreamSource.NonEmpty<readonly [K, V]>): WithKeyValue<Tp, K, V>['nonEmpty'];
addEntries(entries: StreamSource<readonly [K, V]>): WithKeyValue<Tp, K, V>['normal'];
Parameters
| Name | Type | Description |
|---|---|---|
entries | StreamSource.NonEmpty<readonly [K, V]> | a StreamSource containing tuples with a key and value |
HashBiMultiMap.of([1, 1]).addEntries([[2, 2], [1, 3]]).toArray()
// => [[1, 1], [1, 3], [2, 2]]
assumeNonEmpty
Returns the collection as a .NonEmpty type
assumeNonEmptyDefinition
assumeNonEmpty(): WithKeyValue<Tp, K, V>['nonEmpty'];
RimbuError.EmptyCollectionAssumedNonEmptyError if the collection is empty
HashBiMultiMap.empty<number, number>().assumeNonEmpty() // => throws
const m: HashBiMultiMap<number, number> = HashBiMultiMap.of([1, 1], [2, 2])
const m2: HashBiMultiMap.NonEmpty<number, number> = m // => compiler error
const m3: HashBiMultiMap.NonEmpty<number, number> = m.assumeNonEmpty()
returns reference to this collection
filter
Returns a collection containing only those entries that satisfy given pred predicate.
filterpred predicate.Definition
filter(pred: (entry: [K, V], index: number, halt: () => void) => boolean, options?: {
negate?: boolean;
}): WithKeyValue<Tp, K, V>['normal'];
Parameters
| Name | Type | Description |
|---|---|---|
pred | (entry: [K, V], index: number, halt: () => void) => boolean | a predicate function receiving: - entry: the next entry- index: the entry index- halt: a function that, when called, ensures no next elements are passed |
options | {negate?: boolean;} | (optional) an object containing the following properties: - negate: (default: false) when true will negate the given predicate |
HashBiMultiMap.of([1, 'a'], [2, 'b'], [3, 'c']).filter(entry => entry[0] === 2 || entry[1] === 'c').toArray()
// => [[2, 'b'], [3, 'c']]
forEach
Performs given function f for each entry of the collection, using given state as initial traversal state.
forEachf for each entry of the collection, using given state as initial traversal state.Definition
forEach(f: (entry: [K, V], index: number, halt: () => void) => void, options?: {
state?: TraverseState;
}): void;
Parameters
| Name | Type | Description |
|---|---|---|
f | (entry: [K, V], index: number, halt: () => void) => void | the function to perform for each entry, receiving: - entry: the next tuple of a key and value- index: the index of the element- halt: a function that, if called, ensures that no new elements are passed |
options | {state?: TraverseState;} | (optional) an object containing the following properties: - state: (optional) the traversal state |
HashBiMultiMap.of([1, 'a'], [2, 'b'], [3, 'c']).forEach((entry, i, halt) => {
console.log([entry[1], entry[0]]);
if (i >= 1) halt();
})
// => logs ['a', 1] ['b', 2]
O(N)
getKeys
Returns a collection containing the keys associated with the given value.
getKeysvalue.Definition
getKeys<UV = V>(value: RelatedTo<V, UV>): WithKeyValue<Tp, K, V>['valueMultiMapValues'];
Type parameters
| Name | Default | Description |
|---|---|---|
| UV | V |
Parameters
| Name | Type | Description |
|---|---|---|
value | RelatedTo<V, UV> | the value of which to find the keys |
const m = HashBiMultiMap.of([1, 1], [2, 1]);
m.getKeys(1).toArray()
// => [1, 2]
m.getKeys(5).toArray()
// => []
getValues
Returns a collection containing the values associated with the given key.
getValueskey.Definition
getValues<UK = K>(key: RelatedTo<K, UK>): WithKeyValue<Tp, K, V>['keyMultiMapValues'];
Type parameters
| Name | Default | Description |
|---|---|---|
| UK | K |
Parameters
| Name | Type | Description |
|---|---|---|
key | RelatedTo<K, UK> | the key of which to find the values |
const m = HashBiMultiMap.of([1, 1], [1, 2]);
m.getValues(1).toArray()
// => [1, 2]
m.getValues(5).toArray()
// => []
hasEntry
Returns true if the given key and value entry is in the collection.
hasEntryDefinition
hasEntry<UK = K, UV = V>(key: RelatedTo<K, UK>, value: RelatedTo<V, UV>): boolean;
Type parameters
| Name | Default | Description |
|---|---|---|
| UK | K | |
| UV | V |
Parameters
| Name | Type | Description |
|---|---|---|
key | RelatedTo<K, UK> | the entry key to look for |
value | RelatedTo<V, UV> | the entry value to look for |
const m = HashBiMultiMap.of([1, 'a'], [2, 'b'])
m.hasEntry(2, 'b') // => true
m.hasEntry(2, 'c') // => false
hasKey
Returns true if the given key is present in the collection.
hasKeykey is present in the collection.hasValue
Returns true if the given value is present in the collection.
hasValuevalue is present in the collection.nonEmpty
Returns true if there is at least one entry in the collection, and instructs the compiler to treat the collection as a .NonEmpty type.
nonEmptyDefinition
nonEmpty(): this is WithKeyValue<Tp, K, V>['nonEmpty'];
const m: HashBiMultiMap<number, number> = HashBiMultiMap.of([1, 1], [2, 2])
m.stream().first(0) // compiler allows fallback value since the Stream may be empty
if (m.nonEmpty()) {
m.stream().first(0) // compiler error: fallback value not allowed since Stream is not empty
}
removeEntries
Returns the collection where the entries in the given entries StreamSource are removed if present.
removeEntriesentries StreamSource are removed if present.Definition
removeEntries<UK = K, UV = V>(entries: StreamSource<[RelatedTo<K, UK>, RelatedTo<V, UV>]>): WithKeyValue<Tp, K, V>['normal'];
Type parameters
| Name | Default | Description |
|---|---|---|
| UK | K | |
| UV | V |
Parameters
| Name | Type | Description |
|---|---|---|
entries | StreamSource<[RelatedTo<K, UK>, RelatedTo<V, UV>]> | a StreamSource containing entries to remove |
const m = HashBiMultiMap.of([1, 1], [2, 2])
m.removeEntries([[2, 2], [2, 3]]).toArray() // => [[1, 1]]
m.removeEntries([[1, 2], [4, 3]]).toArray() // => [[1, 1], [2, 2]]
m.removeEntries([[3, 3]]) === m // => true
removeEntry
Returns the collection where the entry with given key or value is removed if present.
removeEntrykey or value is removed if present.Definition
removeEntry<UK = K, UV = V>(key: RelatedTo<K, UK>, value: RelatedTo<V, UV>): WithKeyValue<Tp, K, V>['normal'];
Type parameters
| Name | Default | Description |
|---|---|---|
| UK | K | |
| UV | V |
Parameters
| Name | Type | Description |
|---|---|---|
key | RelatedTo<K, UK> | the entry key |
value | RelatedTo<V, UV> | the entry value |
const m = HashBiMultiMap.of([1, 1], [2, 2])
m.removeEntry(2, 2).toArray() // => [[1, 1]]
m.removeEntry(1, 2).toArray() // => [[1, 1], [2, 2]]
m.removeEntry(3, 3) === m // => true
removeKey
Returns the collection where the entries associated with given key are removed if it was part of the collection.
removeKeykey are removed if it was part of the collection.Definition
removeKey<UK = K>(key: RelatedTo<K, UK>): WithKeyValue<Tp, K, V>['normal'];
Type parameters
| Name | Default | Description |
|---|---|---|
| UK | K |
Parameters
| Name | Type | Description |
|---|---|---|
key | RelatedTo<K, UK> | the key of the entries to remove |
const m = HashBiMultiMap.of([1, 1], [1, 2])
m.removeKey(2).toArray() // => [1, 2]
m.removeKey(3) === m // true
guarantees same object reference if the key is not present
removeKeys
Returns the collection where the entries associated with each key in given keys are removed if they were present.
removeKeyskeys are removed if they were present.Definition
removeKeys<UK = K>(keys: StreamSource<RelatedTo<K, UK>>): WithKeyValue<Tp, K, V>['normal'];
Type parameters
| Name | Default | Description |
|---|---|---|
| UK | K |
Parameters
| Name | Type | Description |
|---|---|---|
keys | StreamSource<RelatedTo<K, UK>> | a StreamSource of keys to remove |
const m = HashBiMultiMap.of([1, 1], [2, 2])
m.removeKeys([1, 3]).toArray() // => [[2, 2]]
m.removeKeys([1, 3, 2]).toArray() // => []
m.removeKeys([3, 4, 5]) === m // => true
guarantees same object reference if none of the keys are present
removeValue
Returns the collection where the entries associated with given value are removed if it was part of the collection.
removeValuevalue are removed if it was part of the collection.Definition
removeValue<UV = V>(value: RelatedTo<V, UV>): WithKeyValue<Tp, K, V>['normal'];
Type parameters
| Name | Default | Description |
|---|---|---|
| UV | V |
Parameters
| Name | Type | Description |
|---|---|---|
value | RelatedTo<V, UV> | the value of the entries to remove |
const m = HashBiMultiMap.of([1, 2], [2, 2])
m.removeValue(2).toArray() // => [1, 2]
m.removeValue(3) === m // true
guarantees same object reference if the key is not present
removeValues
Returns the collection where the entries associated with each value in given values are removed if they were present.
removeValuesvalues are removed if they were present.Definition
removeValues<UV = V>(values: StreamSource<RelatedTo<V, UV>>): WithKeyValue<Tp, K, V>['normal'];
Type parameters
| Name | Default | Description |
|---|---|---|
| UV | V |
Parameters
| Name | Type | Description |
|---|---|---|
values | StreamSource<RelatedTo<V, UV>> | a StreamSource of values to remove |
const m = HashBiMultiMap.of([1, 1], [2, 2])
m.removeValues([1, 3]).toArray() // => [[2, 2]]
m.removeValues([1, 3, 2]).toArray() // => []
m.removeValues([3, 4, 5]) === m // => true
guarantees same object reference if none of the keys are present
setKeys
Returns the collection with the keys from the given keys StreamSource associated with the given value.
setKeyskeys StreamSource associated with the given value.Definitions
setKeys(value: V, keys: StreamSource.NonEmpty<K>): WithKeyValue<Tp, K, V>['nonEmpty'];
setKeys(value: V, keys: StreamSource<K>): WithKeyValue<Tp, K, V>['normal'];
Parameters
| Name | Type | Description |
|---|---|---|
value | V | the entry value |
keys | StreamSource.NonEmpty<K> | a StreamSource containing keys to associate with the given value |
HashBiMultiMap.of([1, 1]).setKeys(1, [2, 3]).toArray()
// => [[1, 1], [2, 1], [3, 1]]
setValues
Returns the collection with the values from the given values StreamSource associated with the given key.
setValuesvalues StreamSource associated with the given key.Definitions
setValues(key: K, values: StreamSource.NonEmpty<V>): WithKeyValue<Tp, K, V>['nonEmpty'];
setValues(key: K, values: StreamSource<V>): WithKeyValue<Tp, K, V>['normal'];
Parameters
| Name | Type | Description |
|---|---|---|
key | K | the entry key |
values | StreamSource.NonEmpty<V> | a StreamSource containing values to associate with the given key |
HashBiMultiMap.of([1, 1]).setValues(1, [2, 3]).toArray()
// => [[1, 1], [1, 2], [1, 3]]
stream
Returns a Stream containing all entries of this collection as tuples of key and value.
streamStream containing all entries of this collection as tuples of key and value.streamKeys
Returns a Stream containing all keys of this collection.
streamKeysStream containing all keys of this collection.streamValues
Returns a Stream containing all values of this collection.
streamValuesStream containing all values of this collection.toArray
Returns an array containing all entries in this collection.
toArrayDefinition
toArray(): [K, V][];
HashBiMultiMap.of([1, 'a'], [2, 'b']).toArray() // => [[1, 'a'], [2, 'b']]
O(log(N))
toBuilder
Returns a builder object containing the entries of this collection.
toBuilderDefinition
toBuilder(): WithKeyValue<Tp, K, V>['builder'];
const builder: HashBiMultiMap.Builder<number, string> = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
toJSON
Returns a JSON representation of this collection.
toJSON