Skip to main content

interface HashBiMultiMap<K,V>

A type-invariant immutable bi-directional MultiMap where keys and values have a many-to-many mapping. Its keys and values are hashed. See the BiMultiMap documentation and the HashBiMultiMap API documentation

Companion namespace: HashBiMultiMap

Extends: BiMultiMapBase<K,V,Tp>

Implemented by: HashBiMultiMap.NonEmpty<K,V>

Type parameters

NameDescription
Kthe key type
Vthe value type
example
const h1 = HashBiMultiMap.empty<number, string>()
const h1 = HashBiMultiMap.of([1, 'a'], [1, 'b'])

Properties

context

Returns the context associated to this collection instance.

Definition

readonly context: WithKeyValue<Tp, K, V>['context'];

Overrides

BiMultiMapBase.context

isEmpty

Returns false since this collection is known to be non-empty.

Definition

readonly isEmpty: boolean;

example
HashBiMultiMap.of([1, 1], [2, 2]).isEmpty   // => false

Overrides

BiMultiMapBase.isEmpty

keySize

Returns the number of keys

Definition

readonly keySize: number;

example
HashBiMultiMap.of([1, 10], [1, 20]).keySize       // => 1

Overrides

BiMultiMapBase.keySize

keyValueMultiMap

Returns the MultiMap representation of the key to value mapping.

Definition

readonly keyValueMultiMap: WithKeyValue<Tp, K, V>['keyValueMultiMap'];

example
HashBiMultiMap.of([1, 10], [1, 20]).keyValueMap.toArray()
// => [[1, [10, 20]]

Overrides

BiMultiMapBase.keyValueMultiMap

size

Returns the number of entries

Definition

readonly size: number;

example
HashBiMultiMap.of([1, 10], [2, 10]).keySize       // => 2

Overrides

BiMultiMapBase.size

valueKeyMultiMap

Returns the MultiMap representation of the value to key mapping.

Definition

readonly valueKeyMultiMap: WithKeyValue<Tp, K, V>['valueKeyMultiMap'];

example
HashBiMultiMap.of([10, 1], [20, 1]).valueKeyMap.toArray()
// => [[1, [10, 20]]

Overrides

BiMultiMapBase.valueKeyMultiMap

Methods

[Symbol.iterator]

Returns a FastIterator instance used to iterate over the values of this Iterable.

Definition

[Symbol.iterator](): FastIterator<T>;

Overrides

FastIterable.[Symbol.iterator]

add

Returns the collection with the given key associated to the given value.

Definition

add(key: K, value: V): WithKeyValue<Tp, K, V>['nonEmpty'];

Parameters

NameTypeDescription
keyKthe entry key to add
valueVthe entry value to add
example
HashBiMultiMap.of([1, 1], [2, 2]).add(1, 2).toArray()
// => [[1, 1], [1, 2], [2, 2]]

Overrides

BiMultiMapBase.add

addEntries

Returns the collection with the entries from the given StreamSource 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

NameTypeDescription
entriesStreamSource.NonEmpty<readonly [K, V]>a StreamSource containing tuples with a key and value
example
HashBiMultiMap.of([1, 1]).addEntries([[2, 2], [1, 3]]).toArray()
// => [[1, 1], [1, 3], [2, 2]]

Overrides

BiMultiMapBase.addEntries

assumeNonEmpty

Returns the collection as a .NonEmpty type

Definition

assumeNonEmpty(): WithKeyValue<Tp, K, V>['nonEmpty'];

throws

RimbuError.EmptyCollectionAssumedNonEmptyError if the collection is empty

example
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()
note

returns reference to this collection

Overrides

BiMultiMapBase.assumeNonEmpty

filter

Returns a collection containing only those entries that satisfy given pred predicate.

Definition

filter(pred: (entry: [K, V], index: number, halt: () => void) => boolean, options?: {
    negate?: boolean;
  }): WithKeyValue<Tp, K, V>['normal'];

Parameters

NameTypeDescription
pred(entry: [K, V], index: number, halt: () => void) => booleana 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
example
HashBiMultiMap.of([1, 'a'], [2, 'b'], [3, 'c']).filter(entry => entry[0] === 2 || entry[1] === 'c').toArray()
// => [[2, 'b'], [3, 'c']]

