Skip to main content

class MultiSetBuilder<T,Tp,TpG>

undocumented

Implements: MultiSetBase.Builder<T,Tp>

Type parameters

NameConstraintsDefaultDescription
Tundocumented
TpContextImplTypesundocumented
TpGWithElem<Tp, T>WithElem<Tp, T>undocumented

Properties

_countMap

undocumented

Definition

_countMap?: RMap.Builder<T, number>;

_lock

undocumented

Definition

_lock: number;

_size

undocumented

Definition

_size: number;

add

undocumented

Definition

add: (value: T, amount?: number) => boolean;

addAll

undocumented

Definition

addAll: (source: StreamSource<T>) => boolean;

addEntries

undocumented

Definition

addEntries: (entries: StreamSource<readonly [T, number]>) => boolean;

build

undocumented

Definition

build: () => TpG["normal"];

context

undocumented

Definition

readonly context: TpG['context'];

count

undocumented

Definition

count: <U>(value: RelatedTo<T, U>) => number;

countMap

undocumented

Definition

get countMap(): RMap.Builder<T, number>;

forEach

undocumented

Definition

forEach: (f: (value: T, index: number, halt: () => void) => void, options?: {
    state?: TraverseState;
  }) => void;

has

undocumented

Definition

has: <U>(value: RelatedTo<T, U>) => boolean;

isEmpty

undocumented

Definition

get isEmpty(): boolean;

Overrides

Builder.isEmpty

modifyCount

undocumented

Definition

modifyCount: (value: T, update: (currentCount: number) => number) => boolean;

remove

undocumented

Definition

remove: <U>(value: RelatedTo<T, U>, amount?: number | "ALL") => number;

removeAll

undocumented

Definition

removeAll: <U>(values: StreamSource<RelatedTo<T, U>>, mode: "SINGLE" | "ALL") => boolean;

removeAllEvery

undocumented

Definition

removeAllEvery: <U>(values: StreamSource<RelatedTo<T, U>>) => boolean;

removeAllSingle

undocumented

Definition

removeAllSingle: <U>(values: StreamSource<RelatedTo<T, U>>) => boolean;

setCount

undocumented

Definition

setCount: (value: T, amount: number) => boolean;

size

undocumented

Definition

get size(): number;

Overrides

Builder.size

sizeDistinct

undocumented

Definition

get sizeDistinct(): number;

Overrides

Builder.sizeDistinct

source

undocumented

Definition

source?: TpG["nonEmpty"] | undefined;

Methods

add

Adds given value to the builder.

Definition

add(value: T, amount?: number): boolean;

Parameters

NameTypeDescription
valueT
amountnumber
example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.add(2) // => true
s.add(3, 5) // => true
s.add(3, 0) // => false

Overrides

Builder.add

addAll

Adds the values in given values StreamSource to the builder.

Definition

addAll(values: StreamSource<T>): boolean;

Parameters

NameTypeDescription
valuesStreamSource<T>
example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.addAll(1, 3) // => false
s.addAll(2, 10) // => true

Overrides

Builder.addAll

addEntries

Adds for each tuple of a value and amount in the given entries, the amount of values to the builder.

Definition

addEntries(entries: StreamSource<readonly [T, number]>): boolean;

Parameters

NameTypeDescription
entriesStreamSource<readonly [T, number]>
example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.addEntries([[1, 2], [2, 3]]) // => true
s.addEntries([[1, 0], [3, 0]]) // => false

Overrides

Builder.addEntries

build

Returns an immutable instance containing the values in this builder.

Definition

build(): WithElem<Tp, T>['normal'];

example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
const s2: HashMultiSet<number> = m.build()

Overrides

Builder.build

checkLock

undocumented

Definition

checkLock(): void;

count

Returns the amount of given value in the builder.

Definition

count<U = T>(value: RelatedTo<T, U>): number;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valueRelatedTo<T, U>the value to look for
example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.count(10) // => 0
s.count(2) // => 2

Overrides

Builder.count

forEach

Performs given function f for each value of the collection, using given state as initial traversal state.

Definition

forEach(f: (value: T, index: number, halt: () => void) => void, options?: {
      state?: TraverseState;
    }): void;

Parameters

NameTypeDescription
f(value: T, index: number, halt: () => void) => voidthe function to perform for each value, receiving:
- value: the next value
- index: the index of the value
- halt: a function that, if called, ensures that no new values are passed
options{
      state?: TraverseState;
    }
(optional) an object containing the following properties:
- state: (optional) the traversal state
throws

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

example
HashMultiSet.of(1, 2, 2, 3).toBuilder().forEach((entry, i, halt) => {
console.log(entry)
if (i >= 1) halt()
})
// => logs [1, 1] [2, 2]

Overrides

Builder.forEach

has

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

Definition

has<U = T>(value: RelatedTo<T, U>): boolean;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valueRelatedTo<T, U>the value to look for
example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.has(2) // => true
s.has(10) // => false

Overrides

Builder.has

modifyCount

Changes the amount of given value in the builder according to the result of given update function.

Definition

modifyCount(value: T, update: (currentCount: number) => number): boolean;

Parameters

NameTypeDescription
valueTthe value of which to update the amount
update(currentCount: number) => number
note

if the given value does not exists, the update function is called with 0. @note if the result of update is <= 0, the value will be removed (or not added)

example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.modifyCount(3, v => v) // => false
s.modifyCount(3, v => v + 1) // => true
s.modifyCount(2, v => v + 1) // => true

Overrides

Builder.modifyCount

remove

Removes given amount or all of given value from the builder.

Definition

remove<U = T>(value: RelatedTo<T, U>, amount?: number | 'ALL'): number;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valueRelatedTo<T, U>the value to remove
amountnumber | 'ALL'
example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.remove(10) // => 0
s.remove(1, 2) // => 1
s.remove(2, 2) // => 2

Overrides

Builder.remove

removeAllEvery

Removes every instance of the given values from the builder.

Definition

removeAllEvery<U = T>(values: StreamSource<RelatedTo<T, U>>): boolean;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valuesStreamSource<RelatedTo<T, U>>
example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.removeAllEvery([10, 11]) // => false
s.removeAllEvery([1, 11]) // => true

Overrides

Builder.removeAllEvery

removeAllSingle

Removes every single value in given values from the builder.

Definition

removeAllSingle<U = T>(values: StreamSource<RelatedTo<T, U>>): boolean;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valuesStreamSource<RelatedTo<T, U>>
example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.removeAllSingle([10, 11]) // => false
s.removeAllSingle([1, 11]) // => true

Overrides

Builder.removeAllSingle

setCount

Sets the amount of given value in the collection to amount.

Definition

setCount(value: T, amount: number): boolean;

Parameters

NameTypeDescription
valueTthe value for which to set the amount
amountnumber
note

if amount <= 0, the value will be removed

example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.setCount(1, 1) // => false
s.setCount(1, 3) // => true

Overrides

Builder.setCount