serializable-bptree 3.3.1 → 3.4.0-alpha.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/dist/cjs/index.cjs +29 -0
- package/dist/esm/index.mjs +29 -0
- package/dist/typings/BPTreeAsync.d.ts +1 -0
- package/dist/typings/BPTreeSync.d.ts +1 -0
- package/dist/typings/SerializeStrategyAsync.d.ts +2 -0
- package/dist/typings/SerializeStrategySync.d.ts +2 -0
- package/dist/typings/base/BPTree.d.ts +4 -2
- package/dist/typings/base/SerializeStrategy.d.ts +6 -0
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -436,6 +436,7 @@ var BPTree = class {
|
|
|
436
436
|
root;
|
|
437
437
|
_nodeCreateBuffer;
|
|
438
438
|
_nodeUpdateBuffer;
|
|
439
|
+
_nodeDeleteBuffer;
|
|
439
440
|
verifierMap = {
|
|
440
441
|
gt: (nv, v) => this.comparator.isHigher(nv, v),
|
|
441
442
|
gte: (nv, v) => this.comparator.isHigher(nv, v) || this.comparator.isSame(nv, v),
|
|
@@ -484,6 +485,7 @@ var BPTree = class {
|
|
|
484
485
|
this._cachedRegexp = new CacheBranchSync();
|
|
485
486
|
this._nodeCreateBuffer = /* @__PURE__ */ new Map();
|
|
486
487
|
this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
|
|
488
|
+
this._nodeDeleteBuffer = /* @__PURE__ */ new Map();
|
|
487
489
|
this.nodes = /* @__PURE__ */ new Map();
|
|
488
490
|
this.strategy = strategy;
|
|
489
491
|
this.comparator = comparator;
|
|
@@ -521,6 +523,9 @@ var BPTree = class {
|
|
|
521
523
|
bufferForNodeUpdate(node) {
|
|
522
524
|
this._nodeUpdateBuffer.set(node.id, node);
|
|
523
525
|
}
|
|
526
|
+
bufferForNodeDelete(node) {
|
|
527
|
+
this._nodeDeleteBuffer.set(node.id, node);
|
|
528
|
+
}
|
|
524
529
|
/**
|
|
525
530
|
* Returns the user-defined data stored in the head of the tree.
|
|
526
531
|
* This value can be set using the `setHeadData` method. If no data has been previously inserted, the default value is returned, and the default value is `{}`.
|
|
@@ -644,6 +649,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
644
649
|
}
|
|
645
650
|
if (this.root === node && node.keys.length === 1) {
|
|
646
651
|
const keys2 = node.keys;
|
|
652
|
+
this.bufferForNodeDelete(this.root);
|
|
647
653
|
this.root = this.getNode(keys2[0]);
|
|
648
654
|
this.root.parent = 0;
|
|
649
655
|
this.strategy.head.root = this.root.id;
|
|
@@ -727,6 +733,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
727
733
|
}
|
|
728
734
|
this._deleteEntry(this.getNode(node.parent), node.id, guess);
|
|
729
735
|
this.bufferForNodeUpdate(pointer);
|
|
736
|
+
this.bufferForNodeDelete(node);
|
|
730
737
|
} else {
|
|
731
738
|
if (isPredecessor) {
|
|
732
739
|
let pointerPm;
|
|
@@ -938,6 +945,12 @@ var BPTreeSync = class extends BPTree {
|
|
|
938
945
|
}
|
|
939
946
|
this._nodeUpdateBuffer.clear();
|
|
940
947
|
}
|
|
948
|
+
commitNodeDeleteBuffer() {
|
|
949
|
+
for (const node of this._nodeDeleteBuffer.values()) {
|
|
950
|
+
this.strategy.delete(node.id);
|
|
951
|
+
}
|
|
952
|
+
this._nodeDeleteBuffer.clear();
|
|
953
|
+
}
|
|
941
954
|
keys(condition, filterValues) {
|
|
942
955
|
for (const k in condition) {
|
|
943
956
|
const key = k;
|
|
@@ -1046,6 +1059,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
1046
1059
|
this.commitHeadBuffer();
|
|
1047
1060
|
this.commitNodeCreateBuffer();
|
|
1048
1061
|
this.commitNodeUpdateBuffer();
|
|
1062
|
+
this.commitNodeDeleteBuffer();
|
|
1049
1063
|
}
|
|
1050
1064
|
exists(key, value) {
|
|
1051
1065
|
const node = this.insertableNode(value);
|
|
@@ -1186,6 +1200,7 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1186
1200
|
}
|
|
1187
1201
|
if (this.root === node && node.keys.length === 1) {
|
|
1188
1202
|
const keys2 = node.keys;
|
|
1203
|
+
this.bufferForNodeDelete(this.root);
|
|
1189
1204
|
this.root = await this.getNode(keys2[0]);
|
|
1190
1205
|
this.root.parent = 0;
|
|
1191
1206
|
this.strategy.head.root = this.root.id;
|
|
@@ -1269,6 +1284,7 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1269
1284
|
}
|
|
1270
1285
|
await this._deleteEntry(await this.getNode(node.parent), node.id, guess);
|
|
1271
1286
|
this.bufferForNodeUpdate(pointer);
|
|
1287
|
+
this.bufferForNodeDelete(node);
|
|
1272
1288
|
} else {
|
|
1273
1289
|
if (isPredecessor) {
|
|
1274
1290
|
let pointerPm;
|
|
@@ -1480,6 +1496,12 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1480
1496
|
}
|
|
1481
1497
|
this._nodeUpdateBuffer.clear();
|
|
1482
1498
|
}
|
|
1499
|
+
async commitNodeDeleteBuffer() {
|
|
1500
|
+
for (const node of this._nodeDeleteBuffer.values()) {
|
|
1501
|
+
await this.strategy.delete(node.id);
|
|
1502
|
+
}
|
|
1503
|
+
this._nodeDeleteBuffer.clear();
|
|
1504
|
+
}
|
|
1483
1505
|
async keys(condition, filterValues) {
|
|
1484
1506
|
for (const k in condition) {
|
|
1485
1507
|
const key = k;
|
|
@@ -1588,6 +1610,7 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1588
1610
|
await this.commitHeadBuffer();
|
|
1589
1611
|
await this.commitNodeCreateBuffer();
|
|
1590
1612
|
await this.commitNodeUpdateBuffer();
|
|
1613
|
+
await this.commitNodeDeleteBuffer();
|
|
1591
1614
|
}
|
|
1592
1615
|
async exists(key, value) {
|
|
1593
1616
|
const node = await this.insertableNode(value);
|
|
@@ -1666,6 +1689,9 @@ var InMemoryStoreStrategySync = class extends SerializeStrategySync {
|
|
|
1666
1689
|
write(id, node) {
|
|
1667
1690
|
this.node[id] = node;
|
|
1668
1691
|
}
|
|
1692
|
+
delete(id) {
|
|
1693
|
+
delete this.node[id];
|
|
1694
|
+
}
|
|
1669
1695
|
readHead() {
|
|
1670
1696
|
if (this.head.root === 0) {
|
|
1671
1697
|
return null;
|
|
@@ -1714,6 +1740,9 @@ var InMemoryStoreStrategyAsync = class extends SerializeStrategyAsync {
|
|
|
1714
1740
|
async write(id, node) {
|
|
1715
1741
|
this.node[id] = node;
|
|
1716
1742
|
}
|
|
1743
|
+
async delete(id) {
|
|
1744
|
+
delete this.node[id];
|
|
1745
|
+
}
|
|
1717
1746
|
async readHead() {
|
|
1718
1747
|
if (this.head.root === 0) {
|
|
1719
1748
|
return null;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -402,6 +402,7 @@ var BPTree = class {
|
|
|
402
402
|
root;
|
|
403
403
|
_nodeCreateBuffer;
|
|
404
404
|
_nodeUpdateBuffer;
|
|
405
|
+
_nodeDeleteBuffer;
|
|
405
406
|
verifierMap = {
|
|
406
407
|
gt: (nv, v) => this.comparator.isHigher(nv, v),
|
|
407
408
|
gte: (nv, v) => this.comparator.isHigher(nv, v) || this.comparator.isSame(nv, v),
|
|
@@ -450,6 +451,7 @@ var BPTree = class {
|
|
|
450
451
|
this._cachedRegexp = new CacheBranchSync();
|
|
451
452
|
this._nodeCreateBuffer = /* @__PURE__ */ new Map();
|
|
452
453
|
this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
|
|
454
|
+
this._nodeDeleteBuffer = /* @__PURE__ */ new Map();
|
|
453
455
|
this.nodes = /* @__PURE__ */ new Map();
|
|
454
456
|
this.strategy = strategy;
|
|
455
457
|
this.comparator = comparator;
|
|
@@ -487,6 +489,9 @@ var BPTree = class {
|
|
|
487
489
|
bufferForNodeUpdate(node) {
|
|
488
490
|
this._nodeUpdateBuffer.set(node.id, node);
|
|
489
491
|
}
|
|
492
|
+
bufferForNodeDelete(node) {
|
|
493
|
+
this._nodeDeleteBuffer.set(node.id, node);
|
|
494
|
+
}
|
|
490
495
|
/**
|
|
491
496
|
* Returns the user-defined data stored in the head of the tree.
|
|
492
497
|
* This value can be set using the `setHeadData` method. If no data has been previously inserted, the default value is returned, and the default value is `{}`.
|
|
@@ -610,6 +615,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
610
615
|
}
|
|
611
616
|
if (this.root === node && node.keys.length === 1) {
|
|
612
617
|
const keys2 = node.keys;
|
|
618
|
+
this.bufferForNodeDelete(this.root);
|
|
613
619
|
this.root = this.getNode(keys2[0]);
|
|
614
620
|
this.root.parent = 0;
|
|
615
621
|
this.strategy.head.root = this.root.id;
|
|
@@ -693,6 +699,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
693
699
|
}
|
|
694
700
|
this._deleteEntry(this.getNode(node.parent), node.id, guess);
|
|
695
701
|
this.bufferForNodeUpdate(pointer);
|
|
702
|
+
this.bufferForNodeDelete(node);
|
|
696
703
|
} else {
|
|
697
704
|
if (isPredecessor) {
|
|
698
705
|
let pointerPm;
|
|
@@ -904,6 +911,12 @@ var BPTreeSync = class extends BPTree {
|
|
|
904
911
|
}
|
|
905
912
|
this._nodeUpdateBuffer.clear();
|
|
906
913
|
}
|
|
914
|
+
commitNodeDeleteBuffer() {
|
|
915
|
+
for (const node of this._nodeDeleteBuffer.values()) {
|
|
916
|
+
this.strategy.delete(node.id);
|
|
917
|
+
}
|
|
918
|
+
this._nodeDeleteBuffer.clear();
|
|
919
|
+
}
|
|
907
920
|
keys(condition, filterValues) {
|
|
908
921
|
for (const k in condition) {
|
|
909
922
|
const key = k;
|
|
@@ -1012,6 +1025,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
1012
1025
|
this.commitHeadBuffer();
|
|
1013
1026
|
this.commitNodeCreateBuffer();
|
|
1014
1027
|
this.commitNodeUpdateBuffer();
|
|
1028
|
+
this.commitNodeDeleteBuffer();
|
|
1015
1029
|
}
|
|
1016
1030
|
exists(key, value) {
|
|
1017
1031
|
const node = this.insertableNode(value);
|
|
@@ -1152,6 +1166,7 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1152
1166
|
}
|
|
1153
1167
|
if (this.root === node && node.keys.length === 1) {
|
|
1154
1168
|
const keys2 = node.keys;
|
|
1169
|
+
this.bufferForNodeDelete(this.root);
|
|
1155
1170
|
this.root = await this.getNode(keys2[0]);
|
|
1156
1171
|
this.root.parent = 0;
|
|
1157
1172
|
this.strategy.head.root = this.root.id;
|
|
@@ -1235,6 +1250,7 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1235
1250
|
}
|
|
1236
1251
|
await this._deleteEntry(await this.getNode(node.parent), node.id, guess);
|
|
1237
1252
|
this.bufferForNodeUpdate(pointer);
|
|
1253
|
+
this.bufferForNodeDelete(node);
|
|
1238
1254
|
} else {
|
|
1239
1255
|
if (isPredecessor) {
|
|
1240
1256
|
let pointerPm;
|
|
@@ -1446,6 +1462,12 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1446
1462
|
}
|
|
1447
1463
|
this._nodeUpdateBuffer.clear();
|
|
1448
1464
|
}
|
|
1465
|
+
async commitNodeDeleteBuffer() {
|
|
1466
|
+
for (const node of this._nodeDeleteBuffer.values()) {
|
|
1467
|
+
await this.strategy.delete(node.id);
|
|
1468
|
+
}
|
|
1469
|
+
this._nodeDeleteBuffer.clear();
|
|
1470
|
+
}
|
|
1449
1471
|
async keys(condition, filterValues) {
|
|
1450
1472
|
for (const k in condition) {
|
|
1451
1473
|
const key = k;
|
|
@@ -1554,6 +1576,7 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1554
1576
|
await this.commitHeadBuffer();
|
|
1555
1577
|
await this.commitNodeCreateBuffer();
|
|
1556
1578
|
await this.commitNodeUpdateBuffer();
|
|
1579
|
+
await this.commitNodeDeleteBuffer();
|
|
1557
1580
|
}
|
|
1558
1581
|
async exists(key, value) {
|
|
1559
1582
|
const node = await this.insertableNode(value);
|
|
@@ -1632,6 +1655,9 @@ var InMemoryStoreStrategySync = class extends SerializeStrategySync {
|
|
|
1632
1655
|
write(id, node) {
|
|
1633
1656
|
this.node[id] = node;
|
|
1634
1657
|
}
|
|
1658
|
+
delete(id) {
|
|
1659
|
+
delete this.node[id];
|
|
1660
|
+
}
|
|
1635
1661
|
readHead() {
|
|
1636
1662
|
if (this.head.root === 0) {
|
|
1637
1663
|
return null;
|
|
@@ -1680,6 +1706,9 @@ var InMemoryStoreStrategyAsync = class extends SerializeStrategyAsync {
|
|
|
1680
1706
|
async write(id, node) {
|
|
1681
1707
|
this.node[id] = node;
|
|
1682
1708
|
}
|
|
1709
|
+
async delete(id) {
|
|
1710
|
+
delete this.node[id];
|
|
1711
|
+
}
|
|
1683
1712
|
async readHead() {
|
|
1684
1713
|
if (this.head.root === 0) {
|
|
1685
1714
|
return null;
|
|
@@ -19,6 +19,7 @@ export declare class BPTreeAsync<K, V> extends BPTree<K, V> {
|
|
|
19
19
|
protected commitHeadBuffer(): Promise<void>;
|
|
20
20
|
protected commitNodeCreateBuffer(): Promise<void>;
|
|
21
21
|
protected commitNodeUpdateBuffer(): Promise<void>;
|
|
22
|
+
protected commitNodeDeleteBuffer(): Promise<void>;
|
|
22
23
|
keys(condition: BPTreeCondition<V>, filterValues?: Set<K>): Promise<Set<K>>;
|
|
23
24
|
where(condition: BPTreeCondition<V>): Promise<BPTreePair<K, V>[]>;
|
|
24
25
|
insert(key: K, value: V): Promise<void>;
|
|
@@ -19,6 +19,7 @@ export declare class BPTreeSync<K, V> extends BPTree<K, V> {
|
|
|
19
19
|
protected commitHeadBuffer(): void;
|
|
20
20
|
protected commitNodeCreateBuffer(): void;
|
|
21
21
|
protected commitNodeUpdateBuffer(): void;
|
|
22
|
+
protected commitNodeDeleteBuffer(): void;
|
|
22
23
|
keys(condition: BPTreeCondition<V>, filterValues?: Set<K>): Set<K>;
|
|
23
24
|
where(condition: BPTreeCondition<V>): BPTreePair<K, V>[];
|
|
24
25
|
insert(key: K, value: V): void;
|
|
@@ -5,6 +5,7 @@ export declare abstract class SerializeStrategyAsync<K, V> extends SerializeStra
|
|
|
5
5
|
abstract id(isLeaf: boolean): Promise<number>;
|
|
6
6
|
abstract read(id: number): Promise<BPTreeNode<K, V>>;
|
|
7
7
|
abstract write(id: number, node: BPTreeNode<K, V>): Promise<void>;
|
|
8
|
+
abstract delete(id: number): Promise<void>;
|
|
8
9
|
abstract readHead(): Promise<SerializeStrategyHead | null>;
|
|
9
10
|
abstract writeHead(head: SerializeStrategyHead): Promise<void>;
|
|
10
11
|
getHeadData(key: string, defaultValue: Json): Promise<Json>;
|
|
@@ -17,6 +18,7 @@ export declare class InMemoryStoreStrategyAsync<K, V> extends SerializeStrategyA
|
|
|
17
18
|
id(isLeaf: boolean): Promise<number>;
|
|
18
19
|
read(id: number): Promise<BPTreeNode<K, V>>;
|
|
19
20
|
write(id: number, node: BPTreeNode<K, V>): Promise<void>;
|
|
21
|
+
delete(id: number): Promise<void>;
|
|
20
22
|
readHead(): Promise<SerializeStrategyHead | null>;
|
|
21
23
|
writeHead(head: SerializeStrategyHead): Promise<void>;
|
|
22
24
|
}
|
|
@@ -5,6 +5,7 @@ export declare abstract class SerializeStrategySync<K, V> extends SerializeStrat
|
|
|
5
5
|
abstract id(isLeaf: boolean): number;
|
|
6
6
|
abstract read(id: number): BPTreeNode<K, V>;
|
|
7
7
|
abstract write(id: number, node: BPTreeNode<K, V>): void;
|
|
8
|
+
abstract delete(id: number): void;
|
|
8
9
|
abstract readHead(): SerializeStrategyHead | null;
|
|
9
10
|
abstract writeHead(head: SerializeStrategyHead): void;
|
|
10
11
|
getHeadData(key: string, defaultValue: Json): Json;
|
|
@@ -17,6 +18,7 @@ export declare class InMemoryStoreStrategySync<K, V> extends SerializeStrategySy
|
|
|
17
18
|
id(isLeaf: boolean): number;
|
|
18
19
|
read(id: number): BPTreeNode<K, V>;
|
|
19
20
|
write(id: number, node: BPTreeNode<K, V>): void;
|
|
21
|
+
delete(id: number): void;
|
|
20
22
|
readHead(): SerializeStrategyHead | null;
|
|
21
23
|
writeHead(head: SerializeStrategyHead): void;
|
|
22
24
|
}
|
|
@@ -51,6 +51,7 @@ export declare abstract class BPTree<K, V> {
|
|
|
51
51
|
protected root: BPTreeUnknownNode<K, V>;
|
|
52
52
|
protected readonly _nodeCreateBuffer: Map<number, BPTreeUnknownNode<K, V>>;
|
|
53
53
|
protected readonly _nodeUpdateBuffer: Map<number, BPTreeUnknownNode<K, V>>;
|
|
54
|
+
protected readonly _nodeDeleteBuffer: Map<number, BPTreeUnknownNode<K, V>>;
|
|
54
55
|
protected readonly verifierMap: Record<keyof BPTreeCondition<V>, (nodeValue: V, value: V) => boolean>;
|
|
55
56
|
protected readonly verifierStartNode: Record<keyof BPTreeCondition<V>, (value: V) => Deferred<BPTreeLeafNode<K, V>>>;
|
|
56
57
|
protected readonly verifierDirection: Record<keyof BPTreeCondition<V>, -1 | 1>;
|
|
@@ -124,8 +125,9 @@ export declare abstract class BPTree<K, V> {
|
|
|
124
125
|
*/
|
|
125
126
|
abstract forceUpdate(): Deferred<number>;
|
|
126
127
|
protected _insertAtLeaf(node: BPTreeLeafNode<K, V>, key: K, value: V): void;
|
|
127
|
-
protected bufferForNodeCreate(node: BPTreeUnknownNode<K, V>):
|
|
128
|
-
protected bufferForNodeUpdate(node: BPTreeUnknownNode<K, V>):
|
|
128
|
+
protected bufferForNodeCreate(node: BPTreeUnknownNode<K, V>): void;
|
|
129
|
+
protected bufferForNodeUpdate(node: BPTreeUnknownNode<K, V>): void;
|
|
130
|
+
protected bufferForNodeDelete(node: BPTreeUnknownNode<K, V>): void;
|
|
129
131
|
/**
|
|
130
132
|
* Returns the user-defined data stored in the head of the tree.
|
|
131
133
|
* This value can be set using the `setHeadData` method. If no data has been previously inserted, the default value is returned, and the default value is `{}`.
|
|
@@ -31,6 +31,12 @@ export declare abstract class SerializeStrategy<K, V> {
|
|
|
31
31
|
* @param node This is the JSON object of the node to be stored.
|
|
32
32
|
*/
|
|
33
33
|
abstract write(id: number, node: BPTreeNode<K, V>): void | Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* This method is called when previously created nodes become no longer needed due to deletion or other processes.
|
|
36
|
+
* It can be used to free up space by deleting existing stored nodes.
|
|
37
|
+
* @param id This is the ID of the node to be deleted.
|
|
38
|
+
*/
|
|
39
|
+
abstract delete(id: number): void | Promise<void>;
|
|
34
40
|
/**
|
|
35
41
|
* It is called when the `init` method of the tree instance is called.
|
|
36
42
|
* This method should return the information needed to initialize the tree. This information refers to the values stored in the `writeHead` method.
|