serializable-bptree 1.0.4 → 2.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 +22 -18
- package/dist/cjs/index.js +166 -256
- package/dist/esm/index.js +166 -256
- package/dist/typings/BPTree.d.ts +42 -26
- package/dist/typings/SerializeStrategy.d.ts +2 -0
- package/dist/typings/utils/types.d.ts +5 -0
- package/package.json +2 -1
package/dist/typings/BPTree.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
+
import type { Json } from './utils/types';
|
|
1
2
|
import { BinarySearch } from './utils/BinarySearch';
|
|
2
3
|
import { ValueComparator } from './ValueComparator';
|
|
3
4
|
import { SerializeStrategy } from './SerializeStrategy';
|
|
4
|
-
type BPTreeCondition<V> = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
type BPTreeCondition<V> = Partial<{
|
|
6
|
+
/** Searches for pairs greater than the given value. */
|
|
7
|
+
gt: V;
|
|
8
|
+
/** Searches for pairs less than the given value. */
|
|
9
|
+
lt: V;
|
|
10
|
+
/** Searches for pairs greater than or equal to the given value. */
|
|
11
|
+
gte: V;
|
|
12
|
+
/** Searches for pairs less than or equal to the given value. */
|
|
13
|
+
lte: V;
|
|
14
|
+
/** "Searches for pairs equal to the given value. */
|
|
8
15
|
equal: V;
|
|
9
|
-
|
|
16
|
+
/** Searches for pairs not equal to the given value. */
|
|
10
17
|
notEqual: V;
|
|
11
|
-
|
|
18
|
+
/** Searches for values matching the given pattern. '%' matches zero or more characters, and '_' matches exactly one character. */
|
|
19
|
+
like: V;
|
|
20
|
+
}>;
|
|
12
21
|
type BPTreePair<K, V> = {
|
|
13
22
|
key: K;
|
|
14
23
|
value: V;
|
|
@@ -21,6 +30,7 @@ export interface BPTreeNode<K, V> {
|
|
|
21
30
|
leaf: boolean;
|
|
22
31
|
parent: number;
|
|
23
32
|
next: number;
|
|
33
|
+
prev: number;
|
|
24
34
|
}
|
|
25
35
|
export interface BPTreeInternalNode<K, V> extends BPTreeNode<K, V> {
|
|
26
36
|
leaf: false;
|
|
@@ -36,10 +46,15 @@ export declare class BPTree<K, V> {
|
|
|
36
46
|
protected readonly search: BinarySearch<V>;
|
|
37
47
|
protected readonly order: number;
|
|
38
48
|
protected readonly nodes: Map<number, BPTreeUnknownNode<K, V>>;
|
|
49
|
+
protected data: Record<string, Json>;
|
|
39
50
|
protected root: BPTreeUnknownNode<K, V>;
|
|
40
51
|
private readonly _creates;
|
|
41
52
|
private readonly _updates;
|
|
42
53
|
private _updatedHead;
|
|
54
|
+
private readonly _verifierMap;
|
|
55
|
+
private readonly _verifierStartNode;
|
|
56
|
+
private readonly _verifierDirection;
|
|
57
|
+
private readonly _verifierFullSearch;
|
|
43
58
|
private _createNodeId;
|
|
44
59
|
private _createNode;
|
|
45
60
|
/**
|
|
@@ -56,7 +71,7 @@ export declare class BPTree<K, V> {
|
|
|
56
71
|
private _emitUpdates;
|
|
57
72
|
protected getNode(id: number): BPTreeUnknownNode<K, V>;
|
|
58
73
|
protected leftestNode(): BPTreeLeafNode<K, V>;
|
|
59
|
-
|
|
74
|
+
protected insertableNode(value: V): BPTreeLeafNode<K, V>;
|
|
60
75
|
/**
|
|
61
76
|
* It returns whether there is a value in the tree.
|
|
62
77
|
* @param key The key value to search for.
|
|
@@ -65,32 +80,20 @@ export declare class BPTree<K, V> {
|
|
|
65
80
|
exists(key: K, value: V): boolean;
|
|
66
81
|
private _insertAtLeaf;
|
|
67
82
|
private _insertInParent;
|
|
68
|
-
private
|
|
69
|
-
private
|
|
70
|
-
|
|
71
|
-
private _onlyLtCondition;
|
|
72
|
-
private _rangeCondition;
|
|
73
|
-
private _getKeysFromValue;
|
|
74
|
-
private _getKeysFromNEValue;
|
|
75
|
-
private _getKeysFromRange;
|
|
76
|
-
private _getKeysFromGt;
|
|
77
|
-
private _getKeysFromLt;
|
|
78
|
-
private _getPairsFromValue;
|
|
79
|
-
private _getPairsFromNEValue;
|
|
80
|
-
private _getPairsFromRange;
|
|
81
|
-
private _getPairsFromGt;
|
|
82
|
-
private _getPairsFromLt;
|
|
83
|
+
private _getPairsRightToLeft;
|
|
84
|
+
private _getPairsLeftToRight;
|
|
85
|
+
protected getPairs(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean, direction: -1 | 1): BPTreePair<K, V>[];
|
|
83
86
|
/**
|
|
84
87
|
* 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.
|
|
88
|
+
* The result is key set instance, and you can use the `gt`, `lt`, `gte`, `lte`, `equal`, `notEqual`, `like` condition statements.
|
|
86
89
|
* 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.
|
|
90
|
+
* @param condition You can use the `gt`, `lt`, `gte`, `lte`, `equal`, `notEqual`, `like` condition statements.
|
|
88
91
|
*/
|
|
89
92
|
keys(condition: BPTreeCondition<V>): Set<K>;
|
|
90
93
|
/**
|
|
91
94
|
* It searches for a value within the tree. The result is returned as an array sorted in ascending order based on the value.
|
|
92
|
-
* The result includes the key and value attributes, and you can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
|
|
93
|
-
* @param condition You can use the `gt`, `lt`, `equal`, `notEqual` condition statements.
|
|
95
|
+
* The result includes the key and value attributes, and you can use the `gt`, `lt`, `gte`, `lte`, `equal`, `notEqual`, `like` condition statements.
|
|
96
|
+
* @param condition You can use the `gt`, `lt`, `gte`, `lte`, `equal`, `notEqual`, `like` condition statements.
|
|
94
97
|
*/
|
|
95
98
|
where(condition: BPTreeCondition<V>): BPTreePair<K, V>[];
|
|
96
99
|
/**
|
|
@@ -107,5 +110,18 @@ export declare class BPTree<K, V> {
|
|
|
107
110
|
*/
|
|
108
111
|
delete(key: K, value: V): void;
|
|
109
112
|
private _deleteEntry;
|
|
113
|
+
/**
|
|
114
|
+
* Returns the user-defined data stored in the head of the tree.
|
|
115
|
+
* This value can be set using the `setHeadData` method. If no data has been previously inserted, the default value is returned, and the default value is `{}`.
|
|
116
|
+
* @returns User-defined data stored in the head of the tree.
|
|
117
|
+
*/
|
|
118
|
+
getHeadData(): Record<string, Json>;
|
|
119
|
+
/**
|
|
120
|
+
* Inserts user-defined data into the head of the tree.
|
|
121
|
+
* This feature is useful when you need to store separate, non-volatile information in the tree.
|
|
122
|
+
* For example, you can store information such as the last update time and the number of insertions.
|
|
123
|
+
* @param data User-defined data to be stored in the head of the tree.
|
|
124
|
+
*/
|
|
125
|
+
setHeadData(data: Record<string, Json>): void;
|
|
110
126
|
}
|
|
111
127
|
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { BPTreeNode } from './BPTree';
|
|
2
|
+
import type { Json } from './utils/types';
|
|
2
3
|
export interface SerializeStrategyHead {
|
|
3
4
|
root: number;
|
|
4
5
|
order: number;
|
|
6
|
+
data: Record<string, Json>;
|
|
5
7
|
}
|
|
6
8
|
export declare abstract class SerializeStrategy<K, V> {
|
|
7
9
|
readonly order: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "serializable-bptree",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"serializable-bptree",
|
|
18
18
|
"b-plus-tree",
|
|
19
19
|
"serialize",
|
|
20
|
+
"serialization",
|
|
20
21
|
"store",
|
|
21
22
|
"btree",
|
|
22
23
|
"bptree",
|