Skip to main content

interface VariantTable.NonEmpty<R,C,V>

A non-empty type-variant immutable Table of row key type R, column key type C, and value type V. In the Table, a combination of a row and column key has exactly one value. See the Table documentation and the VariantTable API documentation

Extends: Streamable.NonEmpty<T>, VariantTableBase.NonEmpty<R,C,V,Tp>

Type parameters

NameDescription
Rthe row key type
Cthe column key type
Vthe value type
note

Type-variance means that both the key and value types can be widened in a type-safe way without casting. @note As a consequence of being variant, the type does not contain methods that (can) add new elements to the collection.

Properties

amountRows

Returns the amount of rows in the collection.

Definition

readonly amountRows: number;

example
HashTableHashColumn.empty<number, number, number>().rowSize   // => 0
HashTableHashColumn.of([1, 2, 3], [1, 4, 5]).rowSize // => 1

Overrides

VariantTableBase.amountRows

isEmpty

Returns false since this collection is known to be non-empty

Definition

readonly isEmpty: false;

example
HashTableHashColumn.of([1, 2, 3], [1, 4, 5]).isEmpty   // => false

Overrides

VariantTableBase.isEmptyNonEmpty.isEmpty

rowMap

Returns the Map representation of this collection.

Definition

readonly rowMap: WithRow<Tp, R, C, V>['rowMapNonEmpty'];

example
const m = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
const map: HashMap.NonEmpty<number, HashMap.NonEmpty<number, number>> = m.rowMap

Overrides

VariantTableBase.rowMapNonEmpty.rowMap

size

Returns the amount of entries in the collection.

Definition

readonly size: number;

example
HashTableHashColumn.empty<number, number, number>().size   // => 0
HashTableHashColumn.of([1, 2, 3], [1, 4, 5]).size // => 2

Overrides

VariantTableBase.size

Methods

[Symbol.iterator]

Returns a FastIterator instance used to iterate over the values of this Iterable.

Definition

[Symbol.iterator](): FastIterator<T>;

Overrides

FastIterable.[Symbol.iterator]

asNormal

Returns this collection typed as a 'possibly empty' collection.

Definition

asNormal(): WithRow<Tp, R, C, V>['normal'];

example
Table.of([1, 1, 1], [2, 2, 2]).asNormal();  // type: Table<number, number, number>

Overrides

NonEmpty.asNormal

assumeNonEmpty

Returns a self reference since this collection is known to be non-empty.

Definition

assumeNonEmpty(): this;

example
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t === t.assumeNonEmpty() // => true

Overrides

VariantTableBase.assumeNonEmpty, NonEmpty.assumeNonEmpty

filter

Returns a collection containing only those entries that satisfy given pred predicate.

Definition

filter(pred: (entry: [R, C, V], index: number, halt: () => void) => boolean, options?: {
    negate?: boolean;
  }): WithRow<Tp, R, C, V>['normal'];

Parameters

NameTypeDescription
pred(entry: [R, C, V], index: number, halt: () => void) => booleana 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
example
HashTableHashColumn.of([1, 2, 3], [1, 4, 5], [2, 3, 5])
.filter(entry => entry[2] === 5).toArray()
// => [[1, 4, 5], [2, 3, 5]]

Overrides

VariantTableBase.filter

filterRows

Returns a collection containing only those rows that satisfy given 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

NameTypeDescription
pred(entry: readonly [R, WithRow<Tp, R, C, V>['rowNonEmpty']], index: number, halt: () => void) => booleana 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
example
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

VariantTableBase.filterRows

forEach

Performs given function 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

NameTypeDescription
f(entry: [R, C, V], index: number, halt: () => void) => voidthe 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
example
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]
note

O(N)

Overrides

VariantTableBase.forEach

get

Returns the value at given 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

NameDefaultDescription
URR
UCC

Parameters

NameTypeDescription
rowRelatedTo<R, UR>the row key
columnRelatedTo<C, UC>the column key
example
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

VariantTableBase.get

getRow

Returns a map containing the column keys and values in the given row.

Definition

getRow<UR = R>(row: RelatedTo<R, UR>): WithRow<Tp, R, C, V>['row'];

Type parameters

NameDefaultDescription
URR

Parameters

NameTypeDescription
rowRelatedTo<R, UR>the row key
example
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.getRow(10).toArray() // => []
t.getRow(1).toArray() // => [[2, 3], [4, 5]]

Overrides

VariantTableBase.getRow

hasRowKey

Returns true if given row key is in the collection.

Definition

hasRowKey<UR = R>(row: RelatedTo<R, UR>): boolean;

Type parameters

NameDefaultDescription
URR

Parameters

NameTypeDescription
rowRelatedTo<R, UR>the row key to look for
example
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.hasRowKey(10) // => false
t.hasRowKey(1) // => true

Overrides

VariantTableBase.hasRowKey

hasValueAt

Returns true if the collection has a value for given row and column keys.

Definition

hasValueAt<UR = R, UC = C>(row: RelatedTo<R, UR>, column: RelatedTo<C, UC>): boolean;

Type parameters

NameDefaultDescription
URR
UCC

Parameters

NameTypeDescription
rowRelatedTo<R, UR>the row key
columnRelatedTo<C, UC>the column key
example
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.hasValueAt(10, 1) // => false
t.hasValueAt(1, 4) // => true

