Skip to main content

interface SortedMultiMapSortedValue.Builder<K,V>

A mutable SortedMultiMapSortedValue builder used to efficiently create new immutable instances. See the MultiMap documentation and the SortedMultiMapSortedValue.Builder API documentation

Extends: MultiMapBase.Builder<K,V,Tp>

Type parameters

NameDescription
Kthe key type
Vthe value type

Properties

isEmpty

Returns true if there are no entries in the builder.

Definition

readonly isEmpty: boolean;

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

Overrides

Builder.isEmpty

size

Returns the amount of entries in the builder.

Definition

readonly size: number;

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

Overrides

Builder.size

Methods

add

Adds an entry with given key and value to the builder.

Definition

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

Parameters

NameTypeDescription
keyKthe entry key
valueV

Overrides

Builder.add

addEntries

Adds given entries to the builder.

Definition

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

Parameters

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

Overrides

Builder.addEntries

build

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

Definition

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

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

Overrides

Builder.build

forEach

Performs given function f for each entry of the builder, using given state as initial traversal state.

Definition

forEach(f: (entry: [K, V], index: number, value: () => void) => void, options?: {
      state?: TraverseState;
    }): void;

Parameters

NameTypeDescription
f(entry: [K, V], index: number, value: () => void) => voidthe function to perform for each element, 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;
    }
throws

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

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

O(N)

Overrides

Builder.forEach

getValues

Returns a built immutable collection of the values asssociated with given key

Definition

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

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the key for which to get the associated values
example
const m = HashMultiMapHashValue.of([[1, 'a'], [2, 'b'], [1, 'c']]).toBuilder()
m.getValues(1).toArray() // => ['a', 'c']
m.getValues(10).toArray() // => []

Overrides

Builder.getValues

hasEntry

Returns true if the given value is associated with given key in the builder.

Definition

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

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the key to look for
valueVthe value to look for
example
const m = HashMultiMapHashValue.of([1, 'a'], [2, 'b']).toBuilder()
m.hasEntry(2, 'b') // => true
m.hasEntry(2, 'c') // => false
m.hasEntry(3, 'a') // => false

Overrides

Builder.hasEntry

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 = HashMultiMapHashValue.of([1, 'a'], [2, 'b']).toBuilder()
m.hasKey(2) // => true
m.hasKey(3) // => false

Overrides

Builder.hasKey

removeEntries

Removes the given entries 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 = HashMultiMapHashValue.of([1, 'a'], [2, 'b']).toBuilder()
m.removeEntries([[3, 'a'], [3, 'b']]) // => false
m.removeEntries([[1, 'a'], [3, 'b']]) // => true

Overrides

Builder.removeEntries

removeEntry

Removes the given value from the values associated with given key 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 key at which to remove the value
valueRelatedTo<V, UV>
example
const m = HashMultiMapHashValue.of([1, 'a'], [2, 'b'], [1, 'c']).toBuilder()
m.removeEntry(3, 'a') // => false
m.removeEntry(1, 'a') // => true

Overrides

Builder.removeEntry

removeKey

Removes the values associated with 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 = HashMultiMapHashValue.of([1, 'a'], [2, 'b'], [1, 'c']).toBuilder()
m.removeKey(3) // => false
m.removeKey(1) // => true

Overrides

Builder.removeKey

removeKeys

Removes the values associated with each key of the given keys

Definition

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

Type parameters

NameDefaultDescription
UKK

Parameters

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

Overrides

Builder.removeKeys

setValues

Returns true if the data in the builder has changed

Definition

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

Parameters

NameTypeDescription
keyK
valuesStreamSource<V>
example
const m = HashMultiMapHashValue.of([1, 'a'], [2, 'b']).toBuilder()
m.setValues(1, ['a']) // => false
m.setValues(2, ['c', 'd']) // => true

Overrides

Builder.setValues