interface TableBase<R,C,V,Tp>
undocumented
Companion namespace: TableBase
Extends: VariantTableBase<R,C,V,Tp>
Implemented by: TableEmpty<R,C,V,Tp>
, Table<R,C,V>
, HashTableSortedColumn<R,C,V>
, SortedTableHashColumn<R,C,V>
, TableBase.NonEmpty<R,C,V,Tp>
, SortedTableSortedColumn<R,C,V>
, HashTableHashColumn<R,C,V>
Type parameters
Name | Constraints | Default | Description |
---|---|---|---|
R | undocumented | ||
C | undocumented | ||
V | undocumented | ||
Tp | TableBase.Types | TableBase.Types | undocumented |
Properties
amountRows
Returns the amount of rows in the collection.
amountRows
context
Returns the context
associated to this collection instance.
context
context
associated to this collection instance.isEmpty
Returns true if the collection is empty.
isEmpty
rowMap
Returns the Map representation of this collection.
rowMap
size
Returns the amount of entries in the collection.
size
Methods
[Symbol.iterator]
Returns a FastIterator
instance used to iterate over the values of this Iterable
.
[Symbol.iterator]
FastIterator
instance used to iterate over the values of this Iterable
.addEntries
Returns the collection with the given entries
added.
addEntries
entries
added.Definitions
addEntries(entries:
StreamSource.NonEmpty
<readonly [R, C, V]>):
WithRow
<Tp, R, C, V>['nonEmpty'];
addEntries(entries:
StreamSource
<readonly [R, C, V]>):
WithRow
<Tp, R, C, V>['normal'];
Parameters
Name | Type | Description |
---|---|---|
entries | StreamSource.NonEmpty <readonly [R, C, V]> | a `StreamSource containing entries to add |
const t = HashTableHashColumn.of([1, 2, 3])
t.addEntries([[1, 4, 5], [2, 6, 8]]).toArray()
// => [[1, 2, 3], [1, 4, 5], [2, 6, 8]]
addEntry
Returns the collection with the given entry
added.
addEntry
entry
added.assumeNonEmpty
Returns the collection as a .NonEmpty type
assumeNonEmpty
Definition
assumeNonEmpty():
WithRow
<Tp, R, C, V>['nonEmpty'];
RimbuError.EmptyCollectionAssumedNonEmptyError if the collection is empty
HashTableHashColumn.empty<number, number, number>().assumeNonEmpty() // => throws
const m: Table<number, number, number> = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
const m2: Table.NonEmpty<number, number> = m // => compiler error
const m3: Table.NonEmpty<number, number> = m.assumeNonEmpty()
returns reference to this collection
Overrides
filter
Returns a collection containing only those entries that satisfy given pred
predicate.
filter
pred
predicate.Definition
filter(pred: (entry: [R, C, V], index: number, halt: () => void) => boolean, options?: {
negate?: boolean;
}):
WithRow
<Tp, R, C, V>['normal'];
Parameters
Name | Type | Description |
---|---|---|
pred | (entry: [R, C, V], index: number, halt: () => void) => boolean | a predicate function receiving: - entry : the next entry- index : the entry index- halt : a function that, when called, ensures no next elements are passed |
options | { negate?: boolean; } | object containing the following - negate: (default: false) when true will negate the given predicate |
HashTableHashColumn.of([1, 2, 3], [1, 4, 5], [2, 3, 5])
.filter(entry => entry[2] === 5).toArray()
// => [[1, 4, 5], [2, 3, 5]]
Overrides
filterRows
Returns a collection containing only those rows that satisfy given pred
predicate.
filterRows
pred
predicate.Definition
filterRows(pred: (entry: readonly [R,
WithRow
<Tp, R, C, V>['rowNonEmpty']], index: number, halt: () => void) => boolean, options?: {
negate?: boolean;
}):
WithRow
<Tp, R, C, V>['normal'];
Parameters
Name | Type | Description |
---|---|---|
pred | (entry: readonly [R, WithRow <Tp, R, C, V>['rowNonEmpty']], index: number, halt: () => void) => boolean | a predicate function receiving: - entry : the next entry of the row key and a collection representing its columns and values- index : the entry index - halt : a function that, when called, ensures no next elements are passed |
options | { negate?: boolean; } | object containing the following - negate: (default: false) when true will negate the given predicate |
HashTableHashColumn.of([1, 2, 3], [1, 4, 5], [2, 3, 5])
.filterRows((rowKey, values) => rowKey === 1 && values.hasKey(4)).toArray()
// => [[1, 2, 3], [1, 4, 5]]
Overrides
forEach
Performs given function f
for each entry of the collection, using given state
as initial traversal state.
forEach
f
for each entry of the collection, using given state
as initial traversal state.Definition
forEach(f: (entry: [R, C, V], index: number, halt: () => void) => void, options?: {
state?:
TraverseState
;
}): void;
Parameters
Name | Type | Description |
---|---|---|
f | (entry: [R, C, V], index: number, halt: () => void) => void | the function to perform for each entry, receiving: - entry : the next tuple of a row key, column 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 ; } | object containing the following - state: (optional) the traverse state |
HashTableHashColumn.of([1, 2, 3], [1, 4, 5], [2, 3, 5])
.forEach((entry, i, halt) => {
console.log([entry]);
if (i >= 1) halt();
})
// => logs [1, 2, 3] [1, 4, 5]
O(N)
Overrides
get
Returns the value at given row
and column
keys, or the otherwise
value if no value is present.
get
row
and column
keys, or the otherwise
value if no value is present.Definitions
get<UR = R, UC = C>(row:
RelatedTo
<R, UR>, column:
RelatedTo
<C, UC>): V
|
undefined;
get<UR, UC, O>(row:
RelatedTo
<R, UR>, column:
RelatedTo
<C, UC>, otherwise:
OptLazy
<O>): V
|
O;
Type parameters
Name | Default | Description |
---|---|---|
UR | R | |
UC | C |
Parameters
Name | Type | Description |
---|---|---|
row | RelatedTo <R, UR> | the row key |
column | RelatedTo <C, UC> | the column key |
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.get(10, 1) // => undefined
t.get(10, 1, 0) // => 0
t.get(1, 2) // => 3
t.get(1, 2, 0) // => 3
Overrides
getRow
Returns a map containing the column keys and values in the given row
.
getRow
row
.Definition
getRow<UR = R>(row:
RelatedTo
<R, UR>):
WithRow
<Tp, R, C, V>['row'];
Type parameters
Name | Default | Description |
---|---|---|
UR | R |
Parameters
Name | Type | Description |
---|---|---|
row | RelatedTo <R, UR> | the row key |
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.getRow(10).toArray() // => []
t.getRow(1).toArray() // => [[2, 3], [4, 5]]
Overrides
hasRowKey
Returns true if given row
key is in the collection.
hasRowKey
row
key is in the collection.hasValueAt
Returns true if the collection has a value for given row
and column
keys.
hasValueAt
row
and column
keys.Definition
hasValueAt<UR = R, UC = C>(row:
RelatedTo
<R, UR>, column:
RelatedTo
<C, UC>): boolean;
Type parameters
Name | Default | Description |
---|---|---|
UR | R | |
UC | C |
Parameters
Name | Type | Description |
---|---|---|
row | RelatedTo <R, UR> | the row key |
column | RelatedTo <C, UC> | the column key |
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.hasValueAt(10, 1) // => false
t.hasValueAt(1, 4) // => true
Overrides
mapValues
Returns a collection with the same row and column keys, but where the given mapFun
function is applied to each entry value.
mapValues
mapFun
function is applied to each entry value.Definition
mapValues<V2>(mapFun: (value: V, row: R, column: C) => V2): (Tp &
Row
<R, C, V2>)['normal'];
Type parameters
Name | Description |
---|---|
V2 |
Parameters
Name | Type | Description |
---|---|---|
mapFun | (value: V, row: R, column: C) => V2 | a function taking a value and a row and column key, and returning a new value |
HashTableHashColumn.of([1, 2, 3], [1, 4, 5], [2, 3, 5])
.mapValues(value => value * 2)
// => [[1, 2, 6], [1, 4, 10], [2, 3, 10]]
Overrides
modifyAt
Returns the collection with the value at given row
and column
keys modified according to given options
.
modifyAt
row
and column
keys modified according to given options
.Definition
modifyAt(row: R, column: C, options: {
ifNew?:
OptLazyOr
<V, Token>;
ifExists?: ((value: V, remove: Token) => V
|
Token)
|
V;
}):
WithRow
<Tp, R, C, V>['normal'];
Parameters
Name | Type | Description |
---|---|---|
row | R | the row key |
column | C | the column key |
options | { ifNew?: OptLazyOr <V, Token>; ifExists?: ((value: V, remove: Token) => V | Token) | V; } | an object containing the following information: - ifNew: (optional) if the given row-column combination has no value in the collection, this value or function will be used to generate new values. If a function returning the token argument is given, no new entry is created. - ifExists: (optional) if the row-column combination has a value, this function is called with the current value to return a new value. As a second argument, a remove token is given. If the function returns this token, the current entry is removed. |
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.modifyAt(2, 5, { ifNew: 8 }).toArray()
// => [[1, 2, 3], [1, 4, 5], [2, 5, 8]]
t.modifyAt(2, 5, { ifNew: (none) => 1 < 2 ? none : 8 }).toArray()
// => [[1, 2, 3], [1, 4, 5]]
t.modifyAt(1, 2, { ifExists: (v) => v * 2 }).toArray()
// => [[1, 2, 6], [1, 4, 5]]
t.modifyAt(1, 2, { ifExists: (v, remove) => remove }).toArray()
// => [[1, 4, 5]]
nonEmpty
Returns true if there is at least one entry in the collection, and instructs the compiler to treat the collection as a .NonEmpty type.
nonEmpty
Definition
nonEmpty(): this is
WithRow
<Tp, R, C, V>['nonEmpty'];
const m: Table<number, number> = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
m.stream().first(0) // compiler allows fallback value since the Stream may be empty
if (m.nonEmpty()) {
m.stream().first(0) // compiler error: fallback value not allowed since Stream is not empty
}
Overrides
remove
Returns the collection where the value at given row
and column
keys is removed.
remove
row
and column
keys is removed.Definition
remove<UR = R, UC = C>(row:
RelatedTo
<R, UR>, column:
RelatedTo
<C, UC>):
WithRow
<Tp, R, C, V>['normal'];
Type parameters
Name | Default | Description |
---|---|---|
UR | R | |
UC | C |
Parameters
Name | Type | Description |
---|---|---|
row | RelatedTo <R, UR> | the row key |
column | RelatedTo <C, UC> | the column key |
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.remove(10, 11).toArray() // => [[1, 2, 3], [1, 4, 5]]
t.remove(1, 4).toArray() // => [[1, 2, 3]]
Overrides
removeAndGet
Returns a tuple containing the collection with the value at given row
and column
removed, and the removed value. If no such value is found, it returns undefined.
removeAndGet
row
and column
removed, and the removed value. If no such value is found, it returns undefined.Definition
removeAndGet<UR = R, UC = C>(row:
RelatedTo
<R, UR>, column:
RelatedTo
<C, UC>): [
WithRow
<Tp, R, C, V>['normal'], V]
|
undefined;
Type parameters
Name | Default | Description |
---|---|---|
UR | R | |
UC | C |
Parameters
Name | Type | Description |
---|---|---|
row | RelatedTo <R, UR> | the row key |
column | RelatedTo <C, UC> | the column key |
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.removeAndGet(10, 11) // => undefined
t.removeAndGet(1, 2) // => [HashTableHashColumn([1, 4, 5]), 3]
Overrides
removeEntries
Returns the collection where the given entries
are removed.
removeEntries
entries
are removed.Definition
removeEntries<UR = R, UC = C>(entries:
StreamSource
<[
RelatedTo
<R, UR>,
RelatedTo
<C, UC>]>):
WithRow
<Tp, R, C, V>['normal'];
Type parameters
Name | Default | Description |
---|---|---|
UR | R | |
UC | C |
Parameters
Name | Type | Description |
---|---|---|
entries | StreamSource <[ RelatedTo <R, UR>, RelatedTo <C, UC>]> | a StreamSource of table entries |
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.removeEntries([[6, 7, 8], [7, 8, 9]]).toArray() // => [[1, 2, 3], [1, 4, 5]]
t.removeEntries([[6, 7, 8], [1, 2, 3]]).toArray() // => [[1, 4, 5]]
Overrides
removeRow
Returns the collection where all values in given row
are removed.
removeRow
row
are removed.Definition
removeRow<UR = R>(row:
RelatedTo
<R, UR>):
WithRow
<Tp, R, C, V>['normal'];
Type parameters
Name | Default | Description |
---|---|---|
UR | R |
Parameters
Name | Type | Description |
---|---|---|
row | RelatedTo <R, UR> | the row key |
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5], [2, 2, 3])
t.removeRow(10).toArray() // => [[1, 2, 3], [1, 4, 5], [2, 2, 3]]
t.removeRow(1).toArray() // => [[2, 2, 3]]
Overrides
removeRowAndGet
Returns a tuple containing the collection with the values at given row
removed, and a map containing the removed columns and values. If no such row is found, it returns undefined.
removeRowAndGet
row
removed, and a map containing the removed columns and values. If no such row is found, it returns undefined.Definition
removeRowAndGet<UR = R>(row:
RelatedTo
<R, UR>): [
WithRow
<Tp, R, C, V>['normal'],
WithRow
<Tp, R, C, V>['rowNonEmpty']]
|
undefined;
Type parameters
Name | Default | Description |
---|---|---|
UR | R |
Parameters
Name | Type | Description |
---|---|---|
row | RelatedTo <R, UR> | the row key |
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.removeRowAndGet(10) // => undefined
t.removeRowAndGet(1) // => [HashTableHashColumn(), HashMap(2 => 3, 4 => 5)]
Overrides
removeRows
Returns the collection where the values for each row key in given rows
are removed.
removeRows
rows
are removed.Definition
removeRows<UR = R>(rows:
StreamSource
<
RelatedTo
<R, UR>>):
WithRow
<Tp, R, C, V>['normal'];
Type parameters
Name | Default | Description |
---|---|---|
UR | R |
Parameters
Name | Type | Description |
---|---|---|
rows | StreamSource < RelatedTo <R, UR>> | a StreamSource of row keys |
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.removeRows([10, 11]).toArray() // => [[1, 2, 3], [1, 4, 5]]
t.removeRows([1, 10]).toArray() // => []
Overrides
set
Returns the collection where the given value
is associated with the given row
and column
keys.
set
value
is associated with the given row
and column
keys.Definition
set(row: R, column: C, value: V):
WithRow
<Tp, R, C, V>['nonEmpty'];
Parameters
Name | Type | Description |
---|---|---|
row | R | the row key |
column | C | the column key |
value | V | the value to add |
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.set(1, 2, 10).toArray() // => [[1, 2, 10], [1, 4, 5]]
t.set(2, 6, 8).toArray() // => [[1, 2, 3], [1, 4, 5], [2, 6, 8]]
stream
Returns a Stream containing all entries of this collection as tuples of row key, column key, and value.
stream
streamRows
Returns a Stream containing all row keys of this collection.
streamRows
streamValues
Returns a Stream containing all values of this collection.
streamValues
toArray
Returns an array containing all entries in this collection.
toArray
toBuilder
Returns a builder object containing the entries of this collection.
toBuilder
toJSON
Returns a JSON representation of this collection.
toJSON
toString
Returns a string representation of this collection.
toString
updateAt
Returns the collection with the value at given row
and column
keys updated according to the given update
function.
updateAt
row
and column
keys updated according to the given update
function.Definition
updateAt<UR = R, UC = C>(row:
RelatedTo
<R, UR>, column:
RelatedTo
<C, UC>, update:
Update
<V>):
WithRow
<Tp, R, C, V>['normal'];
Type parameters
Name | Default | Description |
---|---|---|
UR | R | |
UC | C |
Parameters
Name | Type | Description |
---|---|---|
row | RelatedTo <R, UR> | the row key |
column | RelatedTo <C, UC> | the column key |
update | Update <V> | a function taking the current value and returning a new value |
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.updateAt(1, 2, v => v * 2).toArray()
// => [[1, 2, 6], [1, 4, 5]]
t.updateAt(3, 4, v => v * 2)
// => [[1, 2, 3], [1, 4, 5]]