@thi.ng/column-store 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/api.d.ts ADDED
@@ -0,0 +1,101 @@
1
+ import type { FloatType, Fn3, IntType, Maybe, TypedArray, UintType } from "@thi.ng/api";
2
+ import type { BitmapIndex } from "./bitmap.js";
3
+ import type { QueryCtx } from "./query.js";
4
+ import type { Table } from "./table.js";
5
+ export type ColumnSchema = Record<string, ColumnSpec>;
6
+ export type NumericType = IntType | UintType | FloatType;
7
+ export type Cardinality = [number, number];
8
+ export interface ColumnSpec {
9
+ type: NumericType | "num" | "str" | string;
10
+ cardinality: Cardinality;
11
+ flags: number;
12
+ default?: any;
13
+ }
14
+ export interface ColumnTypeSpec {
15
+ /**
16
+ * Factory function to instantiate a colum type for given table, column name
17
+ * & spec.
18
+ */
19
+ impl: Fn3<Table, string, ColumnSpec, IColumn>;
20
+ /**
21
+ * Bit mask of supported flags (default: 0, i.e. none allowed). During
22
+ * column validation, the (inverted) mask will be applied to the user
23
+ * defined flags assigned to a column and will throw an error if the result
24
+ * is non-zero.
25
+ */
26
+ flags?: number;
27
+ /**
28
+ * Supported `[min, max]` number of values per row.
29
+ */
30
+ cardinality: Cardinality;
31
+ /**
32
+ * Only used if min cardinality of this column type is zero, and the type
33
+ * requires at least a (non-null) default value.
34
+ */
35
+ required?: boolean;
36
+ }
37
+ export declare const REQUIRED: Cardinality;
38
+ export declare const OPTIONAL: Cardinality;
39
+ export declare const ONE_PLUS: Cardinality;
40
+ export declare const ZERO_PLUS: Cardinality;
41
+ export declare const FLAG_DICT: number;
42
+ export declare const FLAG_BITMAP: number;
43
+ export declare const FLAG_UNIQUE: number;
44
+ export declare const FLAG_RLE: number;
45
+ export interface IColumn {
46
+ values: any[] | TypedArray;
47
+ bitmap?: BitmapIndex;
48
+ readonly isArray: boolean;
49
+ load(spec: SerializedColumn): void;
50
+ reindex(): void;
51
+ validate(value: any): boolean;
52
+ getRow(i: number): any;
53
+ /**
54
+ * Sets the column's value at given row index. Assumes the value has been
55
+ * pre-validated (via {@link IColumn.validate}). If value is null-ish and
56
+ * the column has a configured default, it will be replaced with said value,
57
+ * otherwise an error will be thrown (if the column requires a value, but
58
+ * has no default).
59
+ *
60
+ * @param i
61
+ * @param value
62
+ */
63
+ setRow(i: number, value: any): void;
64
+ removeRow(i: number): void;
65
+ encode(value: any): any;
66
+ decode(value: any): any;
67
+ replaceValue(currValue: any, newValue: any): boolean;
68
+ }
69
+ export interface SerializedTable {
70
+ schema: ColumnSchema;
71
+ columns: Record<string, SerializedColumn>;
72
+ length: number;
73
+ }
74
+ export interface SerializedColumn {
75
+ dict?: SerializedIndex;
76
+ values: any[];
77
+ }
78
+ export interface SerializedIndex {
79
+ index: any[];
80
+ next: number;
81
+ }
82
+ export type Row = Record<string, any>;
83
+ export interface QueryTerm {
84
+ type: string;
85
+ column?: string;
86
+ value: any;
87
+ params?: any;
88
+ }
89
+ export type QueryTermOp = Fn3<QueryCtx, QueryTerm, Maybe<IColumn>, void>;
90
+ export interface QueryTermOpSpec {
91
+ /**
92
+ * Default mode is: "col";
93
+ */
94
+ mode?: "col" | "row";
95
+ /**
96
+ * Query op implementation. Unless {@link QueryTermOpSpec.mode} is `row`,
97
+ * the provided `column` arg is guaranteed to be defined.
98
+ */
99
+ fn: QueryTermOp;
100
+ }
101
+ //# sourceMappingURL=api.d.ts.map
package/api.js ADDED
@@ -0,0 +1,18 @@
1
+ const REQUIRED = [1, 1];
2
+ const OPTIONAL = [0, 1];
3
+ const ONE_PLUS = [1, -1 >>> 0];
4
+ const ZERO_PLUS = [0, -1 >>> 0];
5
+ const FLAG_DICT = 1 << 0;
6
+ const FLAG_BITMAP = 1 << 1;
7
+ const FLAG_UNIQUE = 1 << 2;
8
+ const FLAG_RLE = 1 << 3;
9
+ export {
10
+ FLAG_BITMAP,
11
+ FLAG_DICT,
12
+ FLAG_RLE,
13
+ FLAG_UNIQUE,
14
+ ONE_PLUS,
15
+ OPTIONAL,
16
+ REQUIRED,
17
+ ZERO_PLUS
18
+ };
package/bitmap.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ export declare class BitmapIndex {
2
+ index: Map<any, Bitfield>;
3
+ /**
4
+ * Returns iterator of row IDs (i.e. bit positions) which have been marked
5
+ * as used by given `key`. If `max` is given, only positions < `max` are
6
+ * considered.
7
+ *
8
+ * @param key
9
+ * @param max
10
+ */
11
+ rowIDs(key: any, max?: number): Generator<number, void, unknown>;
12
+ clear(): void;
13
+ ensure(key: any): Bitfield;
14
+ setBit(key: any, rowID: number): void;
15
+ clearBit(key: any, rowID: number): void;
16
+ /**
17
+ * Removes bit at given position in _all_ indices by clearing it and
18
+ * shifting all successive bits 1 bit to the right (towards the start).
19
+ * Essentially similar to `Array.splice()`.
20
+ *
21
+ * @param id
22
+ */
23
+ removeBit(rowID: number): void;
24
+ toJSON(): Record<string, number[]>;
25
+ }
26
+ export declare class Bitfield {
27
+ buffer?: Uint32Array | undefined;
28
+ constructor(buffer?: Uint32Array | undefined);
29
+ ones(max?: number): Generator<number, void, unknown>;
30
+ setBit(id: number): void;
31
+ clearBit(id: number): void;
32
+ ensure(size: number): Uint32Array<ArrayBufferLike>;
33
+ removeBit(id: number): void;
34
+ }
35
+ //# sourceMappingURL=bitmap.d.ts.map
package/bitmap.js ADDED
@@ -0,0 +1,104 @@
1
+ class BitmapIndex {
2
+ index = /* @__PURE__ */ new Map();
3
+ /**
4
+ * Returns iterator of row IDs (i.e. bit positions) which have been marked
5
+ * as used by given `key`. If `max` is given, only positions < `max` are
6
+ * considered.
7
+ *
8
+ * @param key
9
+ * @param max
10
+ */
11
+ rowIDs(key, max = Infinity) {
12
+ return this.index.get(key)?.ones(max) ?? (function* () {
13
+ })();
14
+ }
15
+ clear() {
16
+ this.index.clear();
17
+ }
18
+ ensure(key) {
19
+ let bitmap = this.index.get(key);
20
+ if (!bitmap) this.index.set(key, bitmap = new Bitfield());
21
+ return bitmap;
22
+ }
23
+ setBit(key, rowID) {
24
+ this.ensure(key).setBit(rowID);
25
+ }
26
+ clearBit(key, rowID) {
27
+ this.index.get(key)?.clearBit(rowID);
28
+ }
29
+ /**
30
+ * Removes bit at given position in _all_ indices by clearing it and
31
+ * shifting all successive bits 1 bit to the right (towards the start).
32
+ * Essentially similar to `Array.splice()`.
33
+ *
34
+ * @param id
35
+ */
36
+ removeBit(rowID) {
37
+ for (let bitmap of this.index.values()) bitmap.removeBit(rowID);
38
+ }
39
+ toJSON() {
40
+ const res = {};
41
+ for (let [k, bits] of this.index) {
42
+ if (bits.buffer) res[k] = Array.from(bits.buffer);
43
+ }
44
+ return res;
45
+ }
46
+ }
47
+ class Bitfield {
48
+ constructor(buffer) {
49
+ this.buffer = buffer;
50
+ }
51
+ *ones(max = Infinity) {
52
+ const buf = this.buffer;
53
+ if (!buf) return;
54
+ for (let i = 0, n = buf.length; i < n; i++) {
55
+ let bits = buf[i];
56
+ while (bits) {
57
+ const lsb = bits & -bits;
58
+ const x = (i << 5) + (Math.clz32(lsb) ^ 31);
59
+ if (x >= max) return;
60
+ yield x;
61
+ bits ^= lsb;
62
+ }
63
+ }
64
+ }
65
+ setBit(id) {
66
+ const w = id >>> 5;
67
+ this.ensure(w)[w] |= 1 << (id & 31);
68
+ }
69
+ clearBit(id) {
70
+ const w = id >>> 5;
71
+ this.ensure(w)[w] &= ~(1 << (id & 31));
72
+ }
73
+ ensure(size) {
74
+ const b = this.buffer;
75
+ if (!b || size >= b.length) {
76
+ const tmp = new Uint32Array(size + 1);
77
+ if (b) tmp.set(b);
78
+ return this.buffer = tmp;
79
+ }
80
+ return b;
81
+ }
82
+ removeBit(id) {
83
+ const b = this.buffer;
84
+ if (!b) return;
85
+ const w = id >>> 5;
86
+ const bit = id & 31;
87
+ const end = b.length - 1;
88
+ if (bit === 0) {
89
+ b[w] >>>= 1;
90
+ } else {
91
+ const mask = (1 << bit) - 1;
92
+ b[w] = bit < 31 ? b[w] & mask | b[w] >>> 1 & ~mask : b[w] & mask;
93
+ }
94
+ if (w < end && b[w + 1] & 1) b[w] |= 1 << 31;
95
+ for (let i = w + 1; i <= end; i++) {
96
+ b[i] >>>= 1;
97
+ if (i < end && b[i + 1] & 1) b[i] |= 1 << 31;
98
+ }
99
+ }
100
+ }
101
+ export {
102
+ Bitfield,
103
+ BitmapIndex
104
+ };
@@ -0,0 +1,19 @@
1
+ import type { BidirIndex } from "@thi.ng/bidir-index";
2
+ import { type ColumnSpec, type SerializedIndex } from "../api.js";
3
+ import { BitmapIndex } from "../bitmap.js";
4
+ import type { Table } from "../table.js";
5
+ export declare abstract class AColumn {
6
+ readonly id: string;
7
+ table: Table;
8
+ spec: ColumnSpec;
9
+ bitmap?: BitmapIndex;
10
+ dict?: BidirIndex<any>;
11
+ constructor(id: string, table: Table);
12
+ encode(value: any): any;
13
+ decode(value: any): any;
14
+ protected loadDict(serialized: SerializedIndex): void;
15
+ protected updateBitmap(rows: ArrayLike<any>): void;
16
+ protected ensureValue(val: any): any;
17
+ protected ensureBitmap(): void;
18
+ }
19
+ //# sourceMappingURL=acolumn.d.ts.map
@@ -0,0 +1,55 @@
1
+ import { isArray } from "@thi.ng/checks";
2
+ import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
3
+ import { FLAG_BITMAP } from "../api.js";
4
+ import { BitmapIndex } from "../bitmap.js";
5
+ class AColumn {
6
+ constructor(id, table) {
7
+ this.id = id;
8
+ this.table = table;
9
+ this.spec = table.schema[id];
10
+ this.ensureBitmap();
11
+ }
12
+ spec;
13
+ bitmap;
14
+ dict;
15
+ encode(value) {
16
+ return value;
17
+ }
18
+ decode(value) {
19
+ return value;
20
+ }
21
+ loadDict(serialized) {
22
+ const { dict } = this;
23
+ if (!dict) return;
24
+ dict.clear();
25
+ const index = serialized.index;
26
+ for (let i = 0; i < index.length; i++) {
27
+ if (index[i] != null) {
28
+ dict.fwd.set(index[i], i);
29
+ dict.rev.set(i, index[i]);
30
+ }
31
+ }
32
+ dict.nextID = serialized.next;
33
+ }
34
+ updateBitmap(rows) {
35
+ this.ensureBitmap();
36
+ const { bitmap } = this;
37
+ if (!bitmap) return;
38
+ bitmap.clear();
39
+ for (let i = 0; i < rows.length; i++) {
40
+ const value = rows[i];
41
+ if (isArray(value)) {
42
+ for (let x of value) bitmap.setBit(x, i);
43
+ } else bitmap.setBit(value, i);
44
+ }
45
+ }
46
+ ensureValue(val) {
47
+ return val != null ? val : this.spec.cardinality[0] > 0 ? this.spec.default ?? illegalArgs(`missing value for column: ${this.id}`) : this.spec.default ?? null;
48
+ }
49
+ ensureBitmap() {
50
+ if (this.spec.flags & FLAG_BITMAP) this.bitmap = new BitmapIndex();
51
+ }
52
+ }
53
+ export {
54
+ AColumn
55
+ };
@@ -0,0 +1,19 @@
1
+ import type { Nullable } from "@thi.ng/api";
2
+ import { type IColumn, type SerializedColumn } from "../api.js";
3
+ import { AColumn } from "./acolumn.js";
4
+ export declare class ArrayColumn extends AColumn implements IColumn {
5
+ values: Nullable<number[]>[];
6
+ readonly isArray = true;
7
+ load(spec: SerializedColumn): void;
8
+ reindex(): void;
9
+ encode(value: any): any[];
10
+ validate(value: any): boolean;
11
+ setRow(i: number, value: any[]): void;
12
+ getRow(i: number): Nullable<number[]>;
13
+ removeRow(i: number): void;
14
+ replaceValue(currValue: any, newValue: any): boolean;
15
+ toJSON(): {
16
+ values: Nullable<number[]>[];
17
+ };
18
+ }
19
+ //# sourceMappingURL=array.d.ts.map
@@ -0,0 +1,62 @@
1
+ import { isArray } from "@thi.ng/checks/is-array";
2
+ import { FLAG_UNIQUE } from "../api.js";
3
+ import { __validateArrayValue } from "../internal/checks.js";
4
+ import { AColumn } from "./acolumn.js";
5
+ class ArrayColumn extends AColumn {
6
+ values = [];
7
+ isArray = true;
8
+ load(spec) {
9
+ this.values = spec.values;
10
+ this.reindex();
11
+ }
12
+ reindex() {
13
+ super.updateBitmap(this.values);
14
+ }
15
+ encode(value) {
16
+ return isArray(value) ? value : [value];
17
+ }
18
+ validate(value) {
19
+ return __validateArrayValue(this.spec, value);
20
+ }
21
+ setRow(i, value) {
22
+ value = this.ensureValue(value);
23
+ const { values, bitmap } = this;
24
+ const old = values[i];
25
+ const row = values[i] = value != null ? this.table.schema[this.id].flags & FLAG_UNIQUE ? [...new Set(value)] : value : null;
26
+ if (bitmap) {
27
+ if (old) for (let x of old) bitmap.clearBit(x, i);
28
+ if (row) for (let x of row) bitmap.setBit(x, i);
29
+ }
30
+ }
31
+ getRow(i) {
32
+ return this.values[i];
33
+ }
34
+ removeRow(i) {
35
+ this.values.splice(i, 1);
36
+ this.bitmap?.removeBit(i);
37
+ }
38
+ replaceValue(currValue, newValue) {
39
+ const { values, bitmap } = this;
40
+ const isUnique = this.spec.flags & FLAG_UNIQUE;
41
+ const bits = bitmap?.ensure(newValue);
42
+ bitmap?.index.delete(currValue);
43
+ let result = false;
44
+ for (let i = 0; i < values.length; i++) {
45
+ const row = values[i];
46
+ if (row?.includes(currValue)) {
47
+ let $values = row.map((x) => x === currValue ? newValue : x);
48
+ if (isUnique) $values = [...new Set($values)];
49
+ values[i] = $values;
50
+ bits?.setBit(i);
51
+ result = true;
52
+ }
53
+ }
54
+ return result;
55
+ }
56
+ toJSON() {
57
+ return { values: this.values };
58
+ }
59
+ }
60
+ export {
61
+ ArrayColumn
62
+ };
@@ -0,0 +1,25 @@
1
+ import { BidirIndex } from "@thi.ng/bidir-index";
2
+ import { type IColumn, type SerializedColumn } from "../api.js";
3
+ import { AColumn } from "./acolumn.js";
4
+ export declare class DictArrayColumn extends AColumn implements IColumn {
5
+ values: (number[] | null)[];
6
+ dict: BidirIndex<any>;
7
+ readonly isArray = true;
8
+ load({ dict, values }: SerializedColumn): void;
9
+ reindex(): void;
10
+ encode(value: any): (number | null)[];
11
+ decode(value: any[]): any[];
12
+ validate(value: any): boolean;
13
+ setRow(i: number, value: any[]): void;
14
+ getRow(i: number): any[] | null;
15
+ removeRow(i: number): void;
16
+ replaceValue(currValue: any, newValue: any): boolean;
17
+ toJSON(): {
18
+ dict: {
19
+ index: any;
20
+ next: number;
21
+ };
22
+ values: (number[] | null)[];
23
+ };
24
+ }
25
+ //# sourceMappingURL=dict-array.d.ts.map
@@ -0,0 +1,79 @@
1
+ import { BidirIndex } from "@thi.ng/bidir-index";
2
+ import { isArray } from "@thi.ng/checks/is-array";
3
+ import { FLAG_UNIQUE } from "../api.js";
4
+ import { __validateArrayValue } from "../internal/checks.js";
5
+ import { __serializeDict } from "../internal/serialize.js";
6
+ import { AColumn } from "./acolumn.js";
7
+ class DictArrayColumn extends AColumn {
8
+ values = [];
9
+ dict = new BidirIndex();
10
+ isArray = true;
11
+ load({ dict, values }) {
12
+ this.values = values;
13
+ super.loadDict(dict);
14
+ super.updateBitmap(this.values);
15
+ }
16
+ reindex() {
17
+ const dict = this.dict;
18
+ const newDict = new BidirIndex();
19
+ this.values = this.values.map(
20
+ (ids) => ids ? newDict.addAll(dict.getAllIDs(ids)) : null
21
+ );
22
+ this.dict = newDict;
23
+ super.updateBitmap(this.values);
24
+ }
25
+ encode(value) {
26
+ return this.dict.getAll(isArray(value) ? value : [value], false, true);
27
+ }
28
+ decode(value) {
29
+ return this.dict.getAllIDs(value, false, true);
30
+ }
31
+ validate(value) {
32
+ return __validateArrayValue(this.spec, value);
33
+ }
34
+ setRow(i, value) {
35
+ value = this.ensureValue(value);
36
+ const { values, dict, bitmap } = this;
37
+ const old = values[i];
38
+ const encoded = values[i] = value != null ? this.table.schema[this.id].flags & FLAG_UNIQUE ? [...dict.addAllUnique(value)] : dict.addAll(value) : null;
39
+ if (bitmap) {
40
+ if (old) for (let x of old) bitmap.clearBit(x, i);
41
+ if (encoded) for (let x of encoded) bitmap.setBit(x, i);
42
+ }
43
+ }
44
+ getRow(i) {
45
+ const values = this.values[i];
46
+ return values != null ? this.dict.getAllIDs(values) : null;
47
+ }
48
+ removeRow(i) {
49
+ this.values.splice(i, 1);
50
+ this.bitmap?.removeBit(i);
51
+ }
52
+ replaceValue(currValue, newValue) {
53
+ const { dict, values, bitmap } = this;
54
+ const res = dict.renameKey(currValue, newValue);
55
+ if (res === "ok") return true;
56
+ if (res === "missing") return false;
57
+ const currID = dict.get(currValue);
58
+ const newID = dict.get(newValue);
59
+ const isUnique = this.spec.flags & FLAG_UNIQUE;
60
+ const bits = bitmap?.ensure(newID);
61
+ bitmap?.index.delete(currID);
62
+ for (let i = 0; i < values.length; i++) {
63
+ const row = values[i];
64
+ if (row?.includes(currID)) {
65
+ let $values = row.map((x) => x === currID ? newID : x);
66
+ if (isUnique) $values = [...new Set($values)];
67
+ values[i] = $values;
68
+ bits?.setBit(i);
69
+ }
70
+ }
71
+ return true;
72
+ }
73
+ toJSON() {
74
+ return { dict: __serializeDict(this.dict), values: this.values };
75
+ }
76
+ }
77
+ export {
78
+ DictArrayColumn
79
+ };
@@ -0,0 +1,25 @@
1
+ import { BidirIndex } from "@thi.ng/bidir-index";
2
+ import { type IColumn, type SerializedColumn } from "../api.js";
3
+ import { AColumn } from "./acolumn.js";
4
+ export declare class DictColumn extends AColumn implements IColumn {
5
+ values: (number | null)[];
6
+ dict: BidirIndex<any>;
7
+ readonly isArray = false;
8
+ load({ dict, values }: SerializedColumn): void;
9
+ reindex(): void;
10
+ encode(value: any): number | undefined;
11
+ decode(value: any): any;
12
+ validate(value: any): boolean;
13
+ setRow(i: number, value: any): void;
14
+ getRow(i: number): any;
15
+ removeRow(i: number): void;
16
+ replaceValue(currValue: any, newValue: any): boolean;
17
+ toJSON(): {
18
+ dict: {
19
+ index: any;
20
+ next: number;
21
+ };
22
+ values: (number | null)[];
23
+ };
24
+ }
25
+ //# sourceMappingURL=dict.d.ts.map
@@ -0,0 +1,82 @@
1
+ import { BidirIndex } from "@thi.ng/bidir-index";
2
+ import { decode as decodeRLE, encode as encodeRLE } from "@thi.ng/rle-pack";
3
+ import { FLAG_RLE } from "../api.js";
4
+ import { __validateValue } from "../internal/checks.js";
5
+ import { __serializeDict } from "../internal/serialize.js";
6
+ import { AColumn } from "./acolumn.js";
7
+ class DictColumn extends AColumn {
8
+ values = [];
9
+ dict = new BidirIndex();
10
+ isArray = false;
11
+ load({ dict, values }) {
12
+ this.values = this.spec.flags & FLAG_RLE ? Array.from(decodeRLE(values)) : values;
13
+ super.loadDict(dict);
14
+ super.updateBitmap(this.values);
15
+ }
16
+ reindex() {
17
+ const dict = this.dict;
18
+ const newDict = new BidirIndex();
19
+ this.values = this.values.map(
20
+ (x) => x != null ? newDict.add(dict.getID(x)) : null
21
+ );
22
+ this.dict = newDict;
23
+ super.updateBitmap(this.values);
24
+ }
25
+ encode(value) {
26
+ return this.dict.get(value);
27
+ }
28
+ decode(value) {
29
+ return this.dict.getID(value);
30
+ }
31
+ validate(value) {
32
+ return __validateValue(this.spec, value);
33
+ }
34
+ setRow(i, value) {
35
+ value = this.ensureValue(value);
36
+ const { values, bitmap } = this;
37
+ const old = values[i];
38
+ const encoded = values[i] = value != null ? this.dict.add(value) : null;
39
+ if (bitmap) {
40
+ if (old != null) bitmap.clearBit(old, i);
41
+ if (encoded != null) bitmap?.setBit(encoded, i);
42
+ }
43
+ }
44
+ getRow(i) {
45
+ const value = this.values[i];
46
+ return value != null ? this.dict.getID(value) : null;
47
+ }
48
+ removeRow(i) {
49
+ this.values.splice(i, 1);
50
+ this.bitmap?.removeBit(i);
51
+ }
52
+ replaceValue(currValue, newValue) {
53
+ const { dict, values, bitmap } = this;
54
+ const res = dict.renameKey(currValue, newValue);
55
+ if (res === "ok") return true;
56
+ if (res === "missing") return false;
57
+ const currID = dict.get(currValue);
58
+ const newID = dict.get(newValue);
59
+ const bits = bitmap?.ensure(newID);
60
+ bitmap?.index.delete(currID);
61
+ for (let i = 0; i < values.length; i++) {
62
+ if (values[i] === currID) {
63
+ values[i] = newID;
64
+ bits?.setBit(i);
65
+ }
66
+ }
67
+ return true;
68
+ }
69
+ toJSON() {
70
+ let values = this.values;
71
+ if (this.spec.flags & FLAG_RLE) {
72
+ const numBits = Math.max(1, Math.ceil(Math.log2(this.dict.size)));
73
+ values = Array.from(
74
+ encodeRLE(values, values.length, numBits)
75
+ );
76
+ }
77
+ return { dict: __serializeDict(this.dict), values };
78
+ }
79
+ }
80
+ export {
81
+ DictColumn
82
+ };
@@ -0,0 +1,17 @@
1
+ import type { IColumn, SerializedColumn } from "../api.js";
2
+ import { AColumn } from "./acolumn.js";
3
+ export declare class PlainColumn extends AColumn implements IColumn {
4
+ values: any[];
5
+ readonly isArray = false;
6
+ load(spec: SerializedColumn): void;
7
+ reindex(): void;
8
+ validate(value: any): boolean;
9
+ setRow(i: number, value: any): void;
10
+ getRow(i: number): any;
11
+ removeRow(i: number): void;
12
+ replaceValue(currValue: any, newValue: any): boolean;
13
+ toJSON(): {
14
+ values: any[];
15
+ };
16
+ }
17
+ //# sourceMappingURL=plain.d.ts.map
@@ -0,0 +1,42 @@
1
+ import { __validateValue } from "../internal/checks.js";
2
+ import { __replaceValue } from "../internal/replace.js";
3
+ import { AColumn } from "./acolumn.js";
4
+ class PlainColumn extends AColumn {
5
+ values = [];
6
+ isArray = false;
7
+ load(spec) {
8
+ this.values = spec.values;
9
+ this.reindex();
10
+ }
11
+ reindex() {
12
+ super.updateBitmap(this.values);
13
+ }
14
+ validate(value) {
15
+ return __validateValue(this.spec, value);
16
+ }
17
+ setRow(i, value) {
18
+ const { values, bitmap } = this;
19
+ const old = values[i];
20
+ values[i] = this.ensureValue(value);
21
+ if (bitmap) {
22
+ if (old != null) bitmap.clearBit(old, i);
23
+ if (value != null) bitmap.setBit(value, i);
24
+ }
25
+ }
26
+ getRow(i) {
27
+ return this.values[i];
28
+ }
29
+ removeRow(i) {
30
+ this.values.splice(i, 1);
31
+ this.bitmap?.removeBit(i);
32
+ }
33
+ replaceValue(currValue, newValue) {
34
+ return __replaceValue(this.bitmap, this.values, currValue, newValue);
35
+ }
36
+ toJSON() {
37
+ return { values: this.values };
38
+ }
39
+ }
40
+ export {
41
+ PlainColumn
42
+ };