serializable-bptree 3.2.0 → 3.2.2
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.js +49 -46
- package/dist/esm/index.js +49 -46
- package/dist/typings/BPTreeSync.d.ts +3 -3
- package/dist/typings/base/BPTree.d.ts +1 -4
- package/dist/typings/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -81,7 +81,6 @@ var BPTree = class {
|
|
|
81
81
|
root;
|
|
82
82
|
_nodeCreateBuffer;
|
|
83
83
|
_nodeUpdateBuffer;
|
|
84
|
-
_headBuffer;
|
|
85
84
|
verifierMap = {
|
|
86
85
|
gt: (nv, v) => this.comparator.isHigher(nv, v),
|
|
87
86
|
gte: (nv, v) => this.comparator.isHigher(nv, v) || this.comparator.isSame(nv, v),
|
|
@@ -126,19 +125,8 @@ var BPTree = class {
|
|
|
126
125
|
notEqual: true,
|
|
127
126
|
like: true
|
|
128
127
|
};
|
|
129
|
-
get headState() {
|
|
130
|
-
const root = this.root.id;
|
|
131
|
-
const order = this.order;
|
|
132
|
-
const data = this.strategy.head.data;
|
|
133
|
-
return {
|
|
134
|
-
root,
|
|
135
|
-
order,
|
|
136
|
-
data
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
128
|
constructor(strategy, comparator) {
|
|
140
129
|
this._regexpCache = new CacheStorage();
|
|
141
|
-
this._headBuffer = null;
|
|
142
130
|
this._nodeCreateBuffer = /* @__PURE__ */ new Map();
|
|
143
131
|
this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
|
|
144
132
|
this.nodes = /* @__PURE__ */ new Map();
|
|
@@ -172,9 +160,6 @@ var BPTree = class {
|
|
|
172
160
|
this.bufferForNodeUpdate(node);
|
|
173
161
|
}
|
|
174
162
|
}
|
|
175
|
-
bufferForHeadUpdate(head) {
|
|
176
|
-
this._headBuffer = head;
|
|
177
|
-
}
|
|
178
163
|
bufferForNodeCreate(node) {
|
|
179
164
|
this._nodeCreateBuffer.set(node.id, node);
|
|
180
165
|
}
|
|
@@ -196,7 +181,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
196
181
|
constructor(strategy, comparator) {
|
|
197
182
|
super(strategy, comparator);
|
|
198
183
|
}
|
|
199
|
-
_getPairsRightToLeft(value, startNode,
|
|
184
|
+
_getPairsRightToLeft(value, startNode, fullScan, comparator) {
|
|
200
185
|
const pairs = [];
|
|
201
186
|
let node = startNode;
|
|
202
187
|
let done = false;
|
|
@@ -212,7 +197,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
212
197
|
while (j--) {
|
|
213
198
|
pairs.push({ key: keys[j], value: nValue });
|
|
214
199
|
}
|
|
215
|
-
} else if (found && !
|
|
200
|
+
} else if (found && !fullScan) {
|
|
216
201
|
done = true;
|
|
217
202
|
break;
|
|
218
203
|
}
|
|
@@ -225,7 +210,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
225
210
|
}
|
|
226
211
|
return pairs.reverse();
|
|
227
212
|
}
|
|
228
|
-
_getPairsLeftToRight(value, startNode,
|
|
213
|
+
_getPairsLeftToRight(value, startNode, fullScan, comparator) {
|
|
229
214
|
const pairs = [];
|
|
230
215
|
let node = startNode;
|
|
231
216
|
let done = false;
|
|
@@ -239,7 +224,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
239
224
|
for (const key of keys) {
|
|
240
225
|
pairs.push({ key, value: nValue });
|
|
241
226
|
}
|
|
242
|
-
} else if (found && !
|
|
227
|
+
} else if (found && !fullScan) {
|
|
243
228
|
done = true;
|
|
244
229
|
break;
|
|
245
230
|
}
|
|
@@ -252,12 +237,12 @@ var BPTreeSync = class extends BPTree {
|
|
|
252
237
|
}
|
|
253
238
|
return pairs;
|
|
254
239
|
}
|
|
255
|
-
getPairs(value, startNode,
|
|
240
|
+
getPairs(value, startNode, fullScan, comparator, direction) {
|
|
256
241
|
switch (direction) {
|
|
257
242
|
case -1:
|
|
258
|
-
return this._getPairsRightToLeft(value, startNode,
|
|
243
|
+
return this._getPairsRightToLeft(value, startNode, fullScan, comparator);
|
|
259
244
|
case 1:
|
|
260
|
-
return this._getPairsLeftToRight(value, startNode,
|
|
245
|
+
return this._getPairsLeftToRight(value, startNode, fullScan, comparator);
|
|
261
246
|
default:
|
|
262
247
|
throw new Error(`Direction must be -1 or 1. but got a ${direction}`);
|
|
263
248
|
}
|
|
@@ -306,7 +291,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
306
291
|
const keys = node.keys;
|
|
307
292
|
this.root = this.getNode(keys[0]);
|
|
308
293
|
this.root.parent = 0;
|
|
309
|
-
this.
|
|
294
|
+
this.strategy.head.root = this.root.id;
|
|
310
295
|
this.bufferForNodeUpdate(this.root);
|
|
311
296
|
return;
|
|
312
297
|
} else if (this.root === node) {
|
|
@@ -512,9 +497,9 @@ var BPTreeSync = class extends BPTree {
|
|
|
512
497
|
if (this.root === node) {
|
|
513
498
|
const root = this._createNode([node.id, pointer.id], [value]);
|
|
514
499
|
this.root = root;
|
|
500
|
+
this.strategy.head.root = root.id;
|
|
515
501
|
node.parent = root.id;
|
|
516
502
|
pointer.parent = root.id;
|
|
517
|
-
this.bufferForHeadUpdate(this.headState);
|
|
518
503
|
this.bufferForNodeCreate(root);
|
|
519
504
|
this.bufferForNodeUpdate(node);
|
|
520
505
|
this.bufferForNodeUpdate(pointer);
|
|
@@ -562,12 +547,13 @@ var BPTreeSync = class extends BPTree {
|
|
|
562
547
|
if (head === null) {
|
|
563
548
|
this.order = this.strategy.order;
|
|
564
549
|
this.root = this._createNode([], [], true);
|
|
565
|
-
this.
|
|
550
|
+
this.strategy.head.root = this.root.id;
|
|
566
551
|
this.bufferForNodeCreate(this.root);
|
|
567
552
|
this.commitHeadBuffer();
|
|
568
553
|
this.commitNodeCreateBuffer();
|
|
569
554
|
} else {
|
|
570
555
|
const { root, order } = head;
|
|
556
|
+
this.strategy.head = head;
|
|
571
557
|
this.order = order;
|
|
572
558
|
this.root = this.getNode(root);
|
|
573
559
|
}
|
|
@@ -610,10 +596,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
610
596
|
return node;
|
|
611
597
|
}
|
|
612
598
|
commitHeadBuffer() {
|
|
613
|
-
|
|
614
|
-
this.strategy.writeHead(this._headBuffer);
|
|
615
|
-
}
|
|
616
|
-
this.bufferForHeadUpdate(null);
|
|
599
|
+
this.strategy.writeHead(this.strategy.head);
|
|
617
600
|
}
|
|
618
601
|
commitNodeCreateBuffer() {
|
|
619
602
|
for (const node of this._nodeCreateBuffer.values()) {
|
|
@@ -638,12 +621,18 @@ var BPTreeSync = class extends BPTree {
|
|
|
638
621
|
const comparator = this.verifierMap[key];
|
|
639
622
|
const pairs = this.getPairs(value, startNode, fullScan, comparator, direction);
|
|
640
623
|
if (result === null) {
|
|
641
|
-
result = pairs.map((pair) => pair.key);
|
|
624
|
+
result = new Set(pairs.map((pair) => pair.key));
|
|
642
625
|
} else {
|
|
643
|
-
|
|
626
|
+
const intersections = /* @__PURE__ */ new Set();
|
|
627
|
+
for (const pair of pairs) {
|
|
628
|
+
if (result.has(pair.key)) {
|
|
629
|
+
intersections.add(pair.key);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
result = intersections;
|
|
644
633
|
}
|
|
645
634
|
}
|
|
646
|
-
return new Set(
|
|
635
|
+
return result ?? /* @__PURE__ */ new Set([]);
|
|
647
636
|
}
|
|
648
637
|
where(condition) {
|
|
649
638
|
let result = null;
|
|
@@ -658,7 +647,13 @@ var BPTreeSync = class extends BPTree {
|
|
|
658
647
|
if (result === null) {
|
|
659
648
|
result = pairs;
|
|
660
649
|
} else {
|
|
661
|
-
|
|
650
|
+
const intersection = [];
|
|
651
|
+
for (const pair of pairs) {
|
|
652
|
+
if (result.find((p) => p.key === pair.key)) {
|
|
653
|
+
intersection.push(pair);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
result = intersection;
|
|
662
657
|
}
|
|
663
658
|
}
|
|
664
659
|
return result ?? [];
|
|
@@ -737,7 +732,6 @@ var BPTreeSync = class extends BPTree {
|
|
|
737
732
|
}
|
|
738
733
|
setHeadData(data) {
|
|
739
734
|
this.strategy.head.data = data;
|
|
740
|
-
this.bufferForHeadUpdate(this.headState);
|
|
741
735
|
this.commitHeadBuffer();
|
|
742
736
|
}
|
|
743
737
|
forceUpdate() {
|
|
@@ -866,7 +860,7 @@ var BPTreeAsync = class extends BPTree {
|
|
|
866
860
|
const keys = node.keys;
|
|
867
861
|
this.root = await this.getNode(keys[0]);
|
|
868
862
|
this.root.parent = 0;
|
|
869
|
-
this.
|
|
863
|
+
this.strategy.head.root = this.root.id;
|
|
870
864
|
this.bufferForNodeUpdate(this.root);
|
|
871
865
|
return;
|
|
872
866
|
} else if (this.root === node) {
|
|
@@ -1045,9 +1039,9 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1045
1039
|
if (this.root === node) {
|
|
1046
1040
|
const root = await this._createNode([node.id, pointer.id], [value]);
|
|
1047
1041
|
this.root = root;
|
|
1042
|
+
this.strategy.head.root = root.id;
|
|
1048
1043
|
node.parent = root.id;
|
|
1049
1044
|
pointer.parent = root.id;
|
|
1050
|
-
this.bufferForHeadUpdate(this.headState);
|
|
1051
1045
|
this.bufferForNodeCreate(root);
|
|
1052
1046
|
this.bufferForNodeUpdate(node);
|
|
1053
1047
|
this.bufferForNodeUpdate(pointer);
|
|
@@ -1095,12 +1089,13 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1095
1089
|
if (head === null) {
|
|
1096
1090
|
this.order = this.strategy.order;
|
|
1097
1091
|
this.root = await this._createNode([], [], true);
|
|
1098
|
-
this.
|
|
1092
|
+
this.strategy.head.root = this.root.id;
|
|
1099
1093
|
this.bufferForNodeCreate(this.root);
|
|
1100
1094
|
this.commitHeadBuffer();
|
|
1101
1095
|
this.commitNodeCreateBuffer();
|
|
1102
1096
|
} else {
|
|
1103
1097
|
const { root, order } = head;
|
|
1098
|
+
this.strategy.head = head;
|
|
1104
1099
|
this.order = order;
|
|
1105
1100
|
this.root = await this.getNode(root);
|
|
1106
1101
|
}
|
|
@@ -1143,10 +1138,7 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1143
1138
|
return node;
|
|
1144
1139
|
}
|
|
1145
1140
|
async commitHeadBuffer() {
|
|
1146
|
-
|
|
1147
|
-
await this.strategy.writeHead(this._headBuffer);
|
|
1148
|
-
}
|
|
1149
|
-
this.bufferForHeadUpdate(null);
|
|
1141
|
+
await this.strategy.writeHead(this.strategy.head);
|
|
1150
1142
|
}
|
|
1151
1143
|
async commitNodeCreateBuffer() {
|
|
1152
1144
|
for (const node of this._nodeCreateBuffer.values()) {
|
|
@@ -1171,12 +1163,18 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1171
1163
|
const comparator = this.verifierMap[key];
|
|
1172
1164
|
const pairs = await this.getPairs(value, startNode, fullScan, comparator, direction);
|
|
1173
1165
|
if (result === null) {
|
|
1174
|
-
result = pairs.map((pair) => pair.key);
|
|
1166
|
+
result = new Set(pairs.map((pair) => pair.key));
|
|
1175
1167
|
} else {
|
|
1176
|
-
|
|
1168
|
+
const intersections = /* @__PURE__ */ new Set();
|
|
1169
|
+
for (const pair of pairs) {
|
|
1170
|
+
if (result.has(pair.key)) {
|
|
1171
|
+
intersections.add(pair.key);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
result = intersections;
|
|
1177
1175
|
}
|
|
1178
1176
|
}
|
|
1179
|
-
return new Set(
|
|
1177
|
+
return result ?? /* @__PURE__ */ new Set([]);
|
|
1180
1178
|
}
|
|
1181
1179
|
async where(condition) {
|
|
1182
1180
|
let result = null;
|
|
@@ -1191,7 +1189,13 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1191
1189
|
if (result === null) {
|
|
1192
1190
|
result = pairs;
|
|
1193
1191
|
} else {
|
|
1194
|
-
|
|
1192
|
+
const intersection = [];
|
|
1193
|
+
for (const pair of pairs) {
|
|
1194
|
+
if (result.find((p) => p.key === pair.key)) {
|
|
1195
|
+
intersection.push(pair);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
result = intersection;
|
|
1195
1199
|
}
|
|
1196
1200
|
}
|
|
1197
1201
|
return result ?? [];
|
|
@@ -1270,7 +1274,6 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1270
1274
|
}
|
|
1271
1275
|
async setHeadData(data) {
|
|
1272
1276
|
this.strategy.head.data = data;
|
|
1273
|
-
this.bufferForHeadUpdate(this.headState);
|
|
1274
1277
|
await this.commitHeadBuffer();
|
|
1275
1278
|
}
|
|
1276
1279
|
async forceUpdate() {
|
package/dist/esm/index.js
CHANGED
|
@@ -47,7 +47,6 @@ var BPTree = class {
|
|
|
47
47
|
root;
|
|
48
48
|
_nodeCreateBuffer;
|
|
49
49
|
_nodeUpdateBuffer;
|
|
50
|
-
_headBuffer;
|
|
51
50
|
verifierMap = {
|
|
52
51
|
gt: (nv, v) => this.comparator.isHigher(nv, v),
|
|
53
52
|
gte: (nv, v) => this.comparator.isHigher(nv, v) || this.comparator.isSame(nv, v),
|
|
@@ -92,19 +91,8 @@ var BPTree = class {
|
|
|
92
91
|
notEqual: true,
|
|
93
92
|
like: true
|
|
94
93
|
};
|
|
95
|
-
get headState() {
|
|
96
|
-
const root = this.root.id;
|
|
97
|
-
const order = this.order;
|
|
98
|
-
const data = this.strategy.head.data;
|
|
99
|
-
return {
|
|
100
|
-
root,
|
|
101
|
-
order,
|
|
102
|
-
data
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
94
|
constructor(strategy, comparator) {
|
|
106
95
|
this._regexpCache = new CacheStorage();
|
|
107
|
-
this._headBuffer = null;
|
|
108
96
|
this._nodeCreateBuffer = /* @__PURE__ */ new Map();
|
|
109
97
|
this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
|
|
110
98
|
this.nodes = /* @__PURE__ */ new Map();
|
|
@@ -138,9 +126,6 @@ var BPTree = class {
|
|
|
138
126
|
this.bufferForNodeUpdate(node);
|
|
139
127
|
}
|
|
140
128
|
}
|
|
141
|
-
bufferForHeadUpdate(head) {
|
|
142
|
-
this._headBuffer = head;
|
|
143
|
-
}
|
|
144
129
|
bufferForNodeCreate(node) {
|
|
145
130
|
this._nodeCreateBuffer.set(node.id, node);
|
|
146
131
|
}
|
|
@@ -162,7 +147,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
162
147
|
constructor(strategy, comparator) {
|
|
163
148
|
super(strategy, comparator);
|
|
164
149
|
}
|
|
165
|
-
_getPairsRightToLeft(value, startNode,
|
|
150
|
+
_getPairsRightToLeft(value, startNode, fullScan, comparator) {
|
|
166
151
|
const pairs = [];
|
|
167
152
|
let node = startNode;
|
|
168
153
|
let done = false;
|
|
@@ -178,7 +163,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
178
163
|
while (j--) {
|
|
179
164
|
pairs.push({ key: keys[j], value: nValue });
|
|
180
165
|
}
|
|
181
|
-
} else if (found && !
|
|
166
|
+
} else if (found && !fullScan) {
|
|
182
167
|
done = true;
|
|
183
168
|
break;
|
|
184
169
|
}
|
|
@@ -191,7 +176,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
191
176
|
}
|
|
192
177
|
return pairs.reverse();
|
|
193
178
|
}
|
|
194
|
-
_getPairsLeftToRight(value, startNode,
|
|
179
|
+
_getPairsLeftToRight(value, startNode, fullScan, comparator) {
|
|
195
180
|
const pairs = [];
|
|
196
181
|
let node = startNode;
|
|
197
182
|
let done = false;
|
|
@@ -205,7 +190,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
205
190
|
for (const key of keys) {
|
|
206
191
|
pairs.push({ key, value: nValue });
|
|
207
192
|
}
|
|
208
|
-
} else if (found && !
|
|
193
|
+
} else if (found && !fullScan) {
|
|
209
194
|
done = true;
|
|
210
195
|
break;
|
|
211
196
|
}
|
|
@@ -218,12 +203,12 @@ var BPTreeSync = class extends BPTree {
|
|
|
218
203
|
}
|
|
219
204
|
return pairs;
|
|
220
205
|
}
|
|
221
|
-
getPairs(value, startNode,
|
|
206
|
+
getPairs(value, startNode, fullScan, comparator, direction) {
|
|
222
207
|
switch (direction) {
|
|
223
208
|
case -1:
|
|
224
|
-
return this._getPairsRightToLeft(value, startNode,
|
|
209
|
+
return this._getPairsRightToLeft(value, startNode, fullScan, comparator);
|
|
225
210
|
case 1:
|
|
226
|
-
return this._getPairsLeftToRight(value, startNode,
|
|
211
|
+
return this._getPairsLeftToRight(value, startNode, fullScan, comparator);
|
|
227
212
|
default:
|
|
228
213
|
throw new Error(`Direction must be -1 or 1. but got a ${direction}`);
|
|
229
214
|
}
|
|
@@ -272,7 +257,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
272
257
|
const keys = node.keys;
|
|
273
258
|
this.root = this.getNode(keys[0]);
|
|
274
259
|
this.root.parent = 0;
|
|
275
|
-
this.
|
|
260
|
+
this.strategy.head.root = this.root.id;
|
|
276
261
|
this.bufferForNodeUpdate(this.root);
|
|
277
262
|
return;
|
|
278
263
|
} else if (this.root === node) {
|
|
@@ -478,9 +463,9 @@ var BPTreeSync = class extends BPTree {
|
|
|
478
463
|
if (this.root === node) {
|
|
479
464
|
const root = this._createNode([node.id, pointer.id], [value]);
|
|
480
465
|
this.root = root;
|
|
466
|
+
this.strategy.head.root = root.id;
|
|
481
467
|
node.parent = root.id;
|
|
482
468
|
pointer.parent = root.id;
|
|
483
|
-
this.bufferForHeadUpdate(this.headState);
|
|
484
469
|
this.bufferForNodeCreate(root);
|
|
485
470
|
this.bufferForNodeUpdate(node);
|
|
486
471
|
this.bufferForNodeUpdate(pointer);
|
|
@@ -528,12 +513,13 @@ var BPTreeSync = class extends BPTree {
|
|
|
528
513
|
if (head === null) {
|
|
529
514
|
this.order = this.strategy.order;
|
|
530
515
|
this.root = this._createNode([], [], true);
|
|
531
|
-
this.
|
|
516
|
+
this.strategy.head.root = this.root.id;
|
|
532
517
|
this.bufferForNodeCreate(this.root);
|
|
533
518
|
this.commitHeadBuffer();
|
|
534
519
|
this.commitNodeCreateBuffer();
|
|
535
520
|
} else {
|
|
536
521
|
const { root, order } = head;
|
|
522
|
+
this.strategy.head = head;
|
|
537
523
|
this.order = order;
|
|
538
524
|
this.root = this.getNode(root);
|
|
539
525
|
}
|
|
@@ -576,10 +562,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
576
562
|
return node;
|
|
577
563
|
}
|
|
578
564
|
commitHeadBuffer() {
|
|
579
|
-
|
|
580
|
-
this.strategy.writeHead(this._headBuffer);
|
|
581
|
-
}
|
|
582
|
-
this.bufferForHeadUpdate(null);
|
|
565
|
+
this.strategy.writeHead(this.strategy.head);
|
|
583
566
|
}
|
|
584
567
|
commitNodeCreateBuffer() {
|
|
585
568
|
for (const node of this._nodeCreateBuffer.values()) {
|
|
@@ -604,12 +587,18 @@ var BPTreeSync = class extends BPTree {
|
|
|
604
587
|
const comparator = this.verifierMap[key];
|
|
605
588
|
const pairs = this.getPairs(value, startNode, fullScan, comparator, direction);
|
|
606
589
|
if (result === null) {
|
|
607
|
-
result = pairs.map((pair) => pair.key);
|
|
590
|
+
result = new Set(pairs.map((pair) => pair.key));
|
|
608
591
|
} else {
|
|
609
|
-
|
|
592
|
+
const intersections = /* @__PURE__ */ new Set();
|
|
593
|
+
for (const pair of pairs) {
|
|
594
|
+
if (result.has(pair.key)) {
|
|
595
|
+
intersections.add(pair.key);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
result = intersections;
|
|
610
599
|
}
|
|
611
600
|
}
|
|
612
|
-
return new Set(
|
|
601
|
+
return result ?? /* @__PURE__ */ new Set([]);
|
|
613
602
|
}
|
|
614
603
|
where(condition) {
|
|
615
604
|
let result = null;
|
|
@@ -624,7 +613,13 @@ var BPTreeSync = class extends BPTree {
|
|
|
624
613
|
if (result === null) {
|
|
625
614
|
result = pairs;
|
|
626
615
|
} else {
|
|
627
|
-
|
|
616
|
+
const intersection = [];
|
|
617
|
+
for (const pair of pairs) {
|
|
618
|
+
if (result.find((p) => p.key === pair.key)) {
|
|
619
|
+
intersection.push(pair);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
result = intersection;
|
|
628
623
|
}
|
|
629
624
|
}
|
|
630
625
|
return result ?? [];
|
|
@@ -703,7 +698,6 @@ var BPTreeSync = class extends BPTree {
|
|
|
703
698
|
}
|
|
704
699
|
setHeadData(data) {
|
|
705
700
|
this.strategy.head.data = data;
|
|
706
|
-
this.bufferForHeadUpdate(this.headState);
|
|
707
701
|
this.commitHeadBuffer();
|
|
708
702
|
}
|
|
709
703
|
forceUpdate() {
|
|
@@ -832,7 +826,7 @@ var BPTreeAsync = class extends BPTree {
|
|
|
832
826
|
const keys = node.keys;
|
|
833
827
|
this.root = await this.getNode(keys[0]);
|
|
834
828
|
this.root.parent = 0;
|
|
835
|
-
this.
|
|
829
|
+
this.strategy.head.root = this.root.id;
|
|
836
830
|
this.bufferForNodeUpdate(this.root);
|
|
837
831
|
return;
|
|
838
832
|
} else if (this.root === node) {
|
|
@@ -1011,9 +1005,9 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1011
1005
|
if (this.root === node) {
|
|
1012
1006
|
const root = await this._createNode([node.id, pointer.id], [value]);
|
|
1013
1007
|
this.root = root;
|
|
1008
|
+
this.strategy.head.root = root.id;
|
|
1014
1009
|
node.parent = root.id;
|
|
1015
1010
|
pointer.parent = root.id;
|
|
1016
|
-
this.bufferForHeadUpdate(this.headState);
|
|
1017
1011
|
this.bufferForNodeCreate(root);
|
|
1018
1012
|
this.bufferForNodeUpdate(node);
|
|
1019
1013
|
this.bufferForNodeUpdate(pointer);
|
|
@@ -1061,12 +1055,13 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1061
1055
|
if (head === null) {
|
|
1062
1056
|
this.order = this.strategy.order;
|
|
1063
1057
|
this.root = await this._createNode([], [], true);
|
|
1064
|
-
this.
|
|
1058
|
+
this.strategy.head.root = this.root.id;
|
|
1065
1059
|
this.bufferForNodeCreate(this.root);
|
|
1066
1060
|
this.commitHeadBuffer();
|
|
1067
1061
|
this.commitNodeCreateBuffer();
|
|
1068
1062
|
} else {
|
|
1069
1063
|
const { root, order } = head;
|
|
1064
|
+
this.strategy.head = head;
|
|
1070
1065
|
this.order = order;
|
|
1071
1066
|
this.root = await this.getNode(root);
|
|
1072
1067
|
}
|
|
@@ -1109,10 +1104,7 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1109
1104
|
return node;
|
|
1110
1105
|
}
|
|
1111
1106
|
async commitHeadBuffer() {
|
|
1112
|
-
|
|
1113
|
-
await this.strategy.writeHead(this._headBuffer);
|
|
1114
|
-
}
|
|
1115
|
-
this.bufferForHeadUpdate(null);
|
|
1107
|
+
await this.strategy.writeHead(this.strategy.head);
|
|
1116
1108
|
}
|
|
1117
1109
|
async commitNodeCreateBuffer() {
|
|
1118
1110
|
for (const node of this._nodeCreateBuffer.values()) {
|
|
@@ -1137,12 +1129,18 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1137
1129
|
const comparator = this.verifierMap[key];
|
|
1138
1130
|
const pairs = await this.getPairs(value, startNode, fullScan, comparator, direction);
|
|
1139
1131
|
if (result === null) {
|
|
1140
|
-
result = pairs.map((pair) => pair.key);
|
|
1132
|
+
result = new Set(pairs.map((pair) => pair.key));
|
|
1141
1133
|
} else {
|
|
1142
|
-
|
|
1134
|
+
const intersections = /* @__PURE__ */ new Set();
|
|
1135
|
+
for (const pair of pairs) {
|
|
1136
|
+
if (result.has(pair.key)) {
|
|
1137
|
+
intersections.add(pair.key);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
result = intersections;
|
|
1143
1141
|
}
|
|
1144
1142
|
}
|
|
1145
|
-
return new Set(
|
|
1143
|
+
return result ?? /* @__PURE__ */ new Set([]);
|
|
1146
1144
|
}
|
|
1147
1145
|
async where(condition) {
|
|
1148
1146
|
let result = null;
|
|
@@ -1157,7 +1155,13 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1157
1155
|
if (result === null) {
|
|
1158
1156
|
result = pairs;
|
|
1159
1157
|
} else {
|
|
1160
|
-
|
|
1158
|
+
const intersection = [];
|
|
1159
|
+
for (const pair of pairs) {
|
|
1160
|
+
if (result.find((p) => p.key === pair.key)) {
|
|
1161
|
+
intersection.push(pair);
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
result = intersection;
|
|
1161
1165
|
}
|
|
1162
1166
|
}
|
|
1163
1167
|
return result ?? [];
|
|
@@ -1236,7 +1240,6 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1236
1240
|
}
|
|
1237
1241
|
async setHeadData(data) {
|
|
1238
1242
|
this.strategy.head.data = data;
|
|
1239
|
-
this.bufferForHeadUpdate(this.headState);
|
|
1240
1243
|
await this.commitHeadBuffer();
|
|
1241
1244
|
}
|
|
1242
1245
|
async forceUpdate() {
|
|
@@ -5,9 +5,9 @@ import { SerializableData } from './base/SerializeStrategy';
|
|
|
5
5
|
export declare class BPTreeSync<K, V> extends BPTree<K, V> {
|
|
6
6
|
protected readonly strategy: SerializeStrategySync<K, V>;
|
|
7
7
|
constructor(strategy: SerializeStrategySync<K, V>, comparator: ValueComparator<V>);
|
|
8
|
-
protected _getPairsRightToLeft(value: V, startNode: BPTreeLeafNode<K, V>,
|
|
9
|
-
protected _getPairsLeftToRight(value: V, startNode: BPTreeLeafNode<K, V>,
|
|
10
|
-
protected getPairs(value: V, startNode: BPTreeLeafNode<K, V>,
|
|
8
|
+
protected _getPairsRightToLeft(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean): BPTreePair<K, V>[];
|
|
9
|
+
protected _getPairsLeftToRight(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean): BPTreePair<K, V>[];
|
|
10
|
+
protected getPairs(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean, direction: 1 | -1): BPTreePair<K, V>[];
|
|
11
11
|
protected _createNodeId(): number;
|
|
12
12
|
protected _createNode(keys: number[] | K[][], values: V[], leaf?: boolean, parent?: number, next?: number, prev?: number): BPTreeUnknownNode<K, V>;
|
|
13
13
|
protected _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>, value: V): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValueComparator } from './ValueComparator';
|
|
2
|
-
import { SerializableData, SerializeStrategy
|
|
2
|
+
import { SerializableData, SerializeStrategy } from './SerializeStrategy';
|
|
3
3
|
type Sync<T> = T;
|
|
4
4
|
type Async<T> = Promise<T>;
|
|
5
5
|
type Deferred<T> = Sync<T> | Async<T>;
|
|
@@ -51,12 +51,10 @@ 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 _headBuffer: SerializeStrategyHead | null;
|
|
55
54
|
protected readonly verifierMap: Record<keyof BPTreeCondition<V>, (nodeValue: V, value: V) => boolean>;
|
|
56
55
|
protected readonly verifierStartNode: Record<keyof BPTreeCondition<V>, (value: V) => Deferred<BPTreeLeafNode<K, V>>>;
|
|
57
56
|
protected readonly verifierDirection: Record<keyof BPTreeCondition<V>, -1 | 1>;
|
|
58
57
|
protected readonly verifierFullScan: Record<keyof BPTreeCondition<V>, boolean>;
|
|
59
|
-
protected get headState(): SerializeStrategyHead;
|
|
60
58
|
protected constructor(strategy: SerializeStrategy<K, V>, comparator: ValueComparator<V>);
|
|
61
59
|
protected abstract _getPairsRightToLeft(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean): Deferred<BPTreePair<K, V>[]>;
|
|
62
60
|
protected abstract _getPairsLeftToRight(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean): Deferred<BPTreePair<K, V>[]>;
|
|
@@ -123,7 +121,6 @@ export declare abstract class BPTree<K, V> {
|
|
|
123
121
|
*/
|
|
124
122
|
abstract forceUpdate(nodeId: number): Deferred<number>;
|
|
125
123
|
protected _insertAtLeaf(node: BPTreeLeafNode<K, V>, key: K, value: V): void;
|
|
126
|
-
protected bufferForHeadUpdate(head: SerializeStrategyHead | null): Deferred<void>;
|
|
127
124
|
protected bufferForNodeCreate(node: BPTreeUnknownNode<K, V>): Deferred<void>;
|
|
128
125
|
protected bufferForNodeUpdate(node: BPTreeUnknownNode<K, V>): Deferred<void>;
|
|
129
126
|
/**
|
package/dist/typings/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type { BPTreeNode } from './base/BPTree';
|
|
2
|
-
export type { SerializeStrategyHead } from './base/SerializeStrategy';
|
|
1
|
+
export type { BPTreeNode, BPTreeCondition } from './base/BPTree';
|
|
2
|
+
export type { SerializeStrategyHead, SerializableData } from './base/SerializeStrategy';
|
|
3
3
|
export { ValueComparator, NumericComparator, StringComparator } from './base/ValueComparator';
|
|
4
4
|
export { BPTreeSync } from './BPTreeSync';
|
|
5
5
|
export { BPTreeAsync } from './BPTreeAsync';
|