Skip to main content

class HashMapBlockBuilder<K,V>

undocumented

Implements: HashMap.Builder<K,V>

Type parameters

NameDescription
Kundocumented
Vundocumented

Properties

_entries

undocumented

Definition

_entries?: (readonly [K, V])[] | undefined;

_entrySets

undocumented

Definition

_entrySets?: MapBlockBuilderEntry<K, V>[] | undefined;

_lock

undocumented

Definition

_lock: number;

addEntries

undocumented

Definition

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

addEntry

undocumented

Definition

addEntry: (entry: readonly [K, V]) => boolean;

build

undocumented

Definition

build: () => HashMap<K, V>;

buildMapValues

undocumented

Definition

buildMapValues: <V2>(f: (value: V, key: K) => V2) => HashMap<K, V2>;

context

undocumented

Definition

readonly context: HashMapContext<K>;

Overrides

Builder.context

entries

undocumented

Definition

get entries(): (readonly [K, V])[];

entrySets

undocumented

Definition

get entrySets(): MapBlockBuilderEntry<K, V>[];

forEach

undocumented

Definition

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

get

undocumented

Definition

get: <UK, O>(key: RelatedTo<K, UK>, otherwise?: OptLazy<O> |undefined, hash?: number) => V| O;

hasKey

undocumented

Definition

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

isEmpty

Returns true if there are no entries in the builder.

Definition

readonly isEmpty: boolean;

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

Overrides

Builder.isEmpty

level

undocumented

Definition

level: number;

modifyAt

undocumented

Definition

modifyAt: (key: K, options: {
    ifNew?: OptLazyOr<V, Token>;
    ifExists?: V |((currentValue: V, remove: Token) => V| Token);
  }, keyHash?: number) => boolean;

removeKey

undocumented

Definition

removeKey: <UK, O>(key: RelatedTo<K, UK>, otherwise?: OptLazy<O> |undefined) => V| O;

removeKeys

undocumented

Definition

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

set

undocumented

Definition

set: (key: K, value: V) => boolean;

size

undocumented

Definition

size: number;

Overrides

Builder.size

source

undocumented

Definition

source?: HashMapBlock<K, V> | undefined;

updateAt

undocumented

Definition

updateAt: <O>(key: K, update: Update<V>, otherwise?: OptLazy<O> |undefined) => V| O;

Methods

addEntries

Adds given entries to the builder.

Definition

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

Parameters

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

Overrides

Builder.addEntries

addEntry

Adds given entry to the builder.

Definition

addEntry(entry: readonly [K, V]): boolean;

Parameters

NameTypeDescription
entryreadonly [K, V]
example
const m = HashMap.of([1, 'a'], [2, 'b']).toBuilder()
m.addEntry([3, 'c']) // => true
m.addEntry([1, 'a']) // => false

Overrides

Builder.addEntry

addEntryInternal

undocumented

Definition

addEntryInternal(entry: readonly [K, V], hash?: number): boolean;

Parameters

NameTypeDescription
entryreadonly [K, V]
hashnumber

build

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

Definition

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

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

Overrides

Builder.build

buildMapValues

Returns an immutable instance of the entries in this builder, with given mapValues function applied to all the values in the entries.

Definition

buildMapValues<V2>(mapFun: (value: V, key: K) => V2): (Tp & KeyValue<K, V2>)['normal'];

Type parameters

NameDescription
V2

Parameters

NameTypeDescription
mapFun(value: V, key: K) => V2a function that takes an entry value and its key, and returns a new value
example
const m = HashMap.of([1, 'a'], [2, 'b']).toBuilder()
const m2: HashMap<number, number> = m.buildMapValues(value => value.length)

Overrides

Builder.buildMapValues

buildNE

undocumented

Definition

buildNE(): HashMapBlock<K, V>;

checkLock

undocumented

Definition

checkLock(): void;

forEach

Performs given function f for each entry of the builder.

Definition

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

Parameters

NameTypeDescription
f(entry: readonly [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
HashMap.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)

Overrides

Builder.forEach

get

Returns the value associated with the given key, or given otherwise value if the key is not in the collection.

Definitions

get<UK = K>(key: RelatedTo<K, UK>): V | undefined;

get<UK, O>(key: RelatedTo<K, UK>, otherwise: OptLazy<O>): V | O;

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the key to look for
example
const m = HashMap.of([1, 'a'], [2, 'b']).toBuilder()
m.get(2) // => 'b'
m.get(3) // => undefined
m.get(2, 'none') // => 'b'
m.get(3, 'none') // => 'none'

Overrides

Builder.get

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

Overrides

Builder.hasKey

modifyAt

Modifies or creates the builder entry with given atKey as its key according to given options.

Definition

modifyAt(key: K, options: {
      ifNew?: OptLazyOr<V, Token>;
      ifExists?: (<V2 extends V = V>(currentValue: V & V2, remove: Token) => V |Token)| V;
    }): boolean;

Parameters

NameTypeDescription
keyK
options{
      ifNew?: OptLazyOr<V, Token>;
      ifExists?: (<V2 extends V = V>(currentValue: V & V2, remove: Token) => V |Token)| V;
    }
example
const m = HashMap.of([1, 'a'], [2, 'b']).toBuilder()
m.modifyAt(1, { ifNew: 'd' })
// => false
m.modifyAt(3, { ifNew: 'c' })
// => true
m.modifyAt(3, { ifNew: (none) => 1 < 2 ? none : 'c' })
// => false
m.modifyAt(2, { ifExists: () => 'c' })
// => true
m.modifyAt(1, { ifExists: (v) => v + 'z' })
// => true
m.modifyAt(2, { ifExists: (v, remove) => v === 'a' ? v : remove })
// => true

Overrides

Builder.modifyAt

prepareMutate

undocumented

Definition

prepareMutate(): void;

removeKey

Removes the entry with given key from the builder.

Definitions

removeKey<UK = K>(key: RelatedTo<K, UK>): V | undefined;

removeKey<UK, O>(key: RelatedTo<K, UK>, otherwise: OptLazy<O>): V | O;

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the key of the entry to remove
example
const m = HashMap.of([1, 'a'], [2, 'b']).toBuilder()
m.removeKey(2) // => 'b'
m.removeKey(3) // => undefined
m.removeKey(3, 'c') // => 'c'

Overrides

Builder.removeKey

removeKeys

Removes the entries in 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 = HashMap.of([1, 'a'], [2, 'b']).toBuilder()
m.removeKeys([3, 4, 5]) // => false
m.removeKeys([1, 10]) // => true

Overrides

Builder.removeKeys

set

Associates given key with given value in the builder.

Definition

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

Parameters

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

Overrides

Builder.set

updateAt

Updates the value in the builder associated with given key according to given update value or function.

Definitions

updateAt(key: K, update: RMapBase.Update<V>): V | undefined;

updateAt<O>(key: K, update: RMapBase.Update<V>, otherwise: OptLazy<O>): V | O;

Parameters

NameTypeDescription
keyKthe key of the entry to update
updateRMapBase.Update<V>a new value or function taking the previous value and returning a new value
example
const m = HashMap.of([1, 'a'], [2, 'b']).toBuilder()
m.updateAt(1, 'a') // => 'a'
m.updateAt(1, 'b') // => 'b'
m.updateAt(2, v => v + 'z') // => 'b'

Overrides

Builder.updateAt