serializable-bptree 4.0.5 → 5.0.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/README.md CHANGED
@@ -59,10 +59,10 @@ tree.insert('c', 3)
59
59
 
60
60
  tree.delete('b', 2)
61
61
 
62
- tree.where({ equal: 1 }) // [{ key: 'a', value: 1 }]
63
- tree.where({ gt: 1 }) // [{ key: 'c', value: 3 }]
64
- tree.where({ lt: 2 }) // [{ key: 'a', value: 1 }]
65
- tree.where({ gt: 0, lt: 4 }) // [{ key: 'a', value: 1 }, { key: 'c', value: 3 }]
62
+ tree.where({ equal: 1 }) // Map([{ key: 'a', value: 1 }])
63
+ tree.where({ gt: 1 }) // Map([{ key: 'c', value: 3 }])
64
+ tree.where({ lt: 2 }) // Map([{ key: 'a', value: 1 }])
65
+ tree.where({ gt: 0, lt: 4 }) // Map([{ key: 'a', value: 1 }, { key: 'c', value: 3 }])
66
66
  ```
67
67
 
68
68
  ## Why use a `serializable-bptree`?
@@ -102,7 +102,7 @@ import {
102
102
  ValueComparator,
103
103
  NumericComparator,
104
104
  StringComparator
105
- } from 'https://cdn.jsdelivr.net/npm/serializable-bptree@4.x.x/dist/esm/index.min.js'
105
+ } from 'https://cdn.jsdelivr.net/npm/serializable-bptree@5.x.x/dist/esm/index.min.js'
106
106
  </script>
107
107
  ```
108
108
 
@@ -417,10 +417,10 @@ await tree.insert('c', 3)
417
417
 
418
418
  await tree.delete('b', 2)
419
419
 
420
- await tree.where({ equal: 1 }) // [{ key: 'a', value: 1 }]
421
- await tree.where({ gt: 1 }) // [{ key: 'c', value: 3 }]
422
- await tree.where({ lt: 2 }) // [{ key: 'a', value: 1 }]
423
- await tree.where({ gt: 0, lt: 4 }) // [{ key: 'a', value: 1 }, { key: 'c', value: 3 }]
420
+ await tree.where({ equal: 1 }) // Map([{ key: 'a', value: 1 }])
421
+ await tree.where({ gt: 1 }) // Map([{ key: 'c', value: 3 }])
422
+ await tree.where({ lt: 2 }) // Map([{ key: 'a', value: 1 }])
423
+ await tree.where({ gt: 0, lt: 4 }) // Map([{ key: 'a', value: 1 }, { key: 'c', value: 3 }])
424
424
  ```
425
425
 
426
426
  The implementation method for asynchronous operations is not significantly different. The **-Async** suffix is used instead of the **-Sync** suffix in the **BPTree** and **SerializeStrategy** classes. The only difference is that the methods become asynchronous. The **ValueComparator** class and similar value comparators do not use asynchronous operations.
@@ -211,7 +211,7 @@ var BPTreeSync = class extends BPTree {
211
211
  constructor(strategy, comparator) {
212
212
  super(strategy, comparator);
213
213
  }
214
- _getPairsRightToLeft(value, startNode, fullScan, comparator) {
214
+ getPairsRightToLeft(value, startNode, fullScan, comparator) {
215
215
  const pairs = [];
216
216
  let node = startNode;
217
217
  let done = false;
@@ -225,7 +225,7 @@ var BPTreeSync = class extends BPTree {
225
225
  found = true;
226
226
  let j = keys.length;
227
227
  while (j--) {
228
- pairs.push({ key: keys[j], value: nValue });
228
+ pairs.push([keys[j], nValue]);
229
229
  }
230
230
  } else if (found && !fullScan) {
231
231
  done = true;
@@ -238,9 +238,9 @@ var BPTreeSync = class extends BPTree {
238
238
  }
239
239
  node = this.getNode(node.prev);
240
240
  }
241
- return pairs.reverse();
241
+ return new Map(pairs.reverse());
242
242
  }
243
- _getPairsLeftToRight(value, startNode, fullScan, comparator) {
243
+ getPairsLeftToRight(value, startNode, fullScan, comparator) {
244
244
  const pairs = [];
245
245
  let node = startNode;
246
246
  let done = false;
@@ -251,8 +251,9 @@ var BPTreeSync = class extends BPTree {
251
251
  const keys = node.keys[i];
252
252
  if (comparator(nValue, value)) {
253
253
  found = true;
254
- for (const key of keys) {
255
- pairs.push({ key, value: nValue });
254
+ for (let j = 0, len2 = keys.length; j < len2; j++) {
255
+ const key = keys[j];
256
+ pairs.push([key, nValue]);
256
257
  }
257
258
  } else if (found && !fullScan) {
258
259
  done = true;
@@ -265,14 +266,14 @@ var BPTreeSync = class extends BPTree {
265
266
  }
266
267
  node = this.getNode(node.next);
267
268
  }
268
- return pairs;
269
+ return new Map(pairs);
269
270
  }
270
271
  getPairs(value, startNode, fullScan, comparator, direction) {
271
272
  switch (direction) {
272
273
  case -1:
273
- return this._getPairsRightToLeft(value, startNode, fullScan, comparator);
274
+ return this.getPairsRightToLeft(value, startNode, fullScan, comparator);
274
275
  case 1:
275
- return this._getPairsLeftToRight(value, startNode, fullScan, comparator);
276
+ return this.getPairsLeftToRight(value, startNode, fullScan, comparator);
276
277
  default:
277
278
  throw new Error(`Direction must be -1 or 1. but got a ${direction}`);
278
279
  }
@@ -634,11 +635,11 @@ var BPTreeSync = class extends BPTree {
634
635
  const comparator = this.verifierMap[key];
635
636
  const pairs = this.getPairs(value, startNode, fullScan, comparator, direction);
636
637
  if (!filterValues) {
637
- filterValues = new Set(pairs.map((pair) => pair.key));
638
+ filterValues = new Set(pairs.keys());
638
639
  } else {
639
640
  const intersections = /* @__PURE__ */ new Set();
640
641
  for (const key2 of filterValues) {
641
- const has = pairs.some((pair) => pair.key === key2);
642
+ const has = pairs.has(key2);
642
643
  if (has) {
643
644
  intersections.add(key2);
644
645
  }
@@ -661,16 +662,16 @@ var BPTreeSync = class extends BPTree {
661
662
  if (result === null) {
662
663
  result = pairs;
663
664
  } else {
664
- const intersection = [];
665
- for (const pair of pairs) {
666
- if (result.find((p) => p.key === pair.key)) {
667
- intersection.push(pair);
665
+ const intersection = /* @__PURE__ */ new Map();
666
+ for (const [k2, v] of pairs) {
667
+ if (result.has(k2)) {
668
+ intersection.set(k2, v);
668
669
  }
669
670
  }
670
671
  result = intersection;
671
672
  }
672
673
  }
673
- return result ?? [];
674
+ return result ?? /* @__PURE__ */ new Map();
674
675
  }
675
676
  insert(key, value) {
676
677
  const before = this.insertableNode(value);
@@ -766,7 +767,7 @@ var BPTreeAsync = class extends BPTree {
766
767
  constructor(strategy, comparator) {
767
768
  super(strategy, comparator);
768
769
  }
769
- async _getPairsRightToLeft(value, startNode, fullScan, comparator) {
770
+ async getPairsRightToLeft(value, startNode, fullScan, comparator) {
770
771
  const pairs = [];
771
772
  let node = startNode;
772
773
  let done = false;
@@ -780,7 +781,7 @@ var BPTreeAsync = class extends BPTree {
780
781
  found = true;
781
782
  let j = keys.length;
782
783
  while (j--) {
783
- pairs.push({ key: keys[j], value: nValue });
784
+ pairs.push([keys[j], nValue]);
784
785
  }
785
786
  } else if (found && !fullScan) {
786
787
  done = true;
@@ -793,9 +794,9 @@ var BPTreeAsync = class extends BPTree {
793
794
  }
794
795
  node = await this.getNode(node.prev);
795
796
  }
796
- return pairs.reverse();
797
+ return new Map(pairs.reverse());
797
798
  }
798
- async _getPairsLeftToRight(value, startNode, fullScan, comparator) {
799
+ async getPairsLeftToRight(value, startNode, fullScan, comparator) {
799
800
  const pairs = [];
800
801
  let node = startNode;
801
802
  let done = false;
@@ -806,8 +807,9 @@ var BPTreeAsync = class extends BPTree {
806
807
  const keys = node.keys[i];
807
808
  if (comparator(nValue, value)) {
808
809
  found = true;
809
- for (const key of keys) {
810
- pairs.push({ key, value: nValue });
810
+ for (let j = 0, len2 = keys.length; j < len2; j++) {
811
+ const key = keys[j];
812
+ pairs.push([key, nValue]);
811
813
  }
812
814
  } else if (found && !fullScan) {
813
815
  done = true;
@@ -820,14 +822,14 @@ var BPTreeAsync = class extends BPTree {
820
822
  }
821
823
  node = await this.getNode(node.next);
822
824
  }
823
- return pairs;
825
+ return new Map(pairs);
824
826
  }
825
827
  async getPairs(value, startNode, fullScan, comparator, direction) {
826
828
  switch (direction) {
827
829
  case -1:
828
- return await this._getPairsRightToLeft(value, startNode, fullScan, comparator);
830
+ return await this.getPairsRightToLeft(value, startNode, fullScan, comparator);
829
831
  case 1:
830
- return await this._getPairsLeftToRight(value, startNode, fullScan, comparator);
832
+ return await this.getPairsLeftToRight(value, startNode, fullScan, comparator);
831
833
  default:
832
834
  throw new Error(`Direction must be -1 or 1. but got a ${direction}`);
833
835
  }
@@ -1189,11 +1191,11 @@ var BPTreeAsync = class extends BPTree {
1189
1191
  const comparator = this.verifierMap[key];
1190
1192
  const pairs = await this.getPairs(value, startNode, fullScan, comparator, direction);
1191
1193
  if (!filterValues) {
1192
- filterValues = new Set(pairs.map((pair) => pair.key));
1194
+ filterValues = new Set(pairs.keys());
1193
1195
  } else {
1194
1196
  const intersections = /* @__PURE__ */ new Set();
1195
1197
  for (const key2 of filterValues) {
1196
- const has = pairs.some((pair) => pair.key === key2);
1198
+ const has = pairs.has(key2);
1197
1199
  if (has) {
1198
1200
  intersections.add(key2);
1199
1201
  }
@@ -1216,16 +1218,16 @@ var BPTreeAsync = class extends BPTree {
1216
1218
  if (result === null) {
1217
1219
  result = pairs;
1218
1220
  } else {
1219
- const intersection = [];
1220
- for (const pair of pairs) {
1221
- if (result.find((p) => p.key === pair.key)) {
1222
- intersection.push(pair);
1221
+ const intersection = /* @__PURE__ */ new Map();
1222
+ for (const [k2, v] of pairs) {
1223
+ if (result.has(k2)) {
1224
+ intersection.set(k2, v);
1223
1225
  }
1224
1226
  }
1225
1227
  result = intersection;
1226
1228
  }
1227
1229
  }
1228
- return result ?? [];
1230
+ return result ?? /* @__PURE__ */ new Map();
1229
1231
  }
1230
1232
  async insert(key, value) {
1231
1233
  const before = await this.insertableNode(value);
@@ -177,7 +177,7 @@ var BPTreeSync = class extends BPTree {
177
177
  constructor(strategy, comparator) {
178
178
  super(strategy, comparator);
179
179
  }
180
- _getPairsRightToLeft(value, startNode, fullScan, comparator) {
180
+ getPairsRightToLeft(value, startNode, fullScan, comparator) {
181
181
  const pairs = [];
182
182
  let node = startNode;
183
183
  let done = false;
@@ -191,7 +191,7 @@ var BPTreeSync = class extends BPTree {
191
191
  found = true;
192
192
  let j = keys.length;
193
193
  while (j--) {
194
- pairs.push({ key: keys[j], value: nValue });
194
+ pairs.push([keys[j], nValue]);
195
195
  }
196
196
  } else if (found && !fullScan) {
197
197
  done = true;
@@ -204,9 +204,9 @@ var BPTreeSync = class extends BPTree {
204
204
  }
205
205
  node = this.getNode(node.prev);
206
206
  }
207
- return pairs.reverse();
207
+ return new Map(pairs.reverse());
208
208
  }
209
- _getPairsLeftToRight(value, startNode, fullScan, comparator) {
209
+ getPairsLeftToRight(value, startNode, fullScan, comparator) {
210
210
  const pairs = [];
211
211
  let node = startNode;
212
212
  let done = false;
@@ -217,8 +217,9 @@ var BPTreeSync = class extends BPTree {
217
217
  const keys = node.keys[i];
218
218
  if (comparator(nValue, value)) {
219
219
  found = true;
220
- for (const key of keys) {
221
- pairs.push({ key, value: nValue });
220
+ for (let j = 0, len2 = keys.length; j < len2; j++) {
221
+ const key = keys[j];
222
+ pairs.push([key, nValue]);
222
223
  }
223
224
  } else if (found && !fullScan) {
224
225
  done = true;
@@ -231,14 +232,14 @@ var BPTreeSync = class extends BPTree {
231
232
  }
232
233
  node = this.getNode(node.next);
233
234
  }
234
- return pairs;
235
+ return new Map(pairs);
235
236
  }
236
237
  getPairs(value, startNode, fullScan, comparator, direction) {
237
238
  switch (direction) {
238
239
  case -1:
239
- return this._getPairsRightToLeft(value, startNode, fullScan, comparator);
240
+ return this.getPairsRightToLeft(value, startNode, fullScan, comparator);
240
241
  case 1:
241
- return this._getPairsLeftToRight(value, startNode, fullScan, comparator);
242
+ return this.getPairsLeftToRight(value, startNode, fullScan, comparator);
242
243
  default:
243
244
  throw new Error(`Direction must be -1 or 1. but got a ${direction}`);
244
245
  }
@@ -600,11 +601,11 @@ var BPTreeSync = class extends BPTree {
600
601
  const comparator = this.verifierMap[key];
601
602
  const pairs = this.getPairs(value, startNode, fullScan, comparator, direction);
602
603
  if (!filterValues) {
603
- filterValues = new Set(pairs.map((pair) => pair.key));
604
+ filterValues = new Set(pairs.keys());
604
605
  } else {
605
606
  const intersections = /* @__PURE__ */ new Set();
606
607
  for (const key2 of filterValues) {
607
- const has = pairs.some((pair) => pair.key === key2);
608
+ const has = pairs.has(key2);
608
609
  if (has) {
609
610
  intersections.add(key2);
610
611
  }
@@ -627,16 +628,16 @@ var BPTreeSync = class extends BPTree {
627
628
  if (result === null) {
628
629
  result = pairs;
629
630
  } else {
630
- const intersection = [];
631
- for (const pair of pairs) {
632
- if (result.find((p) => p.key === pair.key)) {
633
- intersection.push(pair);
631
+ const intersection = /* @__PURE__ */ new Map();
632
+ for (const [k2, v] of pairs) {
633
+ if (result.has(k2)) {
634
+ intersection.set(k2, v);
634
635
  }
635
636
  }
636
637
  result = intersection;
637
638
  }
638
639
  }
639
- return result ?? [];
640
+ return result ?? /* @__PURE__ */ new Map();
640
641
  }
641
642
  insert(key, value) {
642
643
  const before = this.insertableNode(value);
@@ -732,7 +733,7 @@ var BPTreeAsync = class extends BPTree {
732
733
  constructor(strategy, comparator) {
733
734
  super(strategy, comparator);
734
735
  }
735
- async _getPairsRightToLeft(value, startNode, fullScan, comparator) {
736
+ async getPairsRightToLeft(value, startNode, fullScan, comparator) {
736
737
  const pairs = [];
737
738
  let node = startNode;
738
739
  let done = false;
@@ -746,7 +747,7 @@ var BPTreeAsync = class extends BPTree {
746
747
  found = true;
747
748
  let j = keys.length;
748
749
  while (j--) {
749
- pairs.push({ key: keys[j], value: nValue });
750
+ pairs.push([keys[j], nValue]);
750
751
  }
751
752
  } else if (found && !fullScan) {
752
753
  done = true;
@@ -759,9 +760,9 @@ var BPTreeAsync = class extends BPTree {
759
760
  }
760
761
  node = await this.getNode(node.prev);
761
762
  }
762
- return pairs.reverse();
763
+ return new Map(pairs.reverse());
763
764
  }
764
- async _getPairsLeftToRight(value, startNode, fullScan, comparator) {
765
+ async getPairsLeftToRight(value, startNode, fullScan, comparator) {
765
766
  const pairs = [];
766
767
  let node = startNode;
767
768
  let done = false;
@@ -772,8 +773,9 @@ var BPTreeAsync = class extends BPTree {
772
773
  const keys = node.keys[i];
773
774
  if (comparator(nValue, value)) {
774
775
  found = true;
775
- for (const key of keys) {
776
- pairs.push({ key, value: nValue });
776
+ for (let j = 0, len2 = keys.length; j < len2; j++) {
777
+ const key = keys[j];
778
+ pairs.push([key, nValue]);
777
779
  }
778
780
  } else if (found && !fullScan) {
779
781
  done = true;
@@ -786,14 +788,14 @@ var BPTreeAsync = class extends BPTree {
786
788
  }
787
789
  node = await this.getNode(node.next);
788
790
  }
789
- return pairs;
791
+ return new Map(pairs);
790
792
  }
791
793
  async getPairs(value, startNode, fullScan, comparator, direction) {
792
794
  switch (direction) {
793
795
  case -1:
794
- return await this._getPairsRightToLeft(value, startNode, fullScan, comparator);
796
+ return await this.getPairsRightToLeft(value, startNode, fullScan, comparator);
795
797
  case 1:
796
- return await this._getPairsLeftToRight(value, startNode, fullScan, comparator);
798
+ return await this.getPairsLeftToRight(value, startNode, fullScan, comparator);
797
799
  default:
798
800
  throw new Error(`Direction must be -1 or 1. but got a ${direction}`);
799
801
  }
@@ -1155,11 +1157,11 @@ var BPTreeAsync = class extends BPTree {
1155
1157
  const comparator = this.verifierMap[key];
1156
1158
  const pairs = await this.getPairs(value, startNode, fullScan, comparator, direction);
1157
1159
  if (!filterValues) {
1158
- filterValues = new Set(pairs.map((pair) => pair.key));
1160
+ filterValues = new Set(pairs.keys());
1159
1161
  } else {
1160
1162
  const intersections = /* @__PURE__ */ new Set();
1161
1163
  for (const key2 of filterValues) {
1162
- const has = pairs.some((pair) => pair.key === key2);
1164
+ const has = pairs.has(key2);
1163
1165
  if (has) {
1164
1166
  intersections.add(key2);
1165
1167
  }
@@ -1182,16 +1184,16 @@ var BPTreeAsync = class extends BPTree {
1182
1184
  if (result === null) {
1183
1185
  result = pairs;
1184
1186
  } else {
1185
- const intersection = [];
1186
- for (const pair of pairs) {
1187
- if (result.find((p) => p.key === pair.key)) {
1188
- intersection.push(pair);
1187
+ const intersection = /* @__PURE__ */ new Map();
1188
+ for (const [k2, v] of pairs) {
1189
+ if (result.has(k2)) {
1190
+ intersection.set(k2, v);
1189
1191
  }
1190
1192
  }
1191
1193
  result = intersection;
1192
1194
  }
1193
1195
  }
1194
- return result ?? [];
1196
+ return result ?? /* @__PURE__ */ new Map();
1195
1197
  }
1196
1198
  async insert(key, value) {
1197
1199
  const before = await this.insertableNode(value);
@@ -5,9 +5,9 @@ import { SerializableData } from './base/SerializeStrategy';
5
5
  export declare class BPTreeAsync<K, V> extends BPTree<K, V> {
6
6
  protected readonly strategy: SerializeStrategyAsync<K, V>;
7
7
  constructor(strategy: SerializeStrategyAsync<K, V>, comparator: ValueComparator<V>);
8
- protected _getPairsRightToLeft(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean): Promise<BPTreePair<K, V>[]>;
9
- protected _getPairsLeftToRight(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean): Promise<BPTreePair<K, V>[]>;
10
- protected getPairs(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean, direction: 1 | -1): Promise<BPTreePair<K, V>[]>;
8
+ protected getPairsRightToLeft(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean): Promise<BPTreePair<K, V>>;
9
+ protected getPairsLeftToRight(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean): Promise<BPTreePair<K, V>>;
10
+ protected getPairs(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean, direction: 1 | -1): Promise<BPTreePair<K, V>>;
11
11
  protected _createNodeId(isLeaf: boolean): Promise<string>;
12
12
  protected _createNode(isLeaf: boolean, keys: string[] | K[][], values: V[], leaf?: boolean, parent?: string | null, next?: string | null, prev?: string | null): Promise<BPTreeUnknownNode<K, V>>;
13
13
  protected _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>, value: V): Promise<void>;
@@ -21,7 +21,7 @@ export declare class BPTreeAsync<K, V> extends BPTree<K, V> {
21
21
  protected commitNodeUpdateBuffer(): Promise<void>;
22
22
  protected commitNodeDeleteBuffer(): Promise<void>;
23
23
  keys(condition: BPTreeCondition<V>, filterValues?: Set<K>): Promise<Set<K>>;
24
- where(condition: BPTreeCondition<V>): Promise<BPTreePair<K, V>[]>;
24
+ where(condition: BPTreeCondition<V>): Promise<BPTreePair<K, V>>;
25
25
  insert(key: K, value: V): Promise<void>;
26
26
  delete(key: K, value: V): Promise<void>;
27
27
  exists(key: K, value: V): Promise<boolean>;
@@ -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>, 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>[];
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(isLeaf: boolean): string;
12
12
  protected _createNode(isLeaf: boolean, keys: string[] | K[][], values: V[], leaf?: boolean, parent?: string | null, next?: string | null, prev?: string | null): BPTreeUnknownNode<K, V>;
13
13
  protected _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>, value: V): void;
@@ -21,7 +21,7 @@ export declare class BPTreeSync<K, V> extends BPTree<K, V> {
21
21
  protected commitNodeUpdateBuffer(): void;
22
22
  protected commitNodeDeleteBuffer(): void;
23
23
  keys(condition: BPTreeCondition<V>, filterValues?: Set<K>): Set<K>;
24
- where(condition: BPTreeCondition<V>): BPTreePair<K, V>[];
24
+ where(condition: BPTreeCondition<V>): BPTreePair<K, V>;
25
25
  insert(key: K, value: V): void;
26
26
  delete(key: K, value: V): void;
27
27
  exists(key: K, value: V): boolean;
@@ -21,10 +21,7 @@ export type BPTreeCondition<V> = Partial<{
21
21
  /** Searches for values matching the given pattern. '%' matches zero or more characters, and '_' matches exactly one character. */
22
22
  like: Partial<V>;
23
23
  }>;
24
- export type BPTreePair<K, V> = {
25
- key: K;
26
- value: V;
27
- };
24
+ export type BPTreePair<K, V> = Map<K, V>;
28
25
  export type BPTreeUnknownNode<K, V> = BPTreeInternalNode<K, V> | BPTreeLeafNode<K, V>;
29
26
  export interface BPTreeNode<K, V> {
30
27
  id: string;
@@ -58,9 +55,9 @@ export declare abstract class BPTree<K, V> {
58
55
  protected readonly verifierDirection: Record<keyof BPTreeCondition<V>, -1 | 1>;
59
56
  protected readonly verifierFullScan: Record<keyof BPTreeCondition<V>, boolean>;
60
57
  protected constructor(strategy: SerializeStrategy<K, V>, comparator: ValueComparator<V>);
61
- protected abstract _getPairsRightToLeft(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean): Deferred<BPTreePair<K, V>[]>;
62
- protected abstract _getPairsLeftToRight(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean): Deferred<BPTreePair<K, V>[]>;
63
- protected abstract getPairs(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean, direction: -1 | 1): Deferred<BPTreePair<K, V>[]>;
58
+ protected abstract getPairsRightToLeft(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean): Deferred<BPTreePair<K, V>>;
59
+ protected abstract getPairsLeftToRight(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean): Deferred<BPTreePair<K, V>>;
60
+ protected abstract getPairs(value: V, startNode: BPTreeLeafNode<K, V>, fullScan: boolean, comparator: (nodeValue: V, value: V) => boolean, direction: -1 | 1): Deferred<BPTreePair<K, V>>;
64
61
  protected abstract _createNodeId(isLeaf: boolean): Deferred<string>;
65
62
  protected abstract _createNode(isLeaf: boolean, keys: string[] | K[][], values: V[], leaf?: boolean, parent?: string | null, next?: string | null, prev?: string | null): Deferred<BPTreeUnknownNode<K, V>>;
66
63
  protected abstract _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>, value: V): Deferred<void>;
@@ -92,7 +89,7 @@ export declare abstract class BPTree<K, V> {
92
89
  * The result includes the key and value attributes, and you can use the `gt`, `lt`, `gte`, `lte`, `equal`, `notEqual`, `like` condition statements.
93
90
  * @param condition You can use the `gt`, `lt`, `gte`, `lte`, `equal`, `notEqual`, `like` condition statements.
94
91
  */
95
- abstract where(condition: BPTreeCondition<V>): Deferred<BPTreePair<K, V>[]>;
92
+ abstract where(condition: BPTreeCondition<V>): Deferred<BPTreePair<K, V>>;
96
93
  /**
97
94
  * You enter the key and value as a pair. You can later search for the pair by value.
98
95
  * This data is stored in the tree, sorted in ascending order of value.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "4.0.5",
3
+ "version": "5.0.0",
4
4
  "description": "Store the B+tree flexibly, not only in-memory.",
5
5
  "types": "./dist/types/index.d.ts",
6
6
  "main": "./dist/cjs/index.cjs",