Skip to main content

interface BiMultiMapBase.Builder<K,V,Tp>

undocumented

Implemented by: BiMultiMapBuilder<K,V,Tp,TpG>, HashBiMultiMap.Builder<K,V>, SortedBiMultiMap.Builder<K,V>, BiMultiMap.Builder<K,V>

Type parameters

NameConstraintsDefaultDescription
Kundocumented
Vundocumented
TpBiMultiMapBase.TypesBiMultiMapBase.Typesundocumented

Properties

isEmpty

Returns true if there are no entries in the builder.

Definition

readonly isEmpty: boolean;

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

size

Returns the amount of entries in the builder.

Definition

readonly size: number;

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

Methods

add

Associates given key with given value in the builder.

Definition

add(key: K, value: V): boolean;

Parameters

NameTypeDescription
keyKthe entry key
valueV
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.set(1, 'a') // => false
m.set(1, 'b') // => true

addEntries

Adds given entries to the builder.

Definition

addEntries(entries: StreamSource<readonly [K, V]>): boolean;

Parameters

NameTypeDescription
entriesStreamSource<readonly [K, V]>
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.addEntries([1, 'a'], [3, 'c']]) // => true
m.addEntries([]) // => false

build

Returns an immutable collection instance containing the entries in this builder.

Definition

build(): WithKeyValue<Tp, K, V>['normal'];

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

forEach

Performs given function f for each entry of the builder.

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 element, receiving:
- entry: the next key-value entry
- index: the index of the element
- halt: a function that, if called, ensures that no new elements are passed
options{
      state?: TraverseState;
    }
throws

RibuError.ModifiedBuilderWhileLoopingOverItError if the builder is modified while looping over it

example
HashBiMultiMap.of([1, 'a'], [2, 'b'], [3, 'c']).toBuilder().forEach((entry, i, halt) => {
console.log([entry[1], entry[0]]);
if (i >= 1) halt();
})
// => logs ['a', 1] ['b', 2]
note

O(N)

getKeys

Returns a collection representing the keys currently associated with 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 for which to find the keys
note

since it is unsafe to return the internal builder object, the result colleciton will be build upon each call to getKeys.

example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.getKeys('a').toArray() // => [1]
m.getKeys('z').toArray() // => []

getValues

Returns a collection representing the values currently associated with 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 for which to find the values
note

since it is unsafe to return the internal builder object, the result colleciton will be build upon each call to getValues.

example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.getValues(1).toArray() // => ['a']
m.getValues(3).toArray() // => []

hasEntry

Returns true if the given key value entry is present in the builder.

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 key to look for
valueRelatedTo<V, UV>the value to look for
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.hasEntry(1, 'a') // => true
m.hasEntry(1, 'z') // => false

hasKey

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

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']).toBuilder()
m.hasKey(2) // => true
m.hasKey(3) // => false

hasValue

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

Definition

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

Type parameters

NameDefaultDescription
UVV

Parameters

NameTypeDescription
valueRelatedTo<V, UV>the value to look for
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.hasValue('a') // => true
m.hasValue('z') // => false

removeEntries

Removes the entries in the given entries StreamSource from the builder.

Definition

removeEntries<UK = K, UV = V>(entries: StreamSource<[RelatedTo<K, UK>, RelatedTo<V, UV>]>): boolean;

Type parameters

NameDefaultDescription
UKK
UVV

Parameters

NameTypeDescription
entriesStreamSource<[RelatedTo<K, UK>, RelatedTo<V, UV>]>
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.removeEntries([[1, 'c'], ['2', 'a']]) // => false
m.removeEntries([[1, 'a']]) // => true

removeEntry

Removes the entry of given key and value from the builder.

Definition

removeEntry<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
valueRelatedTo<V, UV>
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.removeEntry(1, 'c') // => false
m.removeEntry(1, 'a') // => true

removeKey

Removes the entries related to given key from the builder.

Definition

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

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.removeKey(2) // => true
m.removeKey(3) // => false

removeKeys

Removes the entries related to the given keys StreamSource from the builder.

Definition

removeKeys<UK = K>(keys: StreamSource<RelatedTo<K, UK>>): boolean;

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keysStreamSource<RelatedTo<K, UK>>
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.removeKeys([3, 4, 5]) // => false
m.removeKeys([1, 10]) // => true

removeValue

Removes the entries related to given value from the builder.

Definition

removeValue<UV = V>(value: RelatedTo<V, UV>): boolean;

Type parameters

NameDefaultDescription
UVV

Parameters

NameTypeDescription
valueRelatedTo<V, UV>
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.removeValue('b') // => true
m.removeValue('c') // => false

removeValues

Removes the entries related to the given values StreamSource from the builder.

Definition

removeValues<UV = V>(values: StreamSource<RelatedTo<V, UV>>): boolean;

Type parameters

NameDefaultDescription
UVV

Parameters

NameTypeDescription
valuesStreamSource<RelatedTo<V, UV>>
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.removeValues(['c', 'd', 'e']) // => false
m.removeValues(['a', 'e']) // => true

setKeys

Sets the keys associated to given value to the keys in the given keys StreamSource.

Definition

setKeys(value: V, keys: StreamSource<K>): boolean;

Parameters

NameTypeDescription
valueVthe value to which to associate the keys
keysStreamSource<K>a StreamSource containing the keys to associate to the value
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.setKeys('a', [3, 4]).getKeys('a').toArray() // => [3, 4]

setValues

Sets the values associated to given key to the values in the given values StreamSource.

Definition

setValues(key: K, values: StreamSource<V>): boolean;

Parameters

NameTypeDescription
keyKthe key to which to associate the values
valuesStreamSource<V>a StreamSource containing the values to associate to the key
example
const m = HashBiMultiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.setValues(1, ['b', 'c']).getValues(1).toArray() // => ['b', 'c']