serializable-bptree 2.0.0 → 3.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.
@@ -0,0 +1,45 @@
1
+ import type { Json } from './utils/types';
2
+ import { BPTree, BPTreeLeafNode, BPTreePair, BPTreeNodeKey, BPTreeUnknownNode } from './base/BPTree';
3
+ import { SerializeStrategyAsync } from './SerializeStrategyAsync';
4
+ import { ValueComparator } from './ValueComparator';
5
+ export declare class BPTreeAsync<K, V> extends BPTree<K, V> {
6
+ protected readonly strategy: SerializeStrategyAsync<K, V>;
7
+ constructor(strategy: SerializeStrategyAsync<K, V>, comparator: ValueComparator<V>);
8
+ protected _getPairsRightToLeft(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean): Promise<BPTreePair<K, V>[]>;
9
+ protected _getPairsLeftToRight(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean): Promise<BPTreePair<K, V>[]>;
10
+ protected getPairs(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean, direction: 1 | -1): Promise<BPTreePair<K, V>[]>;
11
+ protected _createNodeId(): Promise<number>;
12
+ protected _createNode(keys: number[] | K[][], values: V[], leaf?: boolean, parent?: number, next?: number, prev?: number): Promise<BPTreeUnknownNode<K, V>>;
13
+ protected _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>, value: V): Promise<void>;
14
+ protected _insertInParent(node: BPTreeUnknownNode<K, V>, value: V, pointer: BPTreeUnknownNode<K, V>): Promise<void>;
15
+ init(): Promise<void>;
16
+ protected getNode(id: number): Promise<BPTreeUnknownNode<K, V>>;
17
+ protected insertableNode(value: V): Promise<BPTreeLeafNode<K, V>>;
18
+ protected leftestNode(): Promise<BPTreeLeafNode<K, V>>;
19
+ protected commitHeadBuffer(): Promise<void>;
20
+ protected commitNodeCreateBuffer(): Promise<void>;
21
+ protected commitNodeUpdateBuffer(): Promise<void>;
22
+ keys(condition: Partial<{
23
+ gt: V;
24
+ lt: V;
25
+ gte: V;
26
+ lte: V;
27
+ equal: V;
28
+ notEqual: V;
29
+ like: V;
30
+ }>): Promise<Set<K>>;
31
+ where(condition: Partial<{
32
+ gt: V;
33
+ lt: V;
34
+ gte: V;
35
+ lte: V;
36
+ equal: V;
37
+ notEqual: V;
38
+ like: V;
39
+ }>): Promise<BPTreePair<K, V>[]>;
40
+ insert(key: K, value: V): Promise<void>;
41
+ delete(key: K, value: V): Promise<void>;
42
+ exists(key: K, value: V): Promise<boolean>;
43
+ setHeadData(data: Record<string, Json>): Promise<void>;
44
+ forceUpdate(nodeId?: number | null): Promise<number>;
45
+ }
@@ -0,0 +1,46 @@
1
+ import type { Json } from './utils/types';
2
+ import { BPTree, BPTreeLeafNode, BPTreePair, BPTreeNodeKey, BPTreeUnknownNode } from './base/BPTree';
3
+ import { SerializeStrategySync } from './SerializeStrategySync';
4
+ import { ValueComparator } from './ValueComparator';
5
+ export declare class BPTreeSync<K, V> extends BPTree<K, V> {
6
+ protected readonly strategy: SerializeStrategySync<K, V>;
7
+ constructor(strategy: SerializeStrategySync<K, V>, comparator: ValueComparator<V>);
8
+ protected _getPairsRightToLeft(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean): BPTreePair<K, V>[];
9
+ protected _getPairsLeftToRight(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean): BPTreePair<K, V>[];
10
+ protected getPairs(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean, direction: 1 | -1): BPTreePair<K, V>[];
11
+ protected _createNodeId(): number;
12
+ protected _createNode(keys: number[] | K[][], values: V[], leaf?: boolean, parent?: number, next?: number, prev?: number): BPTreeUnknownNode<K, V>;
13
+ protected _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>, value: V): void;
14
+ protected _insertAtLeaf(node: BPTreeLeafNode<K, V>, key: K, value: V): void;
15
+ protected _insertInParent(node: BPTreeUnknownNode<K, V>, value: V, pointer: BPTreeUnknownNode<K, V>): void;
16
+ init(): void;
17
+ protected getNode(id: number): BPTreeUnknownNode<K, V>;
18
+ protected insertableNode(value: V): BPTreeLeafNode<K, V>;
19
+ protected leftestNode(): BPTreeLeafNode<K, V>;
20
+ protected commitHeadBuffer(): void;
21
+ protected commitNodeCreateBuffer(): void;
22
+ protected commitNodeUpdateBuffer(): void;
23
+ keys(condition: Partial<{
24
+ gt: V;
25
+ lt: V;
26
+ gte: V;
27
+ lte: V;
28
+ equal: V;
29
+ notEqual: V;
30
+ like: V;
31
+ }>): Set<K>;
32
+ where(condition: Partial<{
33
+ gt: V;
34
+ lt: V;
35
+ gte: V;
36
+ lte: V;
37
+ equal: V;
38
+ notEqual: V;
39
+ like: V;
40
+ }>): BPTreePair<K, V>[];
41
+ insert(key: K, value: V): void;
42
+ delete(key: K, value: V): void;
43
+ exists(key: K, value: V): boolean;
44
+ setHeadData(data: Record<string, Json>): void;
45
+ forceUpdate(nodeId?: number | null): number;
46
+ }
@@ -0,0 +1,21 @@
1
+ import { BPTreeNode } from './base/BPTree';
2
+ import { SerializeStrategy, SerializeStrategyHead } from './base/SerializeStrategy';
3
+ export declare abstract class SerializeStrategyAsync<K, V> extends SerializeStrategy<K, V> {
4
+ abstract id(): Promise<number>;
5
+ abstract read(id: number): Promise<BPTreeNode<K, V>>;
6
+ abstract write(id: number, node: BPTreeNode<K, V>): Promise<void>;
7
+ abstract readHead(): Promise<SerializeStrategyHead | null>;
8
+ abstract writeHead(head: SerializeStrategyHead): Promise<void>;
9
+ }
10
+ export declare class InMemoryStoreStrategyAsync<K, V> extends SerializeStrategyAsync<K, V> {
11
+ protected readonly data: {
12
+ head: SerializeStrategyHead | null;
13
+ node: Record<number, BPTreeNode<K, V>>;
14
+ };
15
+ constructor(order: number);
16
+ id(): Promise<number>;
17
+ read(id: number): Promise<BPTreeNode<K, V>>;
18
+ write(id: number, node: BPTreeNode<K, V>): Promise<void>;
19
+ readHead(): Promise<SerializeStrategyHead | null>;
20
+ writeHead(head: SerializeStrategyHead): Promise<void>;
21
+ }
@@ -0,0 +1,21 @@
1
+ import { BPTreeNode } from './base/BPTree';
2
+ import { SerializeStrategy, SerializeStrategyHead } from './base/SerializeStrategy';
3
+ export declare abstract class SerializeStrategySync<K, V> extends SerializeStrategy<K, V> {
4
+ abstract id(): number;
5
+ abstract read(id: number): BPTreeNode<K, V>;
6
+ abstract write(id: number, node: BPTreeNode<K, V>): void;
7
+ abstract readHead(): SerializeStrategyHead | null;
8
+ abstract writeHead(head: SerializeStrategyHead): void;
9
+ }
10
+ export declare class InMemoryStoreStrategySync<K, V> extends SerializeStrategySync<K, V> {
11
+ protected readonly data: {
12
+ head: SerializeStrategyHead | null;
13
+ node: Record<number, BPTreeNode<K, V>>;
14
+ };
15
+ constructor(order: number);
16
+ id(): number;
17
+ read(id: number): BPTreeNode<K, V>;
18
+ write(id: number, node: BPTreeNode<K, V>): void;
19
+ readHead(): SerializeStrategyHead | null;
20
+ writeHead(head: SerializeStrategyHead): void;
21
+ }
@@ -0,0 +1,138 @@
1
+ import type { Json } from '../utils/types';
2
+ import { ValueComparator } from '../ValueComparator';
3
+ import { SerializeStrategy, SerializeStrategyHead } from './SerializeStrategy';
4
+ type Sync<T> = T;
5
+ type Async<T> = Promise<T>;
6
+ type Deferred<T> = Sync<T> | Async<T>;
7
+ export type BPTreeNodeKey<K> = number | K;
8
+ export type BPTreeCondition<V> = Partial<{
9
+ /** Searches for pairs greater than the given value. */
10
+ gt: V;
11
+ /** Searches for pairs less than the given value. */
12
+ lt: V;
13
+ /** Searches for pairs greater than or equal to the given value. */
14
+ gte: V;
15
+ /** Searches for pairs less than or equal to the given value. */
16
+ lte: V;
17
+ /** "Searches for pairs equal to the given value. */
18
+ equal: V;
19
+ /** Searches for pairs not equal to the given value. */
20
+ notEqual: V;
21
+ /** Searches for values matching the given pattern. '%' matches zero or more characters, and '_' matches exactly one character. */
22
+ like: V;
23
+ }>;
24
+ export type BPTreePair<K, V> = {
25
+ key: K;
26
+ value: V;
27
+ };
28
+ export type BPTreeUnknownNode<K, V> = BPTreeInternalNode<K, V> | BPTreeLeafNode<K, V>;
29
+ export interface BPTreeNode<K, V> {
30
+ id: number;
31
+ keys: number[] | K[][];
32
+ values: V[];
33
+ leaf: boolean;
34
+ parent: number;
35
+ next: number;
36
+ prev: number;
37
+ }
38
+ export interface BPTreeInternalNode<K, V> extends BPTreeNode<K, V> {
39
+ leaf: false;
40
+ keys: number[];
41
+ }
42
+ export interface BPTreeLeafNode<K, V> extends BPTreeNode<K, V> {
43
+ leaf: true;
44
+ keys: K[][];
45
+ }
46
+ export declare abstract class BPTree<K, V> {
47
+ protected readonly strategy: SerializeStrategy<K, V>;
48
+ protected readonly comparator: ValueComparator<V>;
49
+ protected readonly nodes: Map<number, BPTreeUnknownNode<K, V>>;
50
+ protected order: number;
51
+ protected data: Record<string, Json>;
52
+ protected root: BPTreeUnknownNode<K, V>;
53
+ protected readonly _nodeCreateBuffer: Map<number, BPTreeUnknownNode<K, V>>;
54
+ protected readonly _nodeUpdateBuffer: Map<number, BPTreeUnknownNode<K, V>>;
55
+ protected _headBuffer: SerializeStrategyHead | null;
56
+ protected readonly verifierMap: Record<keyof BPTreeCondition<V>, (nodeValue: V, value: V) => boolean>;
57
+ protected readonly verifierStartNode: Record<keyof BPTreeCondition<V>, (value: V) => Deferred<BPTreeLeafNode<K, V>>>;
58
+ protected readonly verifierDirection: Record<keyof BPTreeCondition<V>, -1 | 1>;
59
+ protected readonly verifierFullSearch: Record<keyof BPTreeCondition<V>, boolean>;
60
+ protected get headState(): SerializeStrategyHead;
61
+ protected constructor(strategy: SerializeStrategy<K, V>, comparator: ValueComparator<V>);
62
+ protected abstract _getPairsRightToLeft(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean): Deferred<BPTreePair<K, V>[]>;
63
+ protected abstract _getPairsLeftToRight(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean): Deferred<BPTreePair<K, V>[]>;
64
+ protected abstract getPairs(value: V, startNode: BPTreeLeafNode<K, V>, fullSearch: boolean, comparator: (nodeValue: V, value: V) => boolean, direction: -1 | 1): Deferred<BPTreePair<K, V>[]>;
65
+ protected abstract _createNodeId(): Deferred<number>;
66
+ protected abstract _createNode(keys: number[] | K[][], values: V[], leaf?: boolean, parent?: number, next?: number, prev?: number): Deferred<BPTreeUnknownNode<K, V>>;
67
+ protected abstract _deleteEntry(node: BPTreeUnknownNode<K, V>, key: BPTreeNodeKey<K>, value: V): Deferred<void>;
68
+ protected abstract _insertInParent(node: BPTreeUnknownNode<K, V>, value: V, pointer: BPTreeUnknownNode<K, V>): Deferred<void>;
69
+ protected abstract getNode(id: number): Deferred<BPTreeUnknownNode<K, V>>;
70
+ protected abstract insertableNode(value: V): Deferred<BPTreeLeafNode<K, V>>;
71
+ protected abstract leftestNode(): Deferred<BPTreeLeafNode<K, V>>;
72
+ protected abstract commitHeadBuffer(): Deferred<void>;
73
+ protected abstract commitNodeCreateBuffer(): Deferred<void>;
74
+ protected abstract commitNodeUpdateBuffer(): Deferred<void>;
75
+ /**
76
+ * After creating a tree instance, it must be called.
77
+ * This method is used to initialize the stored tree and recover data.
78
+ * If it is not called, the tree will not function.
79
+ */
80
+ abstract init(): Deferred<void>;
81
+ /**
82
+ * It searches for a key within the tree. The result is returned as an array sorted in ascending order based on the value.
83
+ * The result is key set instance, and you can use the `gt`, `lt`, `gte`, `lte`, `equal`, `notEqual`, `like` condition statements.
84
+ * This method operates much faster than first searching with `where` and then retrieving only the key list.
85
+ * @param condition You can use the `gt`, `lt`, `gte`, `lte`, `equal`, `notEqual`, `like` condition statements.
86
+ */
87
+ abstract keys(condition: BPTreeCondition<V>): Deferred<Set<K>>;
88
+ /**
89
+ * It searches for a value within the tree. The result is returned as an array sorted in ascending order based on the value.
90
+ * The result includes the key and value attributes, and you can use the `gt`, `lt`, `gte`, `lte`, `equal`, `notEqual`, `like` condition statements.
91
+ * @param condition You can use the `gt`, `lt`, `gte`, `lte`, `equal`, `notEqual`, `like` condition statements.
92
+ */
93
+ abstract where(condition: BPTreeCondition<V>): Deferred<BPTreePair<K, V>[]>;
94
+ /**
95
+ * You enter the key and value as a pair. You can later search for the pair by value.
96
+ * This data is stored in the tree, sorted in ascending order of value.
97
+ * @param key The key of the pair.
98
+ * @param value The value of the pair.
99
+ */
100
+ abstract insert(key: K, value: V): Deferred<void>;
101
+ /**
102
+ * Deletes the pair that matches the key and value.
103
+ * @param key The key of the pair.
104
+ * @param value The value of the pair.
105
+ */
106
+ abstract delete(key: K, value: V): Deferred<void>;
107
+ /**
108
+ * It returns whether there is a value in the tree.
109
+ * @param key The key value to search for.
110
+ * @param value The value to search for.
111
+ */
112
+ abstract exists(key: K, value: V): Deferred<boolean>;
113
+ /**
114
+ * Inserts user-defined data into the head of the tree.
115
+ * This feature is useful when you need to store separate, non-volatile information in the tree.
116
+ * For example, you can store information such as the last update time and the number of insertions.
117
+ * @param data User-defined data to be stored in the head of the tree.
118
+ */
119
+ abstract setHeadData(data: Record<string, Json>): Deferred<void>;
120
+ /**
121
+ * This method deletes nodes cached in-memory and caches new nodes from the stored nodes.
122
+ * 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.
123
+ * @param nodeId The node ID to update. If no parameters are passed, it updates all currently cached nodes.
124
+ * @returns The return value is the total number of nodes updated.
125
+ */
126
+ abstract forceUpdate(nodeId: number): Deferred<number>;
127
+ protected _insertAtLeaf(node: BPTreeLeafNode<K, V>, key: K, value: V): void;
128
+ protected bufferForHeadUpdate(head: SerializeStrategyHead | null): Deferred<void>;
129
+ protected bufferForNodeCreate(node: BPTreeUnknownNode<K, V>): Deferred<void>;
130
+ protected bufferForNodeUpdate(node: BPTreeUnknownNode<K, V>): Deferred<void>;
131
+ /**
132
+ * Returns the user-defined data stored in the head of the tree.
133
+ * 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 `{}`.
134
+ * @returns User-defined data stored in the head of the tree.
135
+ */
136
+ getHeadData(): Record<string, Json>;
137
+ }
138
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { BPTreeNode } from './BPTree';
2
- import type { Json } from './utils/types';
2
+ import type { Json } from '../utils/types';
3
3
  export interface SerializeStrategyHead {
4
4
  root: number;
5
5
  order: number;
@@ -14,44 +14,32 @@ export declare abstract class SerializeStrategy<K, V> {
14
14
  *
15
15
  * **WARNING!** The return value should never be `0`.
16
16
  */
17
- abstract id(): number;
17
+ abstract id(): number | Promise<number>;
18
18
  /**
19
19
  * Read the stored node from the ID.
20
20
  * The JSON object of the read node should be returned.
21
21
  * @param id This is the ID of the node to be read.
22
22
  */
23
- abstract read(id: number): BPTreeNode<K, V>;
23
+ abstract read(id: number): BPTreeNode<K, V> | Promise<BPTreeNode<K, V>>;
24
24
  /**
25
25
  * It is called when a node is created or updated and needs to be stored.
26
26
  * The node ID and the node JSON object are passed as parameters. Use this to store the data.
27
27
  * @param id This is the ID of the node to be stored.
28
28
  * @param node This is the JSON object of the node to be stored.
29
29
  */
30
- abstract write(id: number, node: BPTreeNode<K, V>): void;
30
+ abstract write(id: number, node: BPTreeNode<K, V>): void | Promise<void>;
31
31
  /**
32
- * It is called when a tree instance is created.
32
+ * It is called when the `init` method of the tree instance is called.
33
33
  * This method should return the information needed to initialize the tree. This information refers to the values stored in the `writeHead` method.
34
34
  *
35
35
  * If it is the initial creation and there is no stored head, it should return `null`.
36
36
  * In this case, the tree is created based on the order specified in the strategy instance constructor parameters.
37
37
  */
38
- abstract readHead(): SerializeStrategyHead | null;
38
+ abstract readHead(): (SerializeStrategyHead | null) | Promise<(SerializeStrategyHead | null)>;
39
39
  /**
40
40
  * It is called when the root node is created or updated.
41
41
  * The method takes the current state of the tree as a parameter. Serialize and store this value. It will be used for the `readHead` method later.
42
42
  * @param head This is the current state of the tree.
43
43
  */
44
- abstract writeHead(head: SerializeStrategyHead): void;
45
- }
46
- export declare class InMemoryStoreStrategy<K, V> extends SerializeStrategy<K, V> {
47
- protected readonly data: {
48
- head: SerializeStrategyHead | null;
49
- node: Record<number, BPTreeNode<K, V>>;
50
- };
51
- constructor(order: number);
52
- id(): number;
53
- read(id: number): BPTreeNode<K, V>;
54
- write(id: number, node: BPTreeNode<K, V>): void;
55
- readHead(): SerializeStrategyHead | null;
56
- writeHead(head: SerializeStrategyHead): void;
44
+ abstract writeHead(head: SerializeStrategyHead): void | Promise<void>;
57
45
  }
@@ -1,3 +1,7 @@
1
- export { BPTree, BPTreeNode } from './BPTree';
2
- export { SerializeStrategy, SerializeStrategyHead, InMemoryStoreStrategy } from './SerializeStrategy';
1
+ export type { BPTreeNode } from './base/BPTree';
2
+ export type { SerializeStrategyHead } from './base/SerializeStrategy';
3
+ export { BPTreeSync } from './BPTreeSync';
4
+ export { BPTreeAsync } from './BPTreeAsync';
5
+ export { SerializeStrategySync, InMemoryStoreStrategySync } from './SerializeStrategySync';
6
+ export { SerializeStrategyAsync, InMemoryStoreStrategyAsync } from './SerializeStrategyAsync';
3
7
  export { ValueComparator, NumericComparator, StringComparator } from './ValueComparator';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "2.0.0",
3
+ "version": "3.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",
@@ -23,6 +23,10 @@
23
23
  "bptree",
24
24
  "event"
25
25
  ],
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/izure1/serializable-bptree.git"
29
+ },
26
30
  "license": "MIT",
