serializable-bptree 8.1.2 → 8.1.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/README.md +2 -0
- package/dist/cjs/index.cjs +1404 -1466
- package/dist/esm/index.mjs +1404 -1466
- package/dist/types/base/BPTreeTransaction.d.ts +14 -14
- package/dist/types/transaction/BPTreeAsyncTransaction.d.ts +7 -4
- package/dist/types/transaction/BPTreeSyncTransaction.d.ts +3 -3
- package/package.json +4 -4
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { TransactionEntry, TransactionResult } from 'mvcc-api';
|
|
2
2
|
import type { BPTreeCondition, BPTreeConstructorOption, BPTreeUnknownNode, Deferred, BPTreeLeafNode, BPTreeNodeKey, BPTreePair, SerializableData, BPTreeNode, BPTreeMVCC } from '../types';
|
|
3
|
-
import { LRUMap } from 'cache-entanglement';
|
|
4
3
|
import { ValueComparator } from './ValueComparator';
|
|
5
4
|
import { SerializeStrategy } from './SerializeStrategy';
|
|
6
5
|
export declare abstract class BPTreeTransaction<K, V> {
|
|
7
6
|
private readonly _cachedRegexp;
|
|
8
|
-
protected readonly nodes:
|
|
7
|
+
protected readonly nodes: Map<string, BPTreeUnknownNode<K, V>>;
|
|
9
8
|
protected readonly deletedNodeBuffer: Map<string, BPTreeUnknownNode<K, V>>;
|
|
10
9
|
protected readonly rootTx: BPTreeTransaction<K, V>;
|
|
11
10
|
protected readonly mvccRoot: BPTreeMVCC<K, V>;
|
|
@@ -15,6 +14,8 @@ export declare abstract class BPTreeTransaction<K, V> {
|
|
|
15
14
|
protected readonly option: BPTreeConstructorOption;
|
|
16
15
|
protected order: number;
|
|
17
16
|
protected rootId: string;
|
|
17
|
+
protected isInitialized: boolean;
|
|
18
|
+
protected isDestroyed: boolean;
|
|
18
19
|
protected readonly verifierMap: Record<keyof BPTreeCondition<V>, (nodeValue: V, value: V | V[]) => boolean>;
|
|
19
20
|
protected readonly verifierStartNode: Record<keyof BPTreeCondition<V>, (value: V) => Deferred<BPTreeLeafNode<K, V>>>;
|
|
20
21
|
protected readonly verifierEndNode: Record<keyof BPTreeCondition<V>, (value: V) => Deferred<BPTreeLeafNode<K, V> | null>>;
|
|
@@ -72,6 +73,7 @@ export declare abstract class BPTreeTransaction<K, V> {
|
|
|
72
73
|
* @returns Returns true if the value satisfies the condition.
|
|
73
74
|
*/
|
|
74
75
|
verify(nodeValue: V, condition: BPTreeCondition<V>): boolean;
|
|
76
|
+
protected _cloneNode<T extends BPTreeUnknownNode<K, V>>(node: T): T;
|
|
75
77
|
/**
|
|
76
78
|
* Selects the best driver key from a condition object.
|
|
77
79
|
* The driver key determines the starting point and traversal direction for queries.
|
|
@@ -81,11 +83,10 @@ export declare abstract class BPTreeTransaction<K, V> {
|
|
|
81
83
|
*/
|
|
82
84
|
protected getDriverKey(condition: BPTreeCondition<V>): keyof BPTreeCondition<V> | null;
|
|
83
85
|
protected constructor(rootTx: BPTreeTransaction<K, V> | null, mvccRoot: BPTreeMVCC<K, V>, mvcc: BPTreeMVCC<K, V>, strategy: SerializeStrategy<K, V>, comparator: ValueComparator<V>, option?: BPTreeConstructorOption);
|
|
84
|
-
private _createCachedRegexp;
|
|
85
86
|
protected abstract _createNode(leaf: boolean, keys: string[] | K[][], values: V[], parent?: string | null, next?: string | null, prev?: string | null): Deferred<BPTreeUnknownNode<K, V>>;
|
|
86
|
-
protected abstract _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K
|
|
87
|
+
protected abstract _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>): Deferred<BPTreeUnknownNode<K, V>>;
|
|
87
88
|
protected abstract _insertInParent(node: BPTreeUnknownNode<K, V>, value: V, pointer: BPTreeUnknownNode<K, V>): Deferred<void>;
|
|
88
|
-
protected abstract _insertAtLeaf(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>, value: V): Deferred<
|
|
89
|
+
protected abstract _insertAtLeaf(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>, value: V): Deferred<BPTreeUnknownNode<K, V>>;
|
|
89
90
|
protected abstract getNode(id: string): Deferred<BPTreeUnknownNode<K, V>>;
|
|
90
91
|
protected abstract insertableNode(value: V): Deferred<BPTreeLeafNode<K, V>>;
|
|
91
92
|
protected abstract insertableNodeByPrimary(value: V): Deferred<BPTreeLeafNode<K, V>>;
|
|
@@ -94,6 +95,11 @@ export declare abstract class BPTreeTransaction<K, V> {
|
|
|
94
95
|
protected abstract insertableEndNode(value: V, direction: 1 | -1): Deferred<BPTreeLeafNode<K, V> | null>;
|
|
95
96
|
protected abstract leftestNode(): Deferred<BPTreeLeafNode<K, V>>;
|
|
96
97
|
protected abstract rightestNode(): Deferred<BPTreeLeafNode<K, V>>;
|
|
98
|
+
/**
|
|
99
|
+
* After creating a tree instance, it must be called.
|
|
100
|
+
* This method is used to initialize the stored tree and recover data.
|
|
101
|
+
* If it is not called, the tree will not function.
|
|
102
|
+
*/
|
|
97
103
|
/**
|
|
98
104
|
* After creating a tree instance, it must be called.
|
|
99
105
|
* This method is used to initialize the stored tree and recover data.
|
|
@@ -142,14 +148,6 @@ export declare abstract class BPTreeTransaction<K, V> {
|
|
|
142
148
|
* @param data User-defined data to be stored in the head of the tree.
|
|
143
149
|
*/
|
|
144
150
|
abstract setHeadData(data: SerializableData): Deferred<void>;
|
|
145
|
-
/**
|
|
146
|
-
* This method deletes nodes cached in-memory and caches new nodes from the stored nodes.
|
|
147
|
-
* Typically, there's no need to use this method, but it can be used to synchronize data in scenarios where the remote storage and the client are in a 1:n relationship.
|
|
148
|
-
* If you do not specify an ID, all nodes will be updated.
|
|
149
|
-
* @param id The ID of the node to update.
|
|
150
|
-
* @returns The return value is the total number of nodes updated.
|
|
151
|
-
*/
|
|
152
|
-
abstract forceUpdate(id?: string): Deferred<number>;
|
|
153
151
|
/**
|
|
154
152
|
* Returns the user-defined data stored in the head of the tree.
|
|
155
153
|
*/
|
|
@@ -162,7 +160,7 @@ export declare abstract class BPTreeTransaction<K, V> {
|
|
|
162
160
|
/**
|
|
163
161
|
* Rolls back the transaction and returns the result.
|
|
164
162
|
*/
|
|
165
|
-
abstract rollback(): TransactionResult<string, BPTreeNode<K, V
|
|
163
|
+
abstract rollback(): Deferred<TransactionResult<string, BPTreeNode<K, V>>>;
|
|
166
164
|
protected ensureValues(v: V | V[]): V[];
|
|
167
165
|
protected lowestValue(v: V[]): V;
|
|
168
166
|
protected highestValue(v: V[]): V;
|
|
@@ -177,11 +175,13 @@ export declare abstract class BPTreeTransaction<K, V> {
|
|
|
177
175
|
updated: TransactionEntry<string, BPTreeNode<K, V>>[];
|
|
178
176
|
deleted: TransactionEntry<string, BPTreeNode<K, V>>[];
|
|
179
177
|
};
|
|
178
|
+
protected _clearCache(): void;
|
|
180
179
|
/**
|
|
181
180
|
* Clears all cached nodes.
|
|
182
181
|
* This method is useful for freeing up memory when the tree is no longer needed.
|
|
183
182
|
*/
|
|
184
183
|
clear(): void;
|
|
184
|
+
protected _clearInternal(): void;
|
|
185
185
|
protected _binarySearchValues(values: V[], target: V, usePrimary?: boolean, upperBound?: boolean): {
|
|
186
186
|
index: number;
|
|
187
187
|
found: boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TransactionResult } from 'mvcc-api';
|
|
2
2
|
import type { AsyncBPTreeMVCC, BPTreeCondition, BPTreeConstructorOption, BPTreeLeafNode, BPTreeNode, BPTreeNodeKey, BPTreeOrder, BPTreePair, BPTreeUnknownNode, SerializableData, SerializeStrategyHead } from '../types';
|
|
3
|
+
import { Ryoiki } from 'ryoiki';
|
|
3
4
|
import { BPTreeTransaction } from '../base/BPTreeTransaction';
|
|
4
5
|
import { SerializeStrategyAsync } from '../SerializeStrategyAsync';
|
|
5
6
|
import { ValueComparator } from '../base/ValueComparator';
|
|
@@ -10,7 +11,9 @@ export declare class BPTreeAsyncTransaction<K, V> extends BPTreeTransaction<K, V
|
|
|
10
11
|
protected readonly strategy: SerializeStrategyAsync<K, V>;
|
|
11
12
|
protected readonly comparator: ValueComparator<V>;
|
|
12
13
|
protected readonly option: BPTreeConstructorOption;
|
|
14
|
+
protected readonly lock: Ryoiki;
|
|
13
15
|
constructor(rootTx: BPTreeAsyncTransaction<K, V> | null, mvccRoot: AsyncBPTreeMVCC<K, V>, mvcc: AsyncBPTreeMVCC<K, V>, strategy: SerializeStrategyAsync<K, V>, comparator: ValueComparator<V>, option?: BPTreeConstructorOption);
|
|
16
|
+
protected writeLock<T>(id: number, fn: () => Promise<T>): Promise<T>;
|
|
14
17
|
protected getNode(id: string): Promise<BPTreeUnknownNode<K, V>>;
|
|
15
18
|
/**
|
|
16
19
|
* Create a new node with a unique ID.
|
|
@@ -20,7 +23,7 @@ export declare class BPTreeAsyncTransaction<K, V> extends BPTreeTransaction<K, V
|
|
|
20
23
|
protected _deleteNode(node: BPTreeUnknownNode<K, V>): Promise<void>;
|
|
21
24
|
protected _readHead(): Promise<SerializeStrategyHead | null>;
|
|
22
25
|
protected _writeHead(head: SerializeStrategyHead): Promise<void>;
|
|
23
|
-
protected _insertAtLeaf(node:
|
|
26
|
+
protected _insertAtLeaf(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>, value: V): Promise<BPTreeUnknownNode<K, V>>;
|
|
24
27
|
protected _insertInParent(node: BPTreeUnknownNode<K, V>, value: V, pointer: BPTreeUnknownNode<K, V>): Promise<void>;
|
|
25
28
|
protected insertableNode(value: V): Promise<BPTreeLeafNode<K, V>>;
|
|
26
29
|
protected insertableNodeByPrimary(value: V): Promise<BPTreeLeafNode<K, V>>;
|
|
@@ -31,18 +34,18 @@ export declare class BPTreeAsyncTransaction<K, V> extends BPTreeTransaction<K, V
|
|
|
31
34
|
protected rightestNode(): Promise<BPTreeLeafNode<K, V>>;
|
|
32
35
|
protected getPairsGenerator(value: V, startNode: BPTreeLeafNode<K, V>, endNode: BPTreeLeafNode<K, V> | null, comparator: (nodeValue: V, value: V) => boolean, direction: 1 | -1, earlyTerminate: boolean): AsyncGenerator<[K, V]>;
|
|
33
36
|
init(): Promise<void>;
|
|
37
|
+
protected _initInternal(): Promise<void>;
|
|
34
38
|
exists(key: K, value: V): Promise<boolean>;
|
|
35
|
-
forceUpdate(id?: string): Promise<number>;
|
|
36
39
|
get(key: K): Promise<V | undefined>;
|
|
37
40
|
keysStream(condition: BPTreeCondition<V>, filterValues?: Set<K>, limit?: number, order?: BPTreeOrder): AsyncGenerator<K>;
|
|
38
41
|
whereStream(condition: BPTreeCondition<V>, limit?: number, order?: BPTreeOrder): AsyncGenerator<[K, V]>;
|
|
39
42
|
keys(condition: BPTreeCondition<V>, filterValues?: Set<K>, order?: BPTreeOrder): Promise<Set<K>>;
|
|
40
43
|
where(condition: BPTreeCondition<V>, order?: BPTreeOrder): Promise<BPTreePair<K, V>>;
|
|
41
44
|
insert(key: K, value: V): Promise<void>;
|
|
42
|
-
protected _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>): Promise<
|
|
45
|
+
protected _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>): Promise<BPTreeUnknownNode<K, V>>;
|
|
43
46
|
delete(key: K, value: V): Promise<void>;
|
|
44
47
|
getHeadData(): Promise<SerializableData>;
|
|
45
48
|
setHeadData(data: SerializableData): Promise<void>;
|
|
46
49
|
commit(label?: string): Promise<TransactionResult<string, BPTreeNode<K, V>>>;
|
|
47
|
-
rollback(): TransactionResult<string, BPTreeNode<K, V
|
|
50
|
+
rollback(): Promise<TransactionResult<string, BPTreeNode<K, V>>>;
|
|
48
51
|
}
|
|
@@ -20,7 +20,7 @@ export declare class BPTreeSyncTransaction<K, V> extends BPTreeTransaction<K, V>
|
|
|
20
20
|
protected _deleteNode(node: BPTreeUnknownNode<K, V>): void;
|
|
21
21
|
protected _readHead(): SerializeStrategyHead | null;
|
|
22
22
|
protected _writeHead(head: SerializeStrategyHead): void;
|
|
23
|
-
protected _insertAtLeaf(node:
|
|
23
|
+
protected _insertAtLeaf(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>, value: V): BPTreeUnknownNode<K, V>;
|
|
24
24
|
protected _insertInParent(node: BPTreeUnknownNode<K, V>, value: V, pointer: BPTreeUnknownNode<K, V>): void;
|
|
25
25
|
protected insertableNode(value: V): BPTreeLeafNode<K, V>;
|
|
26
26
|
protected insertableNodeByPrimary(value: V): BPTreeLeafNode<K, V>;
|
|
@@ -31,15 +31,15 @@ export declare class BPTreeSyncTransaction<K, V> extends BPTreeTransaction<K, V>
|
|
|
31
31
|
protected rightestNode(): BPTreeLeafNode<K, V>;
|
|
32
32
|
protected getPairsGenerator(value: V, startNode: BPTreeLeafNode<K, V>, endNode: BPTreeLeafNode<K, V> | null, comparator: (nodeValue: V, value: V) => boolean, direction: 1 | -1, earlyTerminate: boolean): Generator<[K, V]>;
|
|
33
33
|
init(): void;
|
|
34
|
+
protected _initInternal(): void;
|
|
34
35
|
exists(key: K, value: V): boolean;
|
|
35
|
-
forceUpdate(id?: string): number;
|
|
36
36
|
get(key: K): V | undefined;
|
|
37
37
|
keysStream(condition: BPTreeCondition<V>, filterValues?: Set<K>, limit?: number, order?: BPTreeOrder): Generator<K>;
|
|
38
38
|
whereStream(condition: BPTreeCondition<V>, limit?: number, order?: BPTreeOrder): Generator<[K, V]>;
|
|
39
39
|
keys(condition: BPTreeCondition<V>, filterValues?: Set<K>, order?: BPTreeOrder): Set<K>;
|
|
40
40
|
where(condition: BPTreeCondition<V>, order?: BPTreeOrder): BPTreePair<K, V>;
|
|
41
41
|
insert(key: K, value: V): void;
|
|
42
|
-
protected _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>):
|
|
42
|
+
protected _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>): BPTreeUnknownNode<K, V>;
|
|
43
43
|
delete(key: K, value: V): void;
|
|
44
44
|
getHeadData(): SerializableData;
|
|
45
45
|
setHeadData(data: SerializableData): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "serializable-bptree",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.4",
|
|
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",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
19
|
"test": "jest --runInBand",
|
|
20
|
-
"build": "node build/index.js && tsc"
|
|
20
|
+
"build": "node build/index.js && tsc",
|
|
21
|
+
"benchmark": "npx tsx benchmark/index.ts"
|
|
21
22
|
},
|
|
22
23
|
"author": "izure <admin@izure.org>",
|
|
23
24
|
"keywords": [
|
|
@@ -43,8 +44,7 @@
|
|
|
43
44
|
"typescript": "^5.9.3"
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"
|
|
47
|
-
"mvcc-api": "^1.2.11",
|
|
47
|
+
"mvcc-api": "^1.3.2",
|
|
48
48
|
"ryoiki": "^1.2.0"
|
|
49
49
|
}
|
|
50
50
|
}
|