Overrides

BiMultiMapBase.filter

forEach

Performs given function f 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

NameTypeDescription
f(entry: [K, V], index: number, halt: () => void) => voidthe 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
example
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]
note

O(N)

Overrides

BiMultiMapBase.forEach

getKeys

Returns a collection containing the keys associated with the given value.

Definition

getKeys<UV = V>(value: RelatedTo<V, UV>): WithKeyValue<Tp, K, V>['valueMultiMapValues'];

Type parameters

NameDefaultDescription
UVV

Parameters

NameTypeDescription
valueRelatedTo<V, UV>the value of which to find the keys
example
const m = HashBiMultiMap.of([1, 1], [2, 1]);
m.getKeys(1).toArray()
// => [1, 2]
m.getKeys(5).toArray()
// => []

Overrides

BiMultiMapBase.getKeys

getValues

Returns a collection containing the values associated with the given key.

Definition

getValues<UK = K>(key: RelatedTo<K, UK>): WithKeyValue<Tp, K, V>['keyMultiMapValues'];

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the key of which to find the values
example
const m = HashBiMultiMap.of([1, 1], [1, 2]);
m.getValues(1).toArray()
// => [1, 2]
m.getValues(5).toArray()
// => []

Overrides

BiMultiMapBase.getValues

hasEntry

Returns true if the given key and value entry is in the collection.

Definition

hasEntry<UK = K, UV = V>(key: RelatedTo<K, UK>, value: RelatedTo<V, UV>): boolean;

Type parameters

NameDefaultDescription
UKK
UVV

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the entry key to look for
valueRelatedTo<V, UV>the entry value to look for
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b'])
m.hasEntry(2, 'b') // => true
m.hasEntry(2, 'c') // => false

Overrides

BiMultiMapBase.hasEntry

hasKey

Returns true if the given key is present in the collection.

Definition

hasKey<UK = K>(key: RelatedTo<K, UK>): boolean;

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the key to look for
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b'])
m.hasKey(2) // => true
m.hasKey(3) // => false

Overrides

BiMultiMapBase.hasKey

hasValue

Returns true if the given value is present in the collection.

Definition

hasValue<UV = V>(key: RelatedTo<V, UV>): boolean;

Type parameters

NameDefaultDescription
UVV

Parameters

NameTypeDescription
keyRelatedTo<V, UV>
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b'])
m.hasKey('a') // => true
m.hasKey('z') // => false

Overrides

BiMultiMapBase.hasValue

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.

Definition

nonEmpty(): this is WithKeyValue<Tp, K, V>['nonEmpty'];

example
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
}

Overrides

BiMultiMapBase.nonEmpty

removeEntries

Returns the collection where the entries in the given entries 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

NameDefaultDescription
UKK
UVV

Parameters

NameTypeDescription
entriesStreamSource<[RelatedTo<K, UK>, RelatedTo<V, UV>]>a StreamSource containing entries to remove
example
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

Overrides

BiMultiMapBase.removeEntries

removeEntry

Returns the collection where the entry with given key 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

NameDefaultDescription
UKK
UVV

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the entry key
valueRelatedTo<V, UV>the entry value
example
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

Overrides

BiMultiMapBase.removeEntry

removeKey

Returns the collection where the entries associated with given key are removed if it was part of the collection.

Definition

removeKey<UK = K>(key: RelatedTo<K, UK>): WithKeyValue<Tp, K, V>['normal'];

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the key of the entries to remove
example
const m = HashBiMultiMap.of([1, 1], [1, 2])
m.removeKey(2).toArray() // => [1, 2]
m.removeKey(3) === m // true
note

guarantees same object reference if the key is not present

Overrides

BiMultiMapBase.removeKey

removeKeys

Returns the collection where the entries associated with each key in given keys are removed if they were present.

Definition

removeKeys<UK = K>(keys: StreamSource<RelatedTo<K, UK>>): WithKeyValue<Tp, K, V>['normal'];

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keysStreamSource<RelatedTo<K, UK>>a StreamSource of keys to remove
example
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
note

