serializable-bptree 1.0.3 → 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 +140 -0
- package/dist/esm/index.js +140 -0
- package/dist/typings/BPTree.d.ts +12 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -321,6 +321,124 @@ var BPTree = class {
|
|
|
321
321
|
_rangeCondition(condition) {
|
|
322
322
|
return Object.prototype.hasOwnProperty.call(condition, "gt") && Object.prototype.hasOwnProperty.call(condition, "lt");
|
|
323
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
|
+
}
|
|
324
442
|
_getPairsFromValue(value) {
|
|
325
443
|
const node = this._insertableNode(value);
|
|
326
444
|
const [start, end] = this.search.range(node.values, value);
|
|
@@ -439,6 +557,28 @@ var BPTree = class {
|
|
|
439
557
|
}
|
|
440
558
|
return pairs;
|
|
441
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
|
+
}
|
|
442
582
|
/**
|
|
443
583
|
* It searches for a value within the tree. The result is returned as an array sorted in ascending order based on the value.
|
|
444
584
|
* The result includes the key and value attributes, and you can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
|
package/dist/esm/index.js
CHANGED
|
@@ -290,6 +290,124 @@ var BPTree = class {
|
|
|
290
290
|
_rangeCondition(condition) {
|
|
291
291
|
return Object.prototype.hasOwnProperty.call(condition, "gt") && Object.prototype.hasOwnProperty.call(condition, "lt");
|
|
292
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
|
+
}
|
|
293
411
|
_getPairsFromValue(value) {
|
|
294
412
|
const node = this._insertableNode(value);
|
|
295
413
|
const [start, end] = this.search.range(node.values, value);
|
|
@@ -408,6 +526,28 @@ var BPTree = class {
|
|
|
408
526
|
}
|
|
409
527
|
return pairs;
|
|
410
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
|
+
}
|
|
411
551
|
/**
|
|
412
552
|
* It searches for a value within the tree. The result is returned as an array sorted in ascending order based on the value.
|
|
413
553
|
* The result includes the key and value attributes, and you can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
|
package/dist/typings/BPTree.d.ts
CHANGED
|
@@ -70,11 +70,23 @@ export declare class BPTree<K, V> {
|
|
|
70
70
|
private _onlyGtCondition;
|
|
71
71
|
private _onlyLtCondition;
|
|
72
72
|
private _rangeCondition;
|
|
73
|
+
private _getKeysFromValue;
|
|
74
|
+
private _getKeysFromNEValue;
|
|
75
|
+
private _getKeysFromRange;
|
|
76
|
+
private _getKeysFromGt;
|
|
77
|
+
private _getKeysFromLt;
|
|
73
78
|
private _getPairsFromValue;
|
|
74
79
|
private _getPairsFromNEValue;
|
|
75
80
|
private _getPairsFromRange;
|
|
76
81
|
private _getPairsFromGt;
|
|
77
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>;
|
|
78
90
|
/**
|
|
79
91
|
* It searches for a value within the tree. The result is returned as an array sorted in ascending order based on the value.
|
|
80
92
|
* The result includes the key and value attributes, and you can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
|