Overrides

VariantTableBase.hasValueAt

mapValues

Returns a non-empty collection with the same row and column keys, but where the given mapFun function is applied to each entry value.

Definition

mapValues<V2>(mapFun: (value: V, row: R, column: C) => V2): (Tp & Row<R, C, V2>)['nonEmpty'];

Type parameters

NameDescription
V2

Parameters

NameTypeDescription
mapFun(value: V, row: R, column: C) => V2a function taking a value and a row and column key, and returning a new value
example
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

VariantTableBase.mapValues, NonEmpty.mapValues

nonEmpty

Returns true since this collection is known to be non-empty

Definition

nonEmpty(): this is WithRow<Tp, R, C, V>['nonEmpty'];

example
HashTableHashColumn.of([1, 2, 3], [1, 4, 5]).nonEmpty()   // => true

Overrides

VariantTableBase.nonEmpty, NonEmpty.nonEmpty

remove

Returns the collection where the value at given 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

NameDefaultDescription
URR
UCC

Parameters

NameTypeDescription
rowRelatedTo<R, UR>the row key
columnRelatedTo<C, UC>the column key
example
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

VariantTableBase.remove

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.

Definition

removeAndGet<UR = R, UC = C>(row: RelatedTo<R, UR>, column: RelatedTo<C, UC>): [WithRow<Tp, R, C, V>['normal'], V] | undefined;

Type parameters

NameDefaultDescription
URR
UCC

Parameters

NameTypeDescription
rowRelatedTo<R, UR>the row key
columnRelatedTo<C, UC>the column key
example
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

VariantTableBase.removeAndGet

removeEntries

Returns the collection where the given 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

NameDefaultDescription
URR
UCC

Parameters

NameTypeDescription
entriesStreamSource<[RelatedTo<R, UR>, RelatedTo<C, UC>]>a StreamSource of table entries
example
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

VariantTableBase.removeEntries

removeRow

Returns the collection where all values in given row are removed.

Definition

removeRow<UR = R>(row: RelatedTo<R, UR>): WithRow<Tp, R, C, V>['normal'];

Type parameters

NameDefaultDescription
URR

Parameters

NameTypeDescription
rowRelatedTo<R, UR>the row key
example
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

VariantTableBase.removeRow

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.

Definition

removeRowAndGet<UR = R>(row: RelatedTo<R, UR>): [WithRow<Tp, R, C, V>['normal'], WithRow<Tp, R, C, V>['rowNonEmpty']] | undefined;

Type parameters

NameDefaultDescription
URR

Parameters

NameTypeDescription
rowRelatedTo<R, UR>the row key
example
const t = HashTableHashColumn.of([1, 2, 3], [1, 4, 5])
t.removeRowAndGet(10) // => undefined
t.removeRowAndGet(1) // => [HashTableHashColumn(), HashMap(2 => 3, 4 => 5)]

Overrides

VariantTableBase.removeRowAndGet

removeRows

Returns the collection where the values for each row key in given rows are removed.

Definition

removeRows<UR = R>(rows: StreamSource<RelatedTo<R, UR>>): WithRow<Tp, R, C, V>['normal'];

Type parameters

NameDefaultDescription
URR

Parameters

NameTypeDescription
rowsStreamSource<RelatedTo<R, UR>>a StreamSource of row keys
example
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

VariantTableBase.removeRows

stream

Returns a non-empty Stream of the elements in this collection.

Definition

stream(): Stream.NonEmpty<T>;

Overrides

NonEmpty.stream, NonEmpty.stream

streamRows

Returns a non-empty Stream containing all row keys of this collection.

Definition

streamRows(): Stream.NonEmpty<R>;

example
HashTableHashColumn.of([1, 2, 3], [1, 4, 5]).streamRows().toArray()
// => [1]

Overrides

VariantTableBase.streamRows, NonEmpty.streamRows

streamValues

Returns a non-empty Stream containing all values of this collection.

Definition

streamValues(): Stream.NonEmpty<V>;

example
HashTableHashColumn.of([1, 2, 3], [1, 4, 5]).streamValues().toArray()
// => [3, 5]

Overrides

VariantTableBase.streamValues, NonEmpty.streamValues

toArray

Returns a non-empty array containing all entries in this collection.

Definition

toArray(): ArrayNonEmpty<[R, C, V]>;

example
HashTableHashColumn.of([1, 2, 3], [1, 4, 5]).toArray()
// => [[1, 2, 3], [1, 4, 5]]
note

O(log(N)) @note it is safe to mutate the returned array, however, the array elements are not copied, thus should be treated as read-only

Overrides

VariantTableBase.toArray, NonEmpty.toArray

toJSON

Returns a JSON representation of this collection.

Definition

toJSON(): ToJSON<[R, [C, V][]][]>;

example
HashTableHashColumn.of([1, 2, 3], [1, 4, 5]).toJSON()
// => { dataType: 'HashTableHashColumn', value: [1, [ [2, 3], [4, 5] ] ] }

Overrides

VariantTableBase.toJSON

toString

Returns a string representation of this collection.

Definition

toString(): string;

example
HashTableHashColumn.of([1, 2, 3], [1, 4, 5]).toString()
// => HashTableHashColumn([1, 2] -> 3, [1, 4] -> 5)

Overrides

VariantTableBase.toString