class MultiSetBuilder<T,Tp,TpG>
undocumented
Implements: MultiSetBase.Builder<T,Tp>
Type parameters
| Name | Constraints | Default | Description |
|---|---|---|---|
| T | undocumented | ||
| Tp | ContextImplTypes | undocumented | |
| TpG | WithElem<Tp, T> | WithElem<Tp, T> | undocumented |
Properties
_countMap
undocumented
_countMapDefinition
_countMap?: RMap.Builder<T, number>;
addAll
undocumented
addAllDefinition
addAll: (source: StreamSource<T>) => boolean;
addEntries
undocumented
addEntriesDefinition
addEntries: (entries: StreamSource<readonly [T, number]>) => boolean;
countMap
undocumented
countMapDefinition
get countMap(): RMap.Builder<T, number>;
forEach
undocumented
forEachDefinition
forEach: (f: (value: T, index: number, halt: () => void) => void, options?: {
state?: TraverseState;
}) => void;
isEmpty
undocumented
isEmptymodifyCount
undocumented
modifyCountDefinition
modifyCount: (value: T, update: (currentCount: number) => number) => boolean;
remove
undocumented
removeremoveAll
undocumented
removeAllDefinition
removeAll: <U>(values: StreamSource<RelatedTo<T, U>>, mode: "SINGLE" | "ALL") => boolean;
removeAllEvery
undocumented
removeAllEveryDefinition
removeAllEvery: <U>(values: StreamSource<RelatedTo<T, U>>) => boolean;
removeAllSingle
undocumented
removeAllSingleDefinition
removeAllSingle: <U>(values: StreamSource<RelatedTo<T, U>>) => boolean;
size
undocumented
sizesizeDistinct
undocumented
sizeDistinctMethods
add
Adds given value to the builder.
addvalue to the builder.addAll
Adds the values in given values StreamSource to the builder.
addAllvalues StreamSource to the builder.Definition
addAll(values: StreamSource<T>): boolean;
Parameters
| Name | Type | Description |
|---|---|---|
values | StreamSource<T> |
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.addAll(1, 3) // => false
s.addAll(2, 10) // => true
Overrides
addEntries
Adds for each tuple of a value and amount in the given entries, the amount of values to the builder.
addEntriesentries, the amount of values to the builder.Definition
addEntries(entries: StreamSource<readonly [T, number]>): boolean;
Parameters
| Name | Type | Description |
|---|---|---|
entries | StreamSource<readonly [T, number]> |
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.addEntries([[1, 2], [2, 3]]) // => true
s.addEntries([[1, 0], [3, 0]]) // => false
Overrides
build
Returns an immutable instance containing the values in this builder.
buildcount
Returns the amount of given value in the builder.
countvalue in the builder.forEach
Performs given function f for each value of the collection, using given state as initial traversal state.
forEachf 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
| Name | Type | Description |
|---|---|---|
f | (value: T, index: number, halt: () => void) => void | the 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 |
RibuError.ModifiedBuilderWhileLoopingOverItError if the builder is modified while looping over it
HashMultiSet.of(1, 2, 2, 3).toBuilder().forEach((entry, i, halt) => {
console.log(entry)
if (i >= 1) halt()
})
// => logs [1, 1] [2, 2]
Overrides
has
Returns true if the given value is present in the builder.
hasvalue is present in the builder.modifyCount
Changes the amount of given value in the builder according to the result of given update function.
modifyCountvalue in the builder according to the result of given update function.Definition
modifyCount(value: T, update: (currentCount: number) => number): boolean;
Parameters
| Name | Type | Description |
|---|---|---|
value | T | the value of which to update the amount |
update | (currentCount: number) => number |
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)
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
remove
Removes given amount or all of given value from the builder.
removeamount or all of given value from the builder.Definition
remove<U = T>(value: RelatedTo<T, U>, amount?: number | 'ALL'): number;
Type parameters
| Name | Default | Description |
|---|---|---|
| U | T |
Parameters
| Name | Type | Description |
|---|---|---|
value | RelatedTo<T, U> | the value to remove |
amount | number | 'ALL' |
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.remove(10) // => 0
s.remove(1, 2) // => 1
s.remove(2, 2) // => 2
Overrides
removeAllEvery
Removes every instance of the given values from the builder.
removeAllEveryvalues from the builder.Definition
removeAllEvery<U = T>(values: StreamSource<RelatedTo<T, U>>): boolean;
Type parameters
| Name | Default | Description |
|---|---|---|
| U | T |
Parameters
| Name | Type | Description |
|---|---|---|
values | StreamSource<RelatedTo<T, U>> |
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.removeAllEvery([10, 11]) // => false
s.removeAllEvery([1, 11]) // => true
Overrides
removeAllSingle
Removes every single value in given values from the builder.
removeAllSinglevalues from the builder.Definition
removeAllSingle<U = T>(values: StreamSource<RelatedTo<T, U>>): boolean;
Type parameters
| Name | Default | Description |
|---|---|---|
| U | T |
Parameters
| Name | Type | Description |
|---|---|---|
values | StreamSource<RelatedTo<T, U>> |
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.removeAllSingle([10, 11]) // => false
s.removeAllSingle([1, 11]) // => true
Overrides
setCount
Sets the amount of given value in the collection to amount.
setCountvalue in the collection to amount.Definition
setCount(value: T, amount: number): boolean;
Parameters
| Name | Type | Description |
|---|---|---|
value | T | the value for which to set the amount |
amount | number |
if amount <= 0, the value will be removed
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.setCount(1, 1) // => false
s.setCount(1, 3) // => true