serializable-bptree 1.0.2 → 1.0.4

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 CHANGED
@@ -189,7 +189,8 @@ var BPTree = class {
189
189
  leftestNode() {
190
190
  let node = this.root;
191
191
  while (!node.leaf) {
192
- node = node.keys[0];
192
+ const keys = node.keys;
193
+ node = this.getNode(keys[0]);
193
194
  }
194
195
  return node;
195
196
  }
@@ -198,14 +199,15 @@ var BPTree = class {
198
199
  while (!node.leaf) {
199
200
  for (let i = 0, len = node.values.length; i < len; i++) {
200
201
  const nValue = node.values[i];
202
+ const k = node.keys;
201
203
  if (this.comparator.isSame(value, nValue)) {
202
- node = node.keys[i + 1];
204
+ node = this.getNode(k[i + 1]);
203
205
  break;
204
206
  } else if (this.comparator.isLower(value, nValue)) {
205
- node = node.keys[i];
207
+ node = this.getNode(k[i]);
206
208
  break;
207
209
  } else if (i + 1 === node.values.length) {
208
- node = node.keys[i + 1];
210
+ node = this.getNode(k[i + 1]);
209
211
  break;
210
212
  }
211
213
  }
@@ -257,7 +259,7 @@ var BPTree = class {
257
259
  }
258
260
  _insertInParent(node, value, pointer) {
259
261
  if (this.root === node) {
260
- const root = this._createNode([node, pointer], [value]);
262
+ const root = this._createNode([node.id, pointer.id], [value]);
261
263
  this.root = root;
262
264
  node.parent = root.id;
263
265
  pointer.parent = root.id;
@@ -270,9 +272,9 @@ var BPTree = class {
270
272
  const parentNode = this.getNode(node.parent);
271
273
  for (let i = 0, len = parentNode.keys.length; i < len; i++) {
272
274
  const nKeys = parentNode.keys[i];
273
- if (nKeys === node) {
275
+ if (nKeys === node.id) {
274
276
  parentNode.values.splice(i, 0, value);
275
- parentNode.keys.splice(i + 1, 0, pointer);
277
+ parentNode.keys.splice(i + 1, 0, pointer.id);
276
278
  this._setUpdates(parentNode);
277
279
  if (parentNode.keys.length > this.order) {
278
280
  const parentPointer = this._createNode([], []);
@@ -288,12 +290,14 @@ var BPTree = class {
288
290
  }
289
291
  parentNode.keys = parentNode.keys.slice(0, mid + 1);
290
292
  for (const k of parentNode.keys) {
291
- const key = k;
292
- key.parent = parentNode.id;
293
+ const node2 = this.getNode(k);
294
+ node2.parent = parentNode.id;
295
+ this._setUpdates(node2);
293
296
  }
294
297
  for (const k of parentPointer.keys) {
295
- const key = k;
296
- key.parent = parentPointer.id;
298
+ const node2 = this.getNode(k);
299
+ node2.parent = parentPointer.id;
300
+ this._setUpdates(node2);
297
301
  }
298
302
  this._insertInParent(parentNode, midValue, parentPointer);
299
303
  this._setCreates(parentPointer);
@@ -317,6 +321,124 @@ var BPTree = class {
317
321
  _rangeCondition(condition) {
318
322
  return Object.prototype.hasOwnProperty.call(condition, "gt") && Object.prototype.hasOwnProperty.call(condition, "lt");
319
323
  }
324
+ _getKeysFromValue(value) {
325
+ const keys = /* @__PURE__ */ new Set();
326
+ const node = this._insertableNode(value);
327
+ const [start, end] = this.search.range(node.values, value);
328
+ if (start === -1) {
329
+ return keys;
330
+ }
331
+ for (let i = start; i < end; i++) {
332
+ const pairKeys = node.keys[i];
333
+ for (const key of pairKeys) {
334
+ keys.add(key);
335
+ }
336
+ }
337
+ return keys;
338
+ }
339
+ _getKeysFromNEValue(value) {
340
+ const keys = /* @__PURE__ */ new Set();
341
+ let node = this.leftestNode();
342
+ let done = false;
343
+ while (!done) {
344
+ for (let i = 0, len = node.values.length; i < len; i++) {
345
+ const nValue = node.values[i];
346
+ const pairKeys = node.keys[i];
347
+ if (this.comparator.isSame(nValue, value) === false) {
348
+ for (const key of pairKeys) {
349
+ keys.add(key);
350
+ }
351
+ }
352
+ }
353
+ if (!node.next) {
354
+ done = true;
355
+ break;
356
+ }
357
+ node = this.getNode(node.next);
358
+ }
359
+ return keys;
360
+ }
361
+ _getKeysFromRange(gt, lt) {
362
+ const keys = /* @__PURE__ */ new Set();
363
+ let node = this._insertableNode(gt);
364
+ let done = false;
365
+ let found = false;
366
+ while (!done) {
367
+ for (let i = 0, len = node.values.length; i < len; i++) {
368
+ const nValue = node.values[i];
369
+ const localKeys = node.keys[i];
370
+ if (this.comparator.isHigher(nValue, gt) && this.comparator.isLower(nValue, lt)) {
371
+ found = true;
372
+ for (const key of localKeys) {
373
+ keys.add(key);
374
+ }
375
+ } else if (found) {
376
+ done = true;
377
+ break;
378
+ }
379
+ }
380
+ if (!node.next) {
381
+ done = true;
382
+ break;
383
+ }
384
+ node = this.getNode(node.next);
385
+ }
386
+ return keys;
387
+ }
388
+ _getKeysFromGt(gt) {
389
+ const keys = /* @__PURE__ */ new Set();
390
+ let node = this._insertableNode(gt);
391
+ let done = false;
392
+ let found = false;
393
+ while (!done) {
394
+ for (let i = 0, len = node.values.length; i < len; i++) {
395
+ const nValue = node.values[i];
396
+ const localKeys = node.keys[i];
397
+ if (this.comparator.isHigher(nValue, gt)) {
398
+ found = true;
399
+ for (const key of localKeys) {
400
+ keys.add(key);
401
+ }
402
+ } else if (found) {
403
+ done = true;
404
+ break;
405
+ }
406
+ }
407
+ if (!node.next) {
408
+ done = true;
409
+ break;
410
+ }
411
+ node = this.getNode(node.next);
412
+ }
413
+ return keys;
414
+ }
415
+ _getKeysFromLt(lt) {
416
+ const keys = /* @__PURE__ */ new Set();
417
+ let node = this.leftestNode();
418
+ let done = false;
419
+ let found = false;
420
+ while (!done) {
421
+ for (let i = 0, len = node.values.length; i < len; i++) {
422
+ const nValue = node.values[i];
423
+ const localKeys = node.keys[i];
424
+ if (this.comparator.isLower(nValue, lt)) {
425
+ found = true;
426
+ for (const key of localKeys) {
427
+ keys.add(key);
428
+ }
429
+ } else if (found) {
430
+ done = true;
431
+ break;
432
+ }
433
+ }
434
+ if (!node.next) {
435
+ done = true;
436
+ break;
437
+ }
438
+ node = this.getNode(node.next);
439
+ }
440
+ return keys;
441
+ }
320
442
  _getPairsFromValue(value) {
321
443
  const node = this._insertableNode(value);
322
444
  const [start, end] = this.search.range(node.values, value);
@@ -435,6 +557,28 @@ var BPTree = class {
435
557
  }
436
558
  return pairs;
437
559
  }
560
+ /**
561
+ * It searches for a key within the tree. The result is returned as an array sorted in ascending order based on the value.
562
+ * The result is key set instance, and you can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
563
+ * This method operates much faster than first searching with `where` and then retrieving only the key list.
564
+ * @param condition You can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
565
+ */
566
+ keys(condition) {
567
+ if (this._equalCondition(condition)) {
568
+ return this._getKeysFromValue(condition.equal);
569
+ } else if (this._notEqualCondition(condition)) {
570
+ return this._getKeysFromNEValue(condition.notEqual);
571
+ } else if (this._rangeCondition(condition)) {
572
+ const { gt, lt } = condition;
573
+ return this._getKeysFromRange(gt, lt);
574
+ } else if (this._onlyGtCondition(condition)) {
575
+ return this._getKeysFromGt(condition.gt);
576
+ } else if (this._onlyLtCondition(condition)) {
577
+ return this._getKeysFromLt(condition.lt);
578
+ } else {
579
+ throw new Error(`The 'condition' parameter is invalid.`);
580
+ }
581
+ }
438
582
  /**
439
583
  * It searches for a value within the tree. The result is returned as an array sorted in ascending order based on the value.
440
584
  * The result includes the key and value attributes, and you can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
@@ -542,7 +686,7 @@ var BPTree = class {
542
686
  }
543
687
  if (this.root === node && node.keys.length === 1) {
544
688
  const keys = node.keys;
545
- this.root = keys[0];
689
+ this.root = this.getNode(keys[0]);
546
690
  this.root.parent = 0;
547
691
  this._setHeadUpdate(this._headState);
548
692
  this._setUpdates(this.root);
@@ -558,13 +702,13 @@ var BPTree = class {
558
702
  let postK = null;
559
703
  for (let i = 0, len = parentNode.keys.length; i < len; i++) {
560
704
  const nKey = parentNode.keys[i];
561
- if (nKey === node) {
705
+ if (nKey === node.id) {
562
706
  if (i > 0) {
563
- prevNode = parentNode.keys[i - 1];
707
+ prevNode = this.getNode(parentNode.keys[i - 1]);
564
708
  prevK = parentNode.values[i - 1];
565
709
  }
566
710
  if (i < parentNode.keys.length - 1) {
567
- nextNode = parentNode.keys[i + 1];
711
+ nextNode = this.getNode(parentNode.keys[i + 1]);
568
712
  postK = parentNode.values[i];
569
713
  }
570
714
  }
@@ -604,10 +748,12 @@ var BPTree = class {
604
748
  if (!pointer.leaf) {
605
749
  const keys = pointer.keys;
606
750
  for (const key2 of keys) {
607
- key2.parent = pointer.id;
751
+ const node2 = this.getNode(key2);
752
+ node2.parent = pointer.id;
753
+ this._setUpdates(node2);
608
754
  }
609
755
  }
610
- this._deleteEntry(this.getNode(node.parent), node, guess);
756
+ this._deleteEntry(this.getNode(node.parent), node.id, guess);
611
757
  this._setUpdates(pointer);
612
758
  } else {
613
759
  if (isPredecessor) {
@@ -680,24 +826,24 @@ var BPTree = class {
680
826
  this._setUpdates(pointer);
681
827
  }
682
828
  if (!pointer.leaf) {
683
- const keys = pointer.keys;
684
- for (const key2 of keys) {
685
- key2.parent = pointer.id;
686
- this._setUpdates(pointer);
829
+ for (const key2 of pointer.keys) {
830
+ const n = this.getNode(key2);
831
+ n.parent = pointer.id;
832
+ this._setUpdates(n);
687
833
  }
688
834
  }
689
835
  if (!node.leaf) {
690
- const keys = node.keys;
691
- for (const key2 of keys) {
692
- key2.parent = node.id;
693
- this._setUpdates(node);
836
+ for (const key2 of node.keys) {
837
+ const n = this.getNode(key2);
838
+ n.parent = node.id;
839
+ this._setUpdates(n);
694
840
  }
695
841
  }
696
842
  if (!parentNode.leaf) {
697
- const keys = parentNode.keys;
698
- for (const key2 of keys) {
699
- key2.parent = parentNode.id;
700
- this._setUpdates(parentNode);
843
+ for (const key2 of parentNode.keys) {
844
+ const n = this.getNode(key2);
845
+ n.parent = parentNode.id;
846
+ this._setUpdates(n);
701
847
  }
702
848
  }
703
849
  }
package/dist/esm/index.js CHANGED
@@ -158,7 +158,8 @@ var BPTree = class {
158
158
  leftestNode() {
159
159
  let node = this.root;
160
160
  while (!node.leaf) {
161
- node = node.keys[0];
161
+ const keys = node.keys;
162
+ node = this.getNode(keys[0]);
162
163
  }
163
164
  return node;
164
165
  }
@@ -167,14 +168,15 @@ var BPTree = class {
167
168
  while (!node.leaf) {
168
169
  for (let i = 0, len = node.values.length; i < len; i++) {
169
170
  const nValue = node.values[i];
171
+ const k = node.keys;
170
172
  if (this.comparator.isSame(value, nValue)) {
171
- node = node.keys[i + 1];
173
+ node = this.getNode(k[i + 1]);
172
174
  break;
173
175
  } else if (this.comparator.isLower(value, nValue)) {
174
- node = node.keys[i];
176
+ node = this.getNode(k[i]);
175
177
  break;
176
178
  } else if (i + 1 === node.values.length) {
177
- node = node.keys[i + 1];
179
+ node = this.getNode(k[i + 1]);
178
180
  break;
179
181
  }
180
182
  }
@@ -226,7 +228,7 @@ var BPTree = class {
226
228
  }
227
229
  _insertInParent(node, value, pointer) {
228
230
  if (this.root === node) {
229
- const root = this._createNode([node, pointer], [value]);
231
+ const root = this._createNode([node.id, pointer.id], [value]);
230
232
  this.root = root;
231
233
  node.parent = root.id;
232
234
  pointer.parent = root.id;
@@ -239,9 +241,9 @@ var BPTree = class {
239
241
  const parentNode = this.getNode(node.parent);
240
242
  for (let i = 0, len = parentNode.keys.length; i < len; i++) {
241
243
  const nKeys = parentNode.keys[i];
242
- if (nKeys === node) {
244
+ if (nKeys === node.id) {
243
245
  parentNode.values.splice(i, 0, value);
244
- parentNode.keys.splice(i + 1, 0, pointer);
246
+ parentNode.keys.splice(i + 1, 0, pointer.id);
245
247
  this._setUpdates(parentNode);
246
248
  if (parentNode.keys.length > this.order) {
247
249
  const parentPointer = this._createNode([], []);
@@ -257,12 +259,14 @@ var BPTree = class {
257
259
  }
258
260
  parentNode.keys = parentNode.keys.slice(0, mid + 1);
259
261
  for (const k of parentNode.keys) {
260
- const key = k;
261
- key.parent = parentNode.id;
262
+ const node2 = this.getNode(k);
263
+ node2.parent = parentNode.id;
264
+ this._setUpdates(node2);
262
265
  }
263
266
  for (const k of parentPointer.keys) {
264
- const key = k;
265
- key.parent = parentPointer.id;
267
+ const node2 = this.getNode(k);
268
+ node2.parent = parentPointer.id;
269
+ this._setUpdates(node2);
266
270
  }
267
271
  this._insertInParent(parentNode, midValue, parentPointer);
268
272
  this._setCreates(parentPointer);
@@ -286,6 +290,124 @@ var BPTree = class {
286
290
  _rangeCondition(condition) {
287
291
  return Object.prototype.hasOwnProperty.call(condition, "gt") && Object.prototype.hasOwnProperty.call(condition, "lt");
288
292
  }
293
+ _getKeysFromValue(value) {
294
+ const keys = /* @__PURE__ */ new Set();
295
+ const node = this._insertableNode(value);
296
+ const [start, end] = this.search.range(node.values, value);
297
+ if (start === -1) {
298
+ return keys;
299
+ }
300
+ for (let i = start; i < end; i++) {
301
+ const pairKeys = node.keys[i];
302
+ for (const key of pairKeys) {
303
+ keys.add(key);
304
+ }
305
+ }
306
+ return keys;
307
+ }
308
+ _getKeysFromNEValue(value) {
309
+ const keys = /* @__PURE__ */ new Set();
310
+ let node = this.leftestNode();
311
+ let done = false;
312
+ while (!done) {
313
+ for (let i = 0, len = node.values.length; i < len; i++) {
314
+ const nValue = node.values[i];
315
+ const pairKeys = node.keys[i];
316
+ if (this.comparator.isSame(nValue, value) === false) {
317
+ for (const key of pairKeys) {
318
+ keys.add(key);
319
+ }
320
+ }
321
+ }
322
+ if (!node.next) {
323
+ done = true;
324
+ break;
325
+ }
326
+ node = this.getNode(node.next);
327
+ }
328
+ return keys;
329
+ }
330
+ _getKeysFromRange(gt, lt) {
331
+ const keys = /* @__PURE__ */ new Set();
332
+ let node = this._insertableNode(gt);
333
+ let done = false;
334
+ let found = false;
335
+ while (!done) {
336
+ for (let i = 0, len = node.values.length; i < len; i++) {
337
+ const nValue = node.values[i];
338
+ const localKeys = node.keys[i];
339
+ if (this.comparator.isHigher(nValue, gt) && this.comparator.isLower(nValue, lt)) {
340
+ found = true;
341
+ for (const key of localKeys) {
342
+ keys.add(key);
343
+ }
344
+ } else if (found) {
345
+ done = true;
346
+ break;
347
+ }
348
+ }
349
+ if (!node.next) {
350
+ done = true;
351
+ break;
352
+ }
353
+ node = this.getNode(node.next);
354
+ }
355
+ return keys;
356
+ }
357
+ _getKeysFromGt(gt) {
358
+ const keys = /* @__PURE__ */ new Set();
359
+ let node = this._insertableNode(gt);
360
+ let done = false;
361
+ let found = false;
362
+ while (!done) {
363
+ for (let i = 0, len = node.values.length; i < len; i++) {
364
+ const nValue = node.values[i];
365
+ const localKeys = node.keys[i];
366
+ if (this.comparator.isHigher(nValue, gt)) {
367
+ found = true;
368
+ for (const key of localKeys) {
369
+ keys.add(key);
370
+ }
371
+ } else if (found) {
372
+ done = true;
373
+ break;
374
+ }
375
+ }
376
+ if (!node.next) {
377
+ done = true;
378
+ break;
379
+ }
380
+ node = this.getNode(node.next);
381
+ }
382
+ return keys;
383
+ }
384
+ _getKeysFromLt(lt) {
385
+ const keys = /* @__PURE__ */ new Set();
386
+ let node = this.leftestNode();
387
+ let done = false;
388
+ let found = false;
389
+ while (!done) {
390
+ for (let i = 0, len = node.values.length; i < len; i++) {
391
+ const nValue = node.values[i];
392
+ const localKeys = node.keys[i];
393
+ if (this.comparator.isLower(nValue, lt)) {
394
+ found = true;
395
+ for (const key of localKeys) {
396
+ keys.add(key);
397
+ }
398
+ } else if (found) {
399
+ done = true;
400
+ break;
401
+ }
402
+ }
403
+ if (!node.next) {
404
+ done = true;
405
+ break;
406
+ }
407
+ node = this.getNode(node.next);
408
+ }
409
+ return keys;
410
+ }
289
411
  _getPairsFromValue(value) {
290
412
  const node = this._insertableNode(value);
291
413
  const [start, end] = this.search.range(node.values, value);
@@ -404,6 +526,28 @@ var BPTree = class {
404
526
  }
405
527
  return pairs;
406
528
  }
529
+ /**
530
+ * It searches for a key within the tree. The result is returned as an array sorted in ascending order based on the value.
531
+ * The result is key set instance, and you can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
532
+ * This method operates much faster than first searching with `where` and then retrieving only the key list.
533
+ * @param condition You can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
534
+ */
535
+ keys(condition) {
536
+ if (this._equalCondition(condition)) {
537
+ return this._getKeysFromValue(condition.equal);
538
+ } else if (this._notEqualCondition(condition)) {
539
+ return this._getKeysFromNEValue(condition.notEqual);
540
+ } else if (this._rangeCondition(condition)) {
541
+ const { gt, lt } = condition;
542
+ return this._getKeysFromRange(gt, lt);
543
+ } else if (this._onlyGtCondition(condition)) {
544
+ return this._getKeysFromGt(condition.gt);
545
+ } else if (this._onlyLtCondition(condition)) {
546
+ return this._getKeysFromLt(condition.lt);
547
+ } else {
548
+ throw new Error(`The 'condition' parameter is invalid.`);
549
+ }
550
+ }
407
551
  /**
408
552
  * It searches for a value within the tree. The result is returned as an array sorted in ascending order based on the value.
409
553
  * The result includes the key and value attributes, and you can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
@@ -511,7 +655,7 @@ var BPTree = class {
511
655
  }
512
656
  if (this.root === node && node.keys.length === 1) {
513
657
  const keys = node.keys;
514
- this.root = keys[0];
658
+ this.root = this.getNode(keys[0]);
515
659
  this.root.parent = 0;
516
660
  this._setHeadUpdate(this._headState);
517
661
  this._setUpdates(this.root);
@@ -527,13 +671,13 @@ var BPTree = class {
527
671
  let postK = null;
528
672
  for (let i = 0, len = parentNode.keys.length; i < len; i++) {
529
673
  const nKey = parentNode.keys[i];
530
- if (nKey === node) {
674
+ if (nKey === node.id) {
531
675
  if (i > 0) {
532
- prevNode = parentNode.keys[i - 1];
676
+ prevNode = this.getNode(parentNode.keys[i - 1]);
533
677
  prevK = parentNode.values[i - 1];
534
678
  }
535
679
  if (i < parentNode.keys.length - 1) {
536
- nextNode = parentNode.keys[i + 1];
680
+ nextNode = this.getNode(parentNode.keys[i + 1]);
537
681
  postK = parentNode.values[i];
538
682
  }
539
683
  }
@@ -573,10 +717,12 @@ var BPTree = class {
573
717
  if (!pointer.leaf) {
574
718
  const keys = pointer.keys;
575
719
  for (const key2 of keys) {
576
- key2.parent = pointer.id;
720
+ const node2 = this.getNode(key2);
721
+ node2.parent = pointer.id;
722
+ this._setUpdates(node2);
577
723
  }
578
724
  }
579
- this._deleteEntry(this.getNode(node.parent), node, guess);
725
+ this._deleteEntry(this.getNode(node.parent), node.id, guess);
580
726
  this._setUpdates(pointer);
581
727
  } else {
582
728
  if (isPredecessor) {
@@ -649,24 +795,24 @@ var BPTree = class {
649
795
  this._setUpdates(pointer);
650
796
  }
651
797
  if (!pointer.leaf) {
652
- const keys = pointer.keys;
653
- for (const key2 of keys) {
654
- key2.parent = pointer.id;
655
- this._setUpdates(pointer);
798
+ for (const key2 of pointer.keys) {
799
+ const n = this.getNode(key2);
800
+ n.parent = pointer.id;
801
+ this._setUpdates(n);
656
802
  }
657
803
  }
658
804
  if (!node.leaf) {
659
- const keys = node.keys;
660
- for (const key2 of keys) {
661
- key2.parent = node.id;
662
- this._setUpdates(node);
805
+ for (const key2 of node.keys) {
806
+ const n = this.getNode(key2);
807
+ n.parent = node.id;
808
+ this._setUpdates(n);
663
809
  }
664
810
  }
665
811
  if (!parentNode.leaf) {
666
- const keys = parentNode.keys;
667
- for (const key2 of keys) {
668
- key2.parent = parentNode.id;
669
- this._setUpdates(parentNode);
812
+ for (const key2 of parentNode.keys) {
813
+ const n = this.getNode(key2);
814
+ n.parent = parentNode.id;
815
+ this._setUpdates(n);
670
816
  }
671
817
  }
672
818
  }
@@ -1,7 +1,6 @@
1
1
  import { BinarySearch } from './utils/BinarySearch';
2
2
  import { ValueComparator } from './ValueComparator';
3
3
  import { SerializeStrategy } from './SerializeStrategy';
4
- type BPTreeNodeKey<K, V> = K[] | BPTreeNode<K, V>;
5
4
  type BPTreeCondition<V> = {
6
5
  gt?: V;
7
6
  lt?: V;
@@ -14,21 +13,30 @@ type BPTreePair<K, V> = {
14
13
  key: K;
15
14
  value: V;
16
15
  };
16
+ export type BPTreeUnknownNode<K, V> = BPTreeInternalNode<K, V> | BPTreeLeafNode<K, V>;
17
17
  export interface BPTreeNode<K, V> {
18
18
  id: number;
19
- keys: BPTreeNodeKey<K, V>[];
19
+ keys: number[] | K[][];
20
20
  values: V[];
21
21
  leaf: boolean;
22
22
  parent: number;
23
23
  next: number;
24
24
  }
25
+ export interface BPTreeInternalNode<K, V> extends BPTreeNode<K, V> {
26
+ leaf: false;
27
+ keys: number[];
28
+ }
29
+ export interface BPTreeLeafNode<K, V> extends BPTreeNode<K, V> {
30
+ leaf: true;
31
+ keys: K[][];
32
+ }
25
33
  export declare class BPTree<K, V> {
26
34
  protected readonly strategy: SerializeStrategy<K, V>;
27
35
  protected readonly comparator: ValueComparator<V>;
28
36
  protected readonly search: BinarySearch<V>;
29
37
  protected readonly order: number;
30
- protected readonly nodes: Map<number, BPTreeNode<K, V>>;
31
- protected root: BPTreeNode<K, V>;
38
+ protected readonly nodes: Map<number, BPTreeUnknownNode<K, V>>;
39
+ protected root: BPTreeUnknownNode<K, V>;
32
40
  private readonly _creates;
33
41
  private readonly _updates;
34
42
  private _updatedHead;
@@ -46,8 +54,8 @@ export declare class BPTree<K, V> {
46
54
  private _emitHeadUpdates;
47
55
  private _emitCreates;
48
56
  private _emitUpdates;
49
- protected getNode(id: number): BPTreeNode<K, V>;
50
- protected leftestNode(): BPTreeNode<K, V>;
57
+ protected getNode(id: number): BPTreeUnknownNode<K, V>;
58
+ protected leftestNode(): BPTreeLeafNode<K, V>;
51
59
  private _insertableNode;
52
60
  /**
53
61
  * It returns whether there is a value in the tree.
@@ -62,11 +70,23 @@ export declare class BPTree<K, V> {
62
70
  private _onlyGtCondition;
63
71
  private _onlyLtCondition;
64
72
  private _rangeCondition;
73
+ private _getKeysFromValue;
74
+ private _getKeysFromNEValue;
75
+ private _getKeysFromRange;
76
+ private _getKeysFromGt;
77
+ private _getKeysFromLt;
65
78
  private _getPairsFromValue;
66
79
  private _getPairsFromNEValue;
67
80
  private _getPairsFromRange;
68
81
  private _getPairsFromGt;
69
82
  private _getPairsFromLt;
83
+ /**
84
+ * It searches for a key within the tree. The result is returned as an array sorted in ascending order based on the value.
85
+ * The result is key set instance, and you can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
86
+ * This method operates much faster than first searching with `where` and then retrieving only the key list.
87
+ * @param condition You can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
88
+ */
89
+ keys(condition: BPTreeCondition<V>): Set<K>;
70
90
  /**
71
91
  * It searches for a value within the tree. The result is returned as an array sorted in ascending order based on the value.
72
92
  * The result includes the key and value attributes, and you can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Store the B+tree flexibly, not only in-memory.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",