serializable-bptree 3.2.1 → 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 +39 -15
- package/dist/esm/index.js +39 -15
- package/dist/typings/BPTreeSync.d.ts +3 -3
- package/dist/typings/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -181,7 +181,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
181
181
|
constructor(strategy, comparator) {
|
|
182
182
|
super(strategy, comparator);
|
|
183
183
|
}
|
|
184
|
-
_getPairsRightToLeft(value, startNode,
|
|
184
|
+
_getPairsRightToLeft(value, startNode, fullScan, comparator) {
|
|
185
185
|
const pairs = [];
|
|
186
186
|
let node = startNode;
|
|
187
187
|
let done = false;
|
|
@@ -197,7 +197,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
197
197
|
while (j--) {
|
|
198
198
|
pairs.push({ key: keys[j], value: nValue });
|
|
199
199
|
}
|
|
200
|
-
} else if (found && !
|
|
200
|
+
} else if (found && !fullScan) {
|
|
201
201
|
done = true;
|
|
202
202
|
break;
|
|
203
203
|
}
|
|
@@ -210,7 +210,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
210
210
|
}
|
|
211
211
|
return pairs.reverse();
|
|
212
212
|
}
|
|
213
|
-
_getPairsLeftToRight(value, startNode,
|
|
213
|
+
_getPairsLeftToRight(value, startNode, fullScan, comparator) {
|
|
214
214
|
const pairs = [];
|
|
215
215
|
let node = startNode;
|
|
216
216
|
let done = false;
|
|
@@ -224,7 +224,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
224
224
|
for (const key of keys) {
|
|
225
225
|
pairs.push({ key, value: nValue });
|
|
226
226
|
}
|
|
227
|
-
} else if (found && !
|
|
227
|
+
} else if (found && !fullScan) {
|
|
228
228
|
done = true;
|
|
229
229
|
break;
|
|
230
230
|
}
|
|
@@ -237,12 +237,12 @@ var BPTreeSync = class extends BPTree {
|
|
|
237
237
|
}
|
|
238
238
|
return pairs;
|
|
239
239
|
}
|
|
240
|
-
getPairs(value, startNode,
|
|
240
|
+
getPairs(value, startNode, fullScan, comparator, direction) {
|
|
241
241
|
switch (direction) {
|
|
242
242
|
case -1:
|
|
243
|
-
return this._getPairsRightToLeft(value, startNode,
|
|
243
|
+
return this._getPairsRightToLeft(value, startNode, fullScan, comparator);
|
|
244
244
|
case 1:
|
|
245
|
-
return this._getPairsLeftToRight(value, startNode,
|
|
245
|
+
return this._getPairsLeftToRight(value, startNode, fullScan, comparator);
|
|
246
246
|
default:
|
|
247
247
|
throw new Error(`Direction must be -1 or 1. but got a ${direction}`);
|
|
248
248
|
}
|
|
@@ -621,12 +621,18 @@ var BPTreeSync = class extends BPTree {
|
|
|
621
621
|
const comparator = this.verifierMap[key];
|
|
622
622
|
const pairs = this.getPairs(value, startNode, fullScan, comparator, direction);
|
|
623
623
|
if (result === null) {
|
|
624
|
-
result = pairs.map((pair) => pair.key);
|
|
624
|
+
result = new Set(pairs.map((pair) => pair.key));
|
|
625
625
|
} else {
|
|
626
|
-
|
|
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;
|
|
627
633
|
}
|
|
628
634
|
}
|
|
629
|
-
return new Set(
|
|
635
|
+
return result ?? /* @__PURE__ */ new Set([]);
|
|
630
636
|
}
|
|
631
637
|
where(condition) {
|
|
632
638
|
let result = null;
|
|
@@ -641,7 +647,13 @@ var BPTreeSync = class extends BPTree {
|
|
|
641
647
|
if (result === null) {
|
|
642
648
|
result = pairs;
|
|
643
649
|
} else {
|
|
644
|
-
|
|
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;
|
|
645
657
|
}
|
|
646
658
|
}
|
|
647
659
|
return result ?? [];
|
|
@@ -1151,12 +1163,18 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1151
1163
|
const comparator = this.verifierMap[key];
|
|
1152
1164
|
const pairs = await this.getPairs(value, startNode, fullScan, comparator, direction);
|
|
1153
1165
|
if (result === null) {
|
|
1154
|
-
result = pairs.map((pair) => pair.key);
|
|
1166
|
+
result = new Set(pairs.map((pair) => pair.key));
|
|
1155
1167
|
} else {
|
|
1156
|
-
|
|
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;
|
|
1157
1175
|
}
|
|
1158
1176
|
}
|
|
1159
|
-
return new Set(
|
|
1177
|
+
return result ?? /* @__PURE__ */ new Set([]);
|
|
1160
1178
|
}
|
|
1161
1179
|
async where(condition) {
|
|
1162
1180
|
let result = null;
|
|
@@ -1171,7 +1189,13 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1171
1189
|
if (result === null) {
|
|
1172
1190
|
result = pairs;
|
|
1173
1191
|
} else {
|
|
1174
|
-
|
|
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;
|
|
1175
1199
|
}
|
|
1176
1200
|
}
|
|
1177
1201
|
return result ?? [];
|
package/dist/esm/index.js
CHANGED
|
@@ -147,7 +147,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
147
147
|
constructor(strategy, comparator) {
|
|
148
148
|
super(strategy, comparator);
|
|
149
149
|
}
|
|
150
|
-
_getPairsRightToLeft(value, startNode,
|
|
150
|
+
_getPairsRightToLeft(value, startNode, fullScan, comparator) {
|
|
151
151
|
const pairs = [];
|
|
152
152
|
let node = startNode;
|
|
153
153
|
let done = false;
|
|
@@ -163,7 +163,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
163
163
|
while (j--) {
|
|
164
164
|
pairs.push({ key: keys[j], value: nValue });
|
|
165
165
|
}
|
|
166
|
-
} else if (found && !
|
|
166
|
+
} else if (found && !fullScan) {
|
|
167
167
|
done = true;
|
|
168
168
|
break;
|
|
169
169
|
}
|
|
@@ -176,7 +176,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
176
176
|
}
|
|
177
177
|
return pairs.reverse();
|
|
178
178
|
}
|
|
179
|
-
_getPairsLeftToRight(value, startNode,
|
|
179
|
+
_getPairsLeftToRight(value, startNode, fullScan, comparator) {
|
|
180
180
|
const pairs = [];
|
|
181
181
|
let node = startNode;
|
|
182
182
|
let done = false;
|
|
@@ -190,7 +190,7 @@ var BPTreeSync = class extends BPTree {
|
|
|
190
190
|
for (const key of keys) {
|
|
191
191
|
pairs.push({ key, value: nValue });
|
|
192
192
|
}
|
|
193
|
-
} else if (found && !
|
|
193
|
+
} else if (found && !fullScan) {
|
|
194
194
|
done = true;
|
|
195
195
|
break;
|
|
196
196
|
}
|
|
@@ -203,12 +203,12 @@ var BPTreeSync = class extends BPTree {
|
|
|
203
203
|
}
|
|
204
204
|
return pairs;
|
|
205
205
|
}
|
|
206
|
-
getPairs(value, startNode,
|
|
206
|
+
getPairs(value, startNode, fullScan, comparator, direction) {
|
|
207
207
|
switch (direction) {
|
|
208
208
|
case -1:
|
|
209
|
-
return this._getPairsRightToLeft(value, startNode,
|
|
209
|
+
return this._getPairsRightToLeft(value, startNode, fullScan, comparator);
|
|
210
210
|
case 1:
|
|
211
|
-
return this._getPairsLeftToRight(value, startNode,
|
|
211
|
+
return this._getPairsLeftToRight(value, startNode, fullScan, comparator);
|
|
212
212
|
default:
|
|
213
213
|
throw new Error(`Direction must be -1 or 1. but got a ${direction}`);
|
|
214
214
|
}
|
|
@@ -587,12 +587,18 @@ var BPTreeSync = class extends BPTree {
|
|
|
587
587
|
const comparator = this.verifierMap[key];
|
|
588
588
|
const pairs = this.getPairs(value, startNode, fullScan, comparator, direction);
|
|
589
589
|
if (result === null) {
|
|
590
|
-
result = pairs.map((pair) => pair.key);
|
|
590
|
+
result = new Set(pairs.map((pair) => pair.key));
|
|
591
591
|
} else {
|
|
592
|
-
|
|
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;
|
|
593
599
|
}
|
|
594
600
|
}
|
|
595
|
-
return new Set(
|
|
601
|
+
return result ?? /* @__PURE__ */ new Set([]);
|
|
596
602
|
}
|
|
597
603
|
where(condition) {
|
|
598
604
|
let result = null;
|
|
@@ -607,7 +613,13 @@ var BPTreeSync = class extends BPTree {
|
|
|
607
613
|
if (result === null) {
|
|
608
614
|
result = pairs;
|
|
609
615
|
} else {
|
|
610
|
-
|
|
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;
|
|
611
623
|
}
|
|
612
624
|
}
|
|
613
625
|
return result ?? [];
|
|
@@ -1117,12 +1129,18 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1117
1129
|
const comparator = this.verifierMap[key];
|
|
1118
1130
|
const pairs = await this.getPairs(value, startNode, fullScan, comparator, direction);
|
|
1119
1131
|
if (result === null) {
|
|
1120
|
-
result = pairs.map((pair) => pair.key);
|
|
1132
|
+
result = new Set(pairs.map((pair) => pair.key));
|
|
1121
1133
|
} else {
|
|
1122
|
-
|
|
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;
|
|
1123
1141
|
}
|
|
1124
1142
|
}
|
|
1125
|
-
return new Set(
|
|
1143
|
+
return result ?? /* @__PURE__ */ new Set([]);
|
|
1126
1144
|
}
|
|
1127
1145
|
async where(condition) {
|
|
1128
1146
|
let result = null;
|
|
@@ -1137,7 +1155,13 @@ var BPTreeAsync = class extends BPTree {
|
|
|
1137
1155
|
if (result === null) {
|
|
1138
1156
|
result = pairs;
|
|
1139
1157
|
} else {
|
|
1140
|
-
|
|
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;
|
|
1141
1165
|
}
|
|
1142
1166
|
}
|
|
1143
1167
|
return result ?? [];
|
|
@@ -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;
|
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';
|