27
31
  "devDependencies": {
28
32
  "@types/jest": "^29.5.8",
@@ -1,127 +0,0 @@
1
- import type { Json } from './utils/types';
2
- import { BinarySearch } from './utils/BinarySearch';
3
- import { ValueComparator } from './ValueComparator';
4
- import { SerializeStrategy } from './SerializeStrategy';
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. */
15
- equal: V;
16
- /** Searches for pairs not equal to the given value. */
17
- notEqual: V;
18
- /** Searches for values matching the given pattern. '%' matches zero or more characters, and '_' matches exactly one character. */
19
- like: V;
20
- }>;
21
- type BPTreePair<K, V> = {
22
- key: K;
23
- value: V;
24
- };
25
- export type BPTreeUnknownNode<K, V> = BPTreeInternalNode<K, V> | BPTreeLeafNode<K, V>;
26
- export interface BPTreeNode<K, V> {
27
- id: number;
28
- keys: number[] | K[][];
29
- values: V[];
30
- leaf: boolean;
31
- parent: number;
32
- next: number;
33
- prev: number;
34
- }
35
- export interface BPTreeInternalNode<K, V> extends BPTreeNode<K, V> {
36
- leaf: false;
37
- keys: number[];
38
- }
39
- export interface BPTreeLeafNode<K, V> extends BPTreeNode<K, V> {
40
- leaf: true;
41
- keys: K[][];
42
- }
43
- export declare class BPTree<K, V> {
44
- protected readonly strategy: SerializeStrategy<K, V>;
45
- protected readonly comparator: ValueComparator<V>;
46
- protected readonly search: BinarySearch<V>;
47
- protected readonly order: number;
48
- protected readonly nodes: Map<number, BPTreeUnknownNode<K, V>>;
49
- protected data: Record<string, Json>;
50
- protected root: BPTreeUnknownNode<K, V>;
51
- private readonly _creates;
52
- private readonly _updates;
53
- private _updatedHead;
54
- private readonly _verifierMap;
55
- private readonly _verifierStartNode;
56
- private readonly _verifierDirection;
57
- private readonly _verifierFullSearch;
58
- private _createNodeId;
59
- private _createNode;
60
- /**
61
- * @param strategy An instance of a strategy that manages the read/write state of a node.
62
- * @param comparator An instance of a comparator that compares the size of values.
63
- */
64
- constructor(strategy: SerializeStrategy<K, V>, comparator: ValueComparator<V>);
65
- private get _headState();
66
- private _setHeadUpdate;
67
- private _setCreates;
68
- private _setUpdates;
69
- private _emitHeadUpdates;
70
- private _emitCreates;
71
- private _emitUpdates;
72
- protected getNode(id: number): BPTreeUnknownNode<K, V>;
73
- protected leftestNode(): BPTreeLeafNode<K, V>;
74
- protected insertableNode(value: V): BPTreeLeafNode<K, V>;
75
- /**
76
- * It returns whether there is a value in the tree.
77
- * @param key The key value to search for.
78
- * @param value The value to search for.
79
- */
80
- exists(key: K, value: V): boolean;
81
- private _insertAtLeaf;
82
- private _insertInParent;
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>[];
86
- /**
87
- * It searches for a key within the tree. The result is returned as an array sorted in ascending order based on the value.
88
- * The result is key set instance, and you can use the `gt`, `lt`, `gte`, `lte`, `equal`, `notEqual`, `like` condition statements.
89
- * This method operates much faster than first searching with `where` and then retrieving only the key list.
90
- * @param condition You can use the `gt`, `lt`, `gte`, `lte`, `equal`, `notEqual`, `like` condition statements.
91
- */
92
- keys(condition: BPTreeCondition<V>): Set<K>;
93
- /**
94
- * It searches for a value within the tree. The result is returned as an array sorted in ascending order based on the value.
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.
97
- */
98
- where(condition: BPTreeCondition<V>): BPTreePair<K, V>[];
99
- /**
100
- * You enter the key and value as a pair. You can later search for the pair by value.
101
- * This data is stored in the tree, sorted in ascending order of value.
102
- * @param key The key of the pair.
103
- * @param value The value of the pair.
104
- */
105
- insert(key: K, value: V): void;
106
- /**
107
- * Deletes the pair that matches the key and value.
108
- * @param key The key of the pair.
109
- * @param value The value of the pair.
110
- */
111
- delete(key: K, value: V): void;
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;
126
- }
127
- export {};
@@ -1,9 +0,0 @@
1
- import { ValueComparator } from '../ValueComparator';
2
- export declare class BinarySearch<T> {
3
- protected readonly comparator: ValueComparator<T>;
4
- constructor(comparator: ValueComparator<T>);
5
- _withRange(array: T[], value: T, left?: number, right?: number): number;
6
- leftest(array: T[], value: T): number;
7
- rightest(array: T[], value: T): number;
8
- range(array: T[], value: T): [number, number];
9
- }