guarantees same object reference if none of the keys are present

Overrides

BiMultiMapBase.removeKeys

removeValue

Returns the collection where the entries associated with given value are removed if it was part of the collection.

Definition

removeValue<UV = V>(value: RelatedTo<V, UV>): WithKeyValue<Tp, K, V>['normal'];

Type parameters

NameDefaultDescription
UVV

Parameters

NameTypeDescription
valueRelatedTo<V, UV>the value of the entries to remove
example
const m = HashBiMultiMap.of([1, 2], [2, 2])
m.removeValue(2).toArray() // => [1, 2]
m.removeValue(3) === m // true
note

guarantees same object reference if the key is not present

Overrides

BiMultiMapBase.removeValue

removeValues

Returns the collection where the entries associated with each value in given values are removed if they were present.

Definition

removeValues<UV = V>(values: StreamSource<RelatedTo<V, UV>>): WithKeyValue<Tp, K, V>['normal'];

Type parameters

NameDefaultDescription
UVV

Parameters

NameTypeDescription
valuesStreamSource<RelatedTo<V, UV>>a StreamSource of values to remove
example
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
note

guarantees same object reference if none of the keys are present

Overrides

BiMultiMapBase.removeValues

setKeys

Returns the collection with the keys from the given keys 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

NameTypeDescription
valueVthe entry value
keysStreamSource.NonEmpty<K>a StreamSource containing keys to associate with the given value
example
HashBiMultiMap.of([1, 1]).setKeys(1, [2, 3]).toArray()
// => [[1, 1], [2, 1], [3, 1]]

Overrides

BiMultiMapBase.setKeys

setValues

Returns the collection with the values from the given values 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

NameTypeDescription
keyKthe entry key
valuesStreamSource.NonEmpty<V>a StreamSource containing values to associate with the given key
example
HashBiMultiMap.of([1, 1]).setValues(1, [2, 3]).toArray()
// => [[1, 1], [1, 2], [1, 3]]

Overrides

BiMultiMapBase.setValues

stream

Returns a Stream containing all entries of this collection as tuples of key and value.

Definition

stream(): Stream<[K, V]>;

example
HashBiMultiMap.of([1, 10], [1, 20]).stream().toArray()  // => [[1, 10], [1, 20]]

Overrides

BiMultiMapBase.stream

streamKeys

Returns a Stream containing all keys of this collection.

Definition

streamKeys(): Stream<K>;

example
HashBiMultiMap.of([[1, 'a'], [2, 'b']]).streamKeys().toArray()   // => [1, 2]

Overrides

BiMultiMapBase.streamKeys

streamValues

Returns a Stream containing all values of this collection.

Definition

streamValues(): Stream<V>;

example
HashBiMultiMap.of([[1, 'a'], [2, 'b']]).streamValues().toArray()   // => ['a', 'b']

Overrides

BiMultiMapBase.streamValues

toArray

Returns an array containing all entries in this collection.

Definition

toArray(): [K, V][];

example
HashBiMultiMap.of([1, 'a'], [2, 'b']).toArray()   // => [[1, 'a'], [2, 'b']]
note

O(log(N))

Overrides

BiMultiMapBase.toArray

toBuilder

Returns a builder object containing the entries of this collection.

Definition

toBuilder(): WithKeyValue<Tp, K, V>['builder'];

example
const builder: HashBiMultiMap.Builder<number, string> = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()

Overrides

BiMultiMapBase.toBuilder

toJSON

Returns a JSON representation of this collection.

Definition

toJSON(): ToJSON<[K, V[]][], this['context']['typeTag']>;

example
HashBiMultiMap.of([1, 'a'], [2, 'b']).toJSON()   // => { dataType: 'HashBiMultiMap', value: [[1, ['a']], [2, ['b']]] }

Overrides

BiMultiMapBase.toJSON

toString

Returns a string representation of this collection.

Definition

toString(): string;

example
HashBiMultiMap.of([1, 'a'], [2, 'b']).toString()   // => HashBiMultiMap(1 <=> ['a'], 2 <=> ['b'])

Overrides

BiMultiMapBase.toString