@ac-kit/data 0.3.2 → 0.4.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/CHANGELOG.md +59 -0
- package/README.md +2 -2
- package/dist/bit/bit-set.d.ts.map +1 -1
- package/dist/bit/bit-set.js +3 -3
- package/dist/bit/bit-set.js.map +1 -1
- package/dist/bit/bit-vector.js +2 -2
- package/dist/bit/bit-vector.js.map +1 -1
- package/dist/cache/_lru-store.d.ts +4 -0
- package/dist/cache/_lru-store.d.ts.map +1 -1
- package/dist/cache/_lru-store.js +16 -1
- package/dist/cache/_lru-store.js.map +1 -1
- package/dist/cache/lru-map.d.ts +16 -0
- package/dist/cache/lru-map.d.ts.map +1 -1
- package/dist/cache/lru-map.js +20 -0
- package/dist/cache/lru-map.js.map +1 -1
- package/dist/cache/ttl-map.d.ts.map +1 -1
- package/dist/cache/ttl-map.js +3 -3
- package/dist/cache/ttl-map.js.map +1 -1
- package/dist/collection/_bounded.d.ts.map +1 -1
- package/dist/collection/_bounded.js +2 -1
- package/dist/collection/_bounded.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/multiset/multi-set.d.ts +1 -1
- package/dist/multiset/multi-set.d.ts.map +1 -1
- package/dist/multiset/multi-set.js +2 -1
- package/dist/multiset/multi-set.js.map +1 -1
- package/dist/probabilistic/bloom-filter.js +3 -3
- package/dist/probabilistic/bloom-filter.js.map +1 -1
- package/dist/probabilistic/count-min-sketch.d.ts.map +1 -1
- package/dist/probabilistic/count-min-sketch.js +4 -3
- package/dist/probabilistic/count-min-sketch.js.map +1 -1
- package/dist/probabilistic/cuckoo-filter.d.ts.map +1 -1
- package/dist/probabilistic/cuckoo-filter.js +3 -2
- package/dist/probabilistic/cuckoo-filter.js.map +1 -1
- package/dist/probabilistic/hyper-log-log.d.ts.map +1 -1
- package/dist/probabilistic/hyper-log-log.js +2 -1
- package/dist/probabilistic/hyper-log-log.js.map +1 -1
- package/dist/probabilistic/top-k.d.ts.map +1 -1
- package/dist/probabilistic/top-k.js +2 -1
- package/dist/probabilistic/top-k.js.map +1 -1
- package/dist/similarity/vp-tree.d.ts +8 -13
- package/dist/similarity/vp-tree.d.ts.map +1 -1
- package/dist/similarity/vp-tree.js +6 -2
- package/dist/similarity/vp-tree.js.map +1 -1
- package/dist/storage/ring-vector.d.ts.map +1 -1
- package/dist/storage/ring-vector.js +3 -3
- package/dist/storage/ring-vector.js.map +1 -1
- package/dist/storage/segmented-ring-vector.d.ts.map +1 -1
- package/dist/storage/segmented-ring-vector.js +3 -2
- package/dist/storage/segmented-ring-vector.js.map +1 -1
- package/dist/storage/typed-column-ring.d.ts +132 -0
- package/dist/storage/typed-column-ring.d.ts.map +1 -0
- package/dist/storage/typed-column-ring.js +218 -0
- package/dist/storage/typed-column-ring.js.map +1 -0
- package/dist/storage/typed-vector.d.ts.map +1 -1
- package/dist/storage/typed-vector.js +3 -2
- package/dist/storage/typed-vector.js.map +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { assertInteger, describeValue } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* The newest rows of a stream of numbers, kept as one typed array (a
|
|
4
|
+
* `Float64Array`, `Int32Array`, `Float32Array`, …) per column, built like
|
|
5
|
+
* `TypedVector`: `new TypedColumnRing(Float64Array, { columnCount, capacity
|
|
6
|
+
* })`. Numbers are stored as the array type stores them: an `Int32Array` column
|
|
7
|
+
* truncates, a `Float32Array` column rounds. Everything is allocated by the
|
|
8
|
+
* constructor: adding, dropping and reading a row allocate nothing, so a
|
|
9
|
+
* tracker fed at the rate of a pointer or a sensor adds no garbage.
|
|
10
|
+
*
|
|
11
|
+
* A row is a record of `columnCount` numbers — a time, an `x` and a `y`. Rows
|
|
12
|
+
* are numbered by age like `Array.prototype.at` numbers elements: `0` is the
|
|
13
|
+
* oldest, `-1` the newest. Once `capacity` rows are held, each new one replaces
|
|
14
|
+
* the oldest. The columns are plain typed arrays of `capacity` slots, which is
|
|
15
|
+
* the point: a loop reads them directly, or hands one to code that takes a
|
|
16
|
+
* typed array, rather than rebuilding an array per read. `slotAt` gives the
|
|
17
|
+
* slot of a row, `column` the array to index it in.
|
|
18
|
+
*
|
|
19
|
+
* Iterate without allocating:
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* const times = ring.column(0);
|
|
23
|
+
* for (let age = 1; age <= ring.length; age++) {
|
|
24
|
+
* const slot = ring.slotAt(-age); // newest first
|
|
25
|
+
* use(times[slot]!);
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Unlike `RingVector`, which holds one boxed `T` per element, a row is not one
|
|
30
|
+
* element, so this class implements no `IStorage`: it has no `get(index)` that
|
|
31
|
+
* answers a value.
|
|
32
|
+
*
|
|
33
|
+
* Time complexity: O(1) for every operation but `push` (O(`columnCount`)) and
|
|
34
|
+
* `pushAll` (O(rows kept × `columnCount`)). Space complexity: O(`columnCount` ×
|
|
35
|
+
* `capacity`) numbers, allocated once.
|
|
36
|
+
*
|
|
37
|
+
* @template C The typed-array constructor, e.g. `Float64Array`.
|
|
38
|
+
*/
|
|
39
|
+
export class TypedColumnRing {
|
|
40
|
+
/** Numbers in a row. */
|
|
41
|
+
columnCount;
|
|
42
|
+
/** Rows kept. */
|
|
43
|
+
capacity;
|
|
44
|
+
columns_;
|
|
45
|
+
// The slot the next row goes to.
|
|
46
|
+
next_ = 0;
|
|
47
|
+
length_ = 0;
|
|
48
|
+
/**
|
|
49
|
+
* @param arrayType - The typed-array constructor of the columns.
|
|
50
|
+
* @throws {RangeError} When `columnCount` or `capacity` is not a positive
|
|
51
|
+
* safe integer, or the columns are too large to allocate.
|
|
52
|
+
*/
|
|
53
|
+
constructor(arrayType, options) {
|
|
54
|
+
assertInteger(options.columnCount, "columnCount", 1);
|
|
55
|
+
assertInteger(options.capacity, "capacity", 1);
|
|
56
|
+
this.columnCount = options.columnCount;
|
|
57
|
+
this.capacity = options.capacity;
|
|
58
|
+
this.columns_ = Array.from({ length: options.columnCount }, () => new arrayType(options.capacity));
|
|
59
|
+
}
|
|
60
|
+
/** Rows held, at most `capacity`. */
|
|
61
|
+
get length() {
|
|
62
|
+
return this.length_;
|
|
63
|
+
}
|
|
64
|
+
/** Whether the next row replaces the oldest. */
|
|
65
|
+
get isFull() {
|
|
66
|
+
return this.length_ === this.capacity;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Adds a newest row and returns its slot, for the caller to write into the
|
|
70
|
+
* columns. The oldest row is replaced when the ring is full. The slot holds
|
|
71
|
+
* the replaced row's numbers, or zeros if it was never used, until written.
|
|
72
|
+
*
|
|
73
|
+
* @returns The slot, in `0 .. capacity - 1`.
|
|
74
|
+
*/
|
|
75
|
+
pushSlot() {
|
|
76
|
+
const slot = this.next_;
|
|
77
|
+
this.next_ = slot + 1 === this.capacity ? 0 : slot + 1;
|
|
78
|
+
if (this.length_ < this.capacity) {
|
|
79
|
+
this.length_++;
|
|
80
|
+
}
|
|
81
|
+
return slot;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Adds a newest row copied from `row`, replacing the oldest when full.
|
|
85
|
+
*
|
|
86
|
+
* @param row - Where the numbers are read from; it may be a view of one of
|
|
87
|
+
* this ring's own columns, read as it was before the call.
|
|
88
|
+
* @param offset - Index in `row` of the first number. Default 0.
|
|
89
|
+
* @returns The row's slot.
|
|
90
|
+
* @throws {RangeError} When `offset` is not a non-negative integer, or fewer
|
|
91
|
+
* than `columnCount` numbers follow it. Nothing is added then.
|
|
92
|
+
*/
|
|
93
|
+
push(row, offset = 0) {
|
|
94
|
+
assertInteger(offset, "offset", 0);
|
|
95
|
+
if (row.length - offset < this.columnCount) {
|
|
96
|
+
throw new RangeError(`row must hold ${this.columnCount} numbers from offset ${offset}, got ${Math.max(0, row.length - offset)}`);
|
|
97
|
+
}
|
|
98
|
+
if (this.isOwnColumn_(row)) {
|
|
99
|
+
// Writing the new row would overwrite numbers still to be read.
|
|
100
|
+
return this.copyRow_(Array.from({ length: this.columnCount }, (_, column) => row[offset + column]), 0);
|
|
101
|
+
}
|
|
102
|
+
return this.copyRow_(row, offset);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Adds consecutive rows, oldest first, as if each were pushed: the ring then
|
|
106
|
+
* holds the newest `capacity` rows of what it held and `rows` together.
|
|
107
|
+
*
|
|
108
|
+
* @param rows - `columnCount` numbers per row, one row after the other; it
|
|
109
|
+
* may be a view of one of this ring's own columns, read as it was before
|
|
110
|
+
* the call.
|
|
111
|
+
* @throws {RangeError} When `rows.length` is not a multiple of `columnCount`.
|
|
112
|
+
* Nothing is added then.
|
|
113
|
+
*/
|
|
114
|
+
pushAll(rows) {
|
|
115
|
+
if (rows.length % this.columnCount !== 0) {
|
|
116
|
+
throw new RangeError(`rows must hold a whole number of rows of ${this.columnCount} numbers, got ${rows.length} numbers`);
|
|
117
|
+
}
|
|
118
|
+
// Writing the rows would overwrite numbers still to be read.
|
|
119
|
+
const source = this.isOwnColumn_(rows) ? Array.from(rows) : rows;
|
|
120
|
+
const rowCount = source.length / this.columnCount;
|
|
121
|
+
// Rows that more than fill the ring would be replaced at once: skip them,
|
|
122
|
+
// moving the write position as pushing them would have.
|
|
123
|
+
const skipped = Math.max(0, rowCount - this.capacity);
|
|
124
|
+
this.next_ = (this.next_ + skipped) % this.capacity;
|
|
125
|
+
for (let row = skipped; row < rowCount; row++) {
|
|
126
|
+
this.copyRow_(source, row * this.columnCount);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Drops the oldest row.
|
|
131
|
+
*
|
|
132
|
+
* @returns Whether there was one.
|
|
133
|
+
*/
|
|
134
|
+
popOldest() {
|
|
135
|
+
if (this.length_ === 0) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
this.length_--;
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
/** Drops every row. The columns keep their numbers until overwritten. */
|
|
142
|
+
clear() {
|
|
143
|
+
this.next_ = 0;
|
|
144
|
+
this.length_ = 0;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The slot of a row, counted like `Array.prototype.at`: `0` is the oldest,
|
|
148
|
+
* `-1` the newest.
|
|
149
|
+
*
|
|
150
|
+
* @throws {RangeError} When `index` is not an integer in `-length .. length -
|
|
151
|
+
* 1`.
|
|
152
|
+
*/
|
|
153
|
+
slotAt(index) {
|
|
154
|
+
const length = this.length_;
|
|
155
|
+
if (!(index >= -length && index < length) || !Number.isInteger(index)) {
|
|
156
|
+
throw new RangeError(`index must be an integer in [${-length}, ${length}), got ${describeValue(index)}`);
|
|
157
|
+
}
|
|
158
|
+
return this.slotOf_(index);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* One number of a row, `undefined` for a row that does not exist, as
|
|
162
|
+
* `Array.prototype.at` answers.
|
|
163
|
+
*
|
|
164
|
+
* @param index - The row, counted as in {@link slotAt}.
|
|
165
|
+
* @param column - The column, in `0 .. columnCount - 1`.
|
|
166
|
+
* @throws {RangeError} When `column` is not an integer in that range.
|
|
167
|
+
*/
|
|
168
|
+
at(index, column) {
|
|
169
|
+
const values = this.column(column);
|
|
170
|
+
const length = this.length_;
|
|
171
|
+
if (!Number.isInteger(index) || index < -length || index >= length) {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
return values[this.slotOf_(index)];
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The typed array of a column, `capacity` slots long, the same array for the
|
|
178
|
+
* ring's life. Index it with a slot from {@link slotAt}, {@link pushSlot} or
|
|
179
|
+
* {@link push}; the slots of rows not held are stale.
|
|
180
|
+
*
|
|
181
|
+
* @throws {RangeError} When `column` is not an integer in `0 .. columnCount -
|
|
182
|
+
* 1`.
|
|
183
|
+
*/
|
|
184
|
+
column(column) {
|
|
185
|
+
const values = this.columns_[column];
|
|
186
|
+
if (values === undefined) {
|
|
187
|
+
throw new RangeError(`column must be an integer in [0, ${this.columnCount}), got ${describeValue(column)}`);
|
|
188
|
+
}
|
|
189
|
+
return values;
|
|
190
|
+
}
|
|
191
|
+
// `index` is already known to be a row that exists.
|
|
192
|
+
slotOf_(index) {
|
|
193
|
+
const length = this.length_;
|
|
194
|
+
const slot = this.next_ - length + (index < 0 ? length + index : index);
|
|
195
|
+
return slot < 0 ? slot + this.capacity : slot;
|
|
196
|
+
}
|
|
197
|
+
// Adds a row from `columnCount` numbers already known to be there.
|
|
198
|
+
copyRow_(source, offset) {
|
|
199
|
+
const slot = this.pushSlot();
|
|
200
|
+
for (let column = 0; column < this.columnCount; column++) {
|
|
201
|
+
this.columns_[column][slot] = source[offset + column];
|
|
202
|
+
}
|
|
203
|
+
return slot;
|
|
204
|
+
}
|
|
205
|
+
// Whether `source` is a view of the memory of one of the columns.
|
|
206
|
+
isOwnColumn_(source) {
|
|
207
|
+
if (!ArrayBuffer.isView(source)) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
for (const column of this.columns_) {
|
|
211
|
+
if (column.buffer === source.buffer) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=typed-column-ring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-column-ring.js","sourceRoot":"","sources":["../../src/storage/typed-column-ring.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAY5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,OAAO,eAAe;IAC3B,wBAAwB;IACf,WAAW,CAAS;IAC7B,iBAAiB;IACR,QAAQ,CAAS;IAET,QAAQ,CAA6B;IACtD,iCAAiC;IACz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;IACb,CAAC;IAED,kEAAkE;IAC1D,YAAY,CAAC,MAAyB;QAC7C,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACd,CAAC;QAED,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpC,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;gBACrC,OAAO,IAAI,CAAC;YACb,CAAC;QACF,CAAC;QAED,OAAO,KAAK,CAAC;IACd,CAAC;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-vector.d.ts","sourceRoot":"","sources":["../../src/storage/typed-vector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typed-vector.d.ts","sourceRoot":"","sources":["../../src/storage/typed-vector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,4EAA4E;AAC5E,MAAM,MAAM,qBAAqB,GAC9B,oBAAoB,GACpB,qBAAqB,GACrB,4BAA4B,GAC5B,qBAAqB,GACrB,sBAAsB,GACtB,qBAAqB,GACrB,sBAAsB,GACtB,uBAAuB,GACvB,uBAAuB,CAAC;AAE3B,kEAAkE;AAClE,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,qBAAqB,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;AAE5E,MAAM,MAAM,kBAAkB,GAAG;IAChC,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,WAAW,CACvB,CAAC,SAAS,qBAAqB,CAC9B,YAAW,QAAQ,CAAC,MAAM,CAAC;IAK3B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAJ3B,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,IAAI,CAAK;IAEjB,YACkB,SAAS,EAAE,CAAC,EAC7B,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC3B,OAAO,CAAC,EAAE,kBAAkB,EAuB5B;IAED,0CAA0C;IAC1C,IAAI,cAAc,IAAI,MAAM,CAE3B;IAEA,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAIrC;IAED,KAAK,IAAI,MAAM,CAEd;IAED,KAAK,IAAI,IAAI,CAEZ;IAED,mEAAmE;IACnE,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMrC;IAED;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAQrC;IAED,sBAAsB;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAK3B;IAED,8EAA8E;IAC9E,WAAW,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAS1C;IAED,YAAY;IACZ,OAAO,IAAI,MAAM,GAAG,SAAS,CAU5B;IAED,YAAY;IACZ,IAAI,IAAI,MAAM,GAAG,SAAS,CAEzB;IAED;;;;;OAKG;IACH,YAAY,IAAI,YAAY,CAAC,CAAC,CAAC,CAE9B;IAED,OAAO,CAAC,aAAa;CAerB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describeValue } from "@ac-kit/core";
|
|
1
2
|
const MIN_PHYSICAL_LENGTH = 8;
|
|
2
3
|
/**
|
|
3
4
|
* A growable vector over a fixed-size typed array.
|
|
@@ -29,7 +30,7 @@ export class TypedVector {
|
|
|
29
30
|
this.arrayType = arrayType;
|
|
30
31
|
const initialCapacity = options?.initialCapacity ?? MIN_PHYSICAL_LENGTH;
|
|
31
32
|
if (!Number.isInteger(initialCapacity) || initialCapacity < 0) {
|
|
32
|
-
throw new RangeError(`Initial capacity must be a non-negative integer, got ${initialCapacity}`);
|
|
33
|
+
throw new RangeError(`Initial capacity must be a non-negative integer, got ${describeValue(initialCapacity)}`);
|
|
33
34
|
}
|
|
34
35
|
const items = iterable === undefined ? undefined : Array.from(iterable);
|
|
35
36
|
const physical = Math.max(MIN_PHYSICAL_LENGTH, initialCapacity, items?.length ?? 0);
|
|
@@ -68,7 +69,7 @@ export class TypedVector {
|
|
|
68
69
|
*/
|
|
69
70
|
set(index, item) {
|
|
70
71
|
if (index < 0 || index >= this.size) {
|
|
71
|
-
throw new RangeError(`Index ${index} is out of bounds [0, ${this.size})`);
|
|
72
|
+
throw new RangeError(`Index ${describeValue(index)} is out of bounds [0, ${this.size})`);
|
|
72
73
|
}
|
|
73
74
|
this.data[index] = item;
|
|
74
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-vector.js","sourceRoot":"","sources":["../../src/storage/typed-vector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typed-vector.js","sourceRoot":"","sources":["../../src/storage/typed-vector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAwB7C,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,WAAW;IAOL,SAAS;IAJnB,IAAI,CAAkB;IACtB,IAAI,GAAG,CAAC,CAAC;IAEjB,YACkB,SAAY,EAC7B,QAA2B,EAC3B,OAA4B;yBAFX,SAAS;QAI1B,MAAM,eAAe,GAAG,OAAO,EAAE,eAAe,IAAI,mBAAmB,CAAC;QAExE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,eAAe,GAAG,CAAC,EAAE,CAAC;YAC/D,MAAM,IAAI,UAAU,CACnB,wDAAwD,aAAa,CAAC,eAAe,CAAC,EAAE,CACxF,CAAC;QACH,CAAC;QAED,MAAM,KAAK,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,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AC,EAAE,IAAI,CAAC,IAAI,CAAoB,CAAC;IACzD,CAAC;IAEO,aAAa,CAAC,KAAa;QAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAEnC,IAAI,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YAClC,OAAO;QACR,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,SAAS,CAC/B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,QAAQ,CAAC,CACrB,CAAC;QAErB,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QAE/C,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACnB,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ac-kit/data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Generic data structures: sequences, associative collections, trees, graphs, indexes and probabilistic sketches.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bloom-filter",
|
|
@@ -45,13 +45,14 @@
|
|
|
45
45
|
"prepack": "yarn build"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@ac-kit/core": "^0.
|
|
48
|
+
"@ac-kit/core": "^0.12.0",
|
|
49
49
|
"@types/web": "^0.0.367"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
+
"@ac-kit/math-random": "0.4.0",
|
|
52
53
|
"@ac-kit/tsconfig": "0.1.0",
|
|
53
54
|
"@ac-kit/typedoc-config": "0.1.0",
|
|
54
|
-
"@ac-kit/vitest-config": "0.
|
|
55
|
+
"@ac-kit/vitest-config": "0.2.0",
|
|
55
56
|
"@typescript/native": "typescript@7.0.2",
|
|
56
57
|
"rimraf": "6.1.4",
|
|
57
58
|
"typedoc": "0.28.20",
|