serializable-bptree 4.0.0 → 4.0.1
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.cjs
CHANGED
|
@@ -426,6 +426,39 @@ var CacheBranchSync = class _CacheBranchSync extends CacheBranch {
|
|
|
426
426
|
}
|
|
427
427
|
};
|
|
428
428
|
|
|
429
|
+
// src/utils/InvertedWeakMap.ts
|
|
430
|
+
var InvertedWeakMap = class {
|
|
431
|
+
_map;
|
|
432
|
+
_registry;
|
|
433
|
+
constructor() {
|
|
434
|
+
this._map = /* @__PURE__ */ new Map();
|
|
435
|
+
this._registry = new FinalizationRegistry((key) => this._map.delete(key));
|
|
436
|
+
}
|
|
437
|
+
clear() {
|
|
438
|
+
return this._map.clear();
|
|
439
|
+
}
|
|
440
|
+
delete(key) {
|
|
441
|
+
return this._map.delete(key);
|
|
442
|
+
}
|
|
443
|
+
get(key) {
|
|
444
|
+
return this._map.get(key)?.deref();
|
|
445
|
+
}
|
|
446
|
+
has(key) {
|
|
447
|
+
return this._map.has(key) && this.get(key) !== void 0;
|
|
448
|
+
}
|
|
449
|
+
set(key, value) {
|
|
450
|
+
this._map.set(key, new WeakRef(value));
|
|
451
|
+
this._registry.register(value, key);
|
|
452
|
+
return this;
|
|
453
|
+
}
|
|
454
|
+
get size() {
|
|
455
|
+
return this._map.size;
|
|
456
|
+
}
|
|
457
|
+
keys() {
|
|
458
|
+
return this._map.keys();
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
|
|
429
462
|
// src/base/BPTree.ts
|
|
430
463
|
var BPTree = class {
|
|
431
464
|
_cachedRegexp;
|
|
@@ -486,7 +519,7 @@ var BPTree = class {
|
|
|
486
519
|
this._nodeCreateBuffer = /* @__PURE__ */ new Map();
|
|
487
520
|
this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
|
|
488
521
|
this._nodeDeleteBuffer = /* @__PURE__ */ new Map();
|
|
489
|
-
this.nodes =
|
|
522
|
+
this.nodes = new InvertedWeakMap();
|
|
490
523
|
this.strategy = strategy;
|
|
491
524
|
this.comparator = comparator;
|
|
492
525
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -392,6 +392,39 @@ var CacheBranchSync = class _CacheBranchSync extends CacheBranch {
|
|
|
392
392
|
}
|
|
393
393
|
};
|
|
394
394
|
|
|
395
|
+
// src/utils/InvertedWeakMap.ts
|
|
396
|
+
var InvertedWeakMap = class {
|
|
397
|
+
_map;
|
|
398
|
+
_registry;
|
|
399
|
+
constructor() {
|
|
400
|
+
this._map = /* @__PURE__ */ new Map();
|
|
401
|
+
this._registry = new FinalizationRegistry((key) => this._map.delete(key));
|
|
402
|
+
}
|
|
403
|
+
clear() {
|
|
404
|
+
return this._map.clear();
|
|
405
|
+
}
|
|
406
|
+
delete(key) {
|
|
407
|
+
return this._map.delete(key);
|
|
408
|
+
}
|
|
409
|
+
get(key) {
|
|
410
|
+
return this._map.get(key)?.deref();
|
|
411
|
+
}
|
|
412
|
+
has(key) {
|
|
413
|
+
return this._map.has(key) && this.get(key) !== void 0;
|
|
414
|
+
}
|
|
415
|
+
set(key, value) {
|
|
416
|
+
this._map.set(key, new WeakRef(value));
|
|
417
|
+
this._registry.register(value, key);
|
|
418
|
+
return this;
|
|
419
|
+
}
|
|
420
|
+
get size() {
|
|
421
|
+
return this._map.size;
|
|
422
|
+
}
|
|
423
|
+
keys() {
|
|
424
|
+
return this._map.keys();
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
|
|
395
428
|
// src/base/BPTree.ts
|
|
396
429
|
var BPTree = class {
|
|
397
430
|
_cachedRegexp;
|
|
@@ -452,7 +485,7 @@ var BPTree = class {
|
|
|
452
485
|
this._nodeCreateBuffer = /* @__PURE__ */ new Map();
|
|
453
486
|
this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
|
|
454
487
|
this._nodeDeleteBuffer = /* @__PURE__ */ new Map();
|
|
455
|
-
this.nodes =
|
|
488
|
+
this.nodes = new InvertedWeakMap();
|
|
456
489
|
this.strategy = strategy;
|
|
457
490
|
this.comparator = comparator;
|
|
458
491
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ValueComparator } from './ValueComparator';
|
|
2
2
|
import { SerializableData, SerializeStrategy } from './SerializeStrategy';
|
|
3
|
+
import { InvertedWeakMap } from '../utils/InvertedWeakMap';
|
|
3
4
|
type Sync<T> = T;
|
|
4
5
|
type Async<T> = Promise<T>;
|
|
5
6
|
type Deferred<T> = Sync<T> | Async<T>;
|
|
@@ -46,7 +47,7 @@ export declare abstract class BPTree<K, V> {
|
|
|
46
47
|
private readonly _cachedRegexp;
|
|
47
48
|
protected readonly strategy: SerializeStrategy<K, V>;
|
|
48
49
|
protected readonly comparator: ValueComparator<V>;
|
|
49
|
-
protected readonly nodes:
|
|
50
|
+
protected readonly nodes: InvertedWeakMap<string, BPTreeUnknownNode<K, V>>;
|
|
50
51
|
protected order: number;
|
|
51
52
|
protected root: BPTreeUnknownNode<K, V>;
|
|
52
53
|
protected readonly _nodeCreateBuffer: Map<string, BPTreeUnknownNode<K, V>>;
|
|
@@ -14,7 +14,6 @@ export declare abstract class SerializeStrategy<K, V> {
|
|
|
14
14
|
* The rule for generating node IDs is set.
|
|
15
15
|
* When a new node is created within the tree, the value returned by this method becomes the node's ID.
|
|
16
16
|
*
|
|
17
|
-
* **WARNING!** The return value should never be `null`.
|
|
18
17
|
* @param isLeaf This is a flag that indicates whether the node is a leaf node or not.
|
|
19
18
|
*/
|
|
20
19
|
abstract id(isLeaf: boolean): string | Promise<string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class InvertedWeakMap<K extends string | number | symbol, V extends WeakKey> {
|
|
2
|
+
private readonly _map;
|
|
3
|
+
private readonly _registry;
|
|
4
|
+
constructor();
|
|
5
|
+
clear(): void;
|
|
6
|
+
delete(key: K): boolean;
|
|
7
|
+
get(key: K): V | undefined;
|
|
8
|
+
has(key: K): boolean;
|
|
9
|
+
set(key: K, value: V): this;
|
|
10
|
+
get size(): number;
|
|
11
|
+
keys(): IterableIterator<K>;
|
|
12
|
+
}
|