serializable-bptree 4.0.4 → 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,12 +635,13 @@ 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
- for (const pair of pairs) {
641
- if (filterValues.has(pair.key)) {
642
- intersections.add(pair.key);
641
+ for (const key2 of filterValues) {
642
+ const has = pairs.has(key2);
643
+ if (has) {
644
+ intersections.add(key2);
643
645
  }
644
646
  }
645
647
  filterValues = intersections;
@@ -660,16 +662,16 @@ var BPTreeSync = class extends BPTree {
660
662
  if (result === null) {
661
663
  result = pairs;
662
664
  } else {
663
- const intersection = [];
664
- for (const pair of pairs) {
665
- if (result.find((p) => p.key === pair.key)) {
666
- 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);
667
669
  }
668
670
  }
669
671
  result = intersection;
670
672
  }
671
673
  }
672
- return result ?? [];
674
+ return result ?? /* @__PURE__ */ new Map();
673
675
  }
674
676
  insert(key, value) {
675
677
  const before = this.insertableNode(value);
@@ -765,7 +767,7 @@ var BPTreeAsync = class extends BPTree {
765
767
  constructor(strategy, comparator) {
766
768
  super(strategy, comparator);
767
769
  }
768
- async _getPairsRightToLeft(value, startNode, fullScan, comparator) {
770
+ async getPairsRightToLeft(value, startNode, fullScan, comparator) {
769
771
  const pairs = [];
770
772
  let node = startNode;
771
773
  let done = false;
@@ -779,7 +781,7 @@ var BPTreeAsync = class extends BPTree {
779
781
  found = true;
780
782
  let j = keys.length;
781
783
  while (j--) {
782
- pairs.push({ key: keys[j], value: nValue });
784
+ pairs.push([keys[j], nValue]);
783
785
  }
784
786
  } else if (found && !fullScan) {
785
787
  done = true;
@@ -792,9 +794,9 @@ var BPTreeAsync = class extends BPTree {
792
794
  }
793
795
  node = await this.getNode(node.prev);
794
796
  }
795
- return pairs.reverse();
797
+ return new Map(pairs.reverse());
796
798
  }
797
- async _getPairsLeftToRight(value, startNode, fullScan, comparator) {
799
+ async getPairsLeftToRight(value, startNode, fullScan, comparator) {
798
800
  const pairs = [];
799
801
  let node = startNode;
800
802
  let done = false;
@@ -805,8 +807,9 @@ var BPTreeAsync = class extends BPTree {
805
807
  const keys = node.keys[i];
806
808
  if (comparator(nValue, value)) {
807
809
  found = true;
808
- for (const key of keys) {
809
- 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]);
810
813
  }
811
814
  } else if (found && !fullScan) {
812
815
  done = true;
@@ -819,14 +822,14 @@ var BPTreeAsync = class extends BPTree {
819
822
  }
820
823
  node = await this.getNode(node.next);
821
824
  }
822
- return pairs;
825
+ return new Map(pairs);
823
826
  }
824
827
  async getPairs(value, startNode, fullScan, comparator, direction) {
825
828
  switch (direction) {
826
829
  case -1:
827
- return await this._getPairsRightToLeft(value, startNode, fullScan, comparator);
830
+ return await this.getPairsRightToLeft(value, startNode, fullScan, comparator);
828
831
  case 1:
829
- return await this._getPairsLeftToRight(value, startNode, fullScan, comparator);
832
+ return await this.getPairsLeftToRight(value, startNode, fullScan, comparator);
830
833
  default:
831
834
  throw new Error(`Direction must be -1 or 1. but got a ${direction}`);
832
835
  }
@@ -1188,12 +1191,13 @@ var BPTreeAsync = class extends BPTree {
1188
1191
  const comparator = this.verifierMap[key];
1189
1192
  const pairs = await this.getPairs(value, startNode, fullScan, comparator, direction);
1190
1193
  if (!filterValues) {
1191
- filterValues = new Set(pairs.map((pair) => pair.key));
1194
+ filterValues = new Set(pairs.keys());
1192
1195
  } else {
1193
1196
  const intersections = /* @__PURE__ */ new Set();
1194
- for (const pair of pairs) {
1195
- if (filterValues.has(pair.key)) {
1196
- intersections.add(pair.key);
1197
+ for (const key2 of filterValues) {
1198
+ const has = pairs.has(key2);
1199
+ if (has) {
1200
+ intersections.add(key2);
1197
1201
  }
1198
1202
  }
1199
1203
  filterValues = intersections;
@@ -1214,16 +1218,16 @@ var BPTreeAsync = class extends BPTree {
1214
1218
  if (result === null) {
1215
1219
  result = pairs;
1216
1220
  } else {
1217
- const intersection = [];
1218
- for (const pair of pairs) {
1219
- if (result.find((p) => p.key === pair.key)) {
1220
- 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);
1221
1225
  }
1222
1226
  }
1223
1227
  result = intersection;
1224
1228
  }
1225
1229
  }
1226
- return result ?? [];
1230
+ return result ?? /* @__PURE__ */ new Map();
1227
1231
  }
1228
1232
  async insert(key, value) {
1229
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,12 +601,13 @@ 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
- for (const pair of pairs) {
607
- if (filterValues.has(pair.key)) {
608
- intersections.add(pair.key);
607
+ for (const key2 of filterValues) {
608
+ const has = pairs.has(key2);
609
+ if (has) {
610
+ intersections.add(key2);
609
611
  }
610
612
  }
611
613
  filterValues = intersections;
@@ -626,16 +628,16 @@ var BPTreeSync = class extends BPTree {
626
628
  if (result === null) {
627
629
  result = pairs;
628
630
  } else {
629
- const intersection = [];
630
- for (const pair of pairs) {
631
- if (result.find((p) => p.key === pair.key)) {
632
- 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);
633
635
  }
634
636
  }
635
637
  result = intersection;
636
638
  }
637
639
  }
638
- return result ?? [];
640
+ return result ?? /* @__PURE__ */ new Map();
639
641
  }
640
642
  insert(key, value) {
641
643
  const before = this.insertableNode(value);
@@ -731,7 +733,7 @@ var BPTreeAsync = class extends BPTree {
731
733
  constructor(strategy, comparator) {
732
734
  super(strategy, comparator);
733
735
  }
734
- async _getPairsRightToLeft(value, startNode, fullScan, comparator) {
736
+ async getPairsRightToLeft(value, startNode, fullScan, comparator) {
735
737
  const pairs = [];
736
738
  let node = startNode;
737
739
  let done = false;
@@ -745,7 +747,7 @@ var BPTreeAsync = class extends BPTree {
745
747
  found = true;
746
748
  let j = keys.length;
747
749
  while (j--) {
748
- pairs.push({ key: keys[j], value: nValue });
750
+ pairs.push([keys[j], nValue]);
749
751
  }
750
752
  } else if (found && !fullScan) {
751
753
  done = true;
@@ -758,9 +760,9 @@ var BPTreeAsync = class extends BPTree {
758
760
  }
759
761
  node = await this.getNode(node.prev);
760
762
  }
761
- return pairs.reverse();
763
+ return new Map(pairs.reverse());
762
764
  }
763
- async _getPairsLeftToRight(value, startNode, fullScan, comparator) {
765
+ async getPairsLeftToRight(value, startNode, fullScan, comparator) {
764
766
  const pairs = [];
765
767
  let node = startNode;
766
768
  let done = false;
@@ -771,8 +773,9 @@ var BPTreeAsync = class extends BPTree {
771
773
  const keys = node.keys[i];
772
774
  if (comparator(nValue, value)) {
773
775
  found = true;
774
- for (const key of keys) {
775
- 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]);
776
779
  }
777
780
  } else if (found && !fullScan) {
778
781
  done = true;
@@ -785,14 +788,14 @@ var BPTreeAsync = class extends BPTree {
785
788
  }
786
789
  node = await this.getNode(node.next);
787
790
  }
788
- return pairs;
791
+ return new Map(pairs);
789
792
  }
790
793
  async getPairs(value, startNode, fullScan, comparator, direction) {
791
794
  switch (direction) {
792
795
  case -1:
793
- return await this._getPairsRightToLeft(value, startNode, fullScan, comparator);
796
+ return await this.getPairsRightToLeft(value, startNode, fullScan, comparator);
794
797
  case 1:
795
- return await this._getPairsLeftToRight(value, startNode, fullScan, comparator);
798
+ return await this.getPairsLeftToRight(value, startNode, fullScan, comparator);
796
799
  default:
797
800
  throw new Error(`Direction must be -1 or 1. but got a ${direction}`);
798
801
  }
@@ -1154,12 +1157,13 @@ var BPTreeAsync = class extends BPTree {
1154
1157
  const comparator = this.verifierMap[key];
1155
1158
  const pairs = await this.getPairs(value, startNode, fullScan, comparator, direction);
1156
1159
  if (!filterValues) {
1157
- filterValues = new Set(pairs.map((pair) => pair.key));
1160
+ filterValues = new Set(pairs.keys());
1158
1161
  } else {
1159
1162
  const intersections = /* @__PURE__ */ new Set();
1160
- for (const pair of pairs) {
1161
- if (filterValues.has(pair.key)) {
1162
- intersections.add(pair.key);
1163
+ for (const key2 of filterValues) {
1164
+ const has = pairs.has(key2);
1165
+ if (has) {
1166
+ intersections.add(key2);
1163
1167
  }
1164
1168
  }
1165
1169
  filterValues = intersections;
@@ -1180,16 +1184,16 @@ var BPTreeAsync = class extends BPTree {
1180
1184
  if (result === null) {
1181
1185
  result = pairs;
1182
1186
  } else {
1183
- const intersection = [];
1184
- for (const pair of pairs) {
1185
- if (result.find((p) => p.key === pair.key)) {
1186
- 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);
1187
1191
  }
1188
1192
  }
1189
1193
  result = intersection;
1190
1194
  }
1191
1195
  }
1192
- return result ?? [];
1196
+ return result ?? /* @__PURE__ */ new Map();
1193
1197
  }
1194
1198
  async insert(key, value) {
1195
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.4",
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",
@@ -36,10 +36,10 @@
36
36
  },
37
37
  "license": "MIT",
38
38
  "devDependencies": {
39
- "@types/jest": "^29.5.13",
40
- "esbuild": "^0.23.1",
39
+ "@types/jest": "^29.5.14",
40
+ "esbuild": "^0.24.0",
41
41
  "jest": "^29.7.0",
42
42
  "ts-jest": "^29.2.5",
43
- "typescript": "^5.6.2"
43
+ "typescript": "^5.6.3"
44
44
  }
45
45
  }