queue-typed 1.52.9 → 1.53.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/data-structures/binary-tree/avl-tree-multi-map.d.ts +21 -21
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +64 -47
- package/dist/data-structures/binary-tree/avl-tree.d.ts +20 -20
- package/dist/data-structures/binary-tree/avl-tree.js +29 -27
- package/dist/data-structures/binary-tree/binary-tree.d.ts +186 -144
- package/dist/data-structures/binary-tree/binary-tree.js +376 -265
- package/dist/data-structures/binary-tree/bst.d.ts +56 -56
- package/dist/data-structures/binary-tree/bst.js +108 -78
- package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -13
- package/dist/data-structures/binary-tree/rb-tree.js +42 -36
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +21 -21
- package/dist/data-structures/binary-tree/tree-multi-map.js +59 -49
- package/dist/data-structures/trie/trie.js +3 -3
- package/dist/interfaces/binary-tree.d.ts +5 -5
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +13 -13
- package/dist/types/data-structures/binary-tree/bst.d.ts +3 -3
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +60 -54
- package/src/data-structures/binary-tree/avl-tree.ts +32 -35
- package/src/data-structures/binary-tree/binary-tree.ts +440 -360
- package/src/data-structures/binary-tree/bst.ts +144 -113
- package/src/data-structures/binary-tree/rb-tree.ts +44 -43
- package/src/data-structures/binary-tree/tree-multi-map.ts +57 -61
- package/src/data-structures/trie/trie.ts +3 -3
- package/src/interfaces/binary-tree.ts +6 -6
- package/src/types/data-structures/binary-tree/binary-tree.ts +13 -14
- package/src/types/data-structures/binary-tree/bst.ts +3 -3
|
@@ -37,7 +37,7 @@ exports.RedBlackTreeNode = RedBlackTreeNode;
|
|
|
37
37
|
class RedBlackTree extends bst_1.BST {
|
|
38
38
|
/**
|
|
39
39
|
* This is the constructor function for a Red-Black Tree data structure in TypeScript.
|
|
40
|
-
* @param
|
|
40
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
|
|
41
41
|
* iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
|
|
42
42
|
* initialize the RBTree with the provided elements.
|
|
43
43
|
* @param [options] - The `options` parameter is an optional object that can be passed to the
|
|
@@ -45,11 +45,11 @@ class RedBlackTree extends bst_1.BST {
|
|
|
45
45
|
* configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
|
|
46
46
|
* depend on the implementation
|
|
47
47
|
*/
|
|
48
|
-
constructor(
|
|
48
|
+
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
49
49
|
super([], options);
|
|
50
50
|
this._root = this.NIL;
|
|
51
|
-
if (
|
|
52
|
-
this.addMany(
|
|
51
|
+
if (keysNodesEntriesOrRaws) {
|
|
52
|
+
this.addMany(keysNodesEntriesOrRaws);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
@@ -74,7 +74,7 @@ class RedBlackTree extends bst_1.BST {
|
|
|
74
74
|
* returned.
|
|
75
75
|
*/
|
|
76
76
|
createNode(key, value, color = 'BLACK') {
|
|
77
|
-
return new RedBlackTreeNode(key, value, color);
|
|
77
|
+
return new RedBlackTreeNode(key, this._isMapMode ? undefined : value, color);
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* The function creates a new Red-Black Tree with the specified options.
|
|
@@ -83,20 +83,20 @@ class RedBlackTree extends bst_1.BST {
|
|
|
83
83
|
* @returns a new instance of a RedBlackTree object.
|
|
84
84
|
*/
|
|
85
85
|
createTree(options) {
|
|
86
|
-
return new RedBlackTree([], Object.assign({ iterationType: this.iterationType, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
|
|
86
|
+
return new RedBlackTree([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Time Complexity: O(1)
|
|
90
90
|
* Space Complexity: O(1)
|
|
91
91
|
*
|
|
92
92
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
93
|
-
* @param {
|
|
94
|
-
* `
|
|
95
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
93
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
94
|
+
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
95
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
|
|
96
96
|
* an instance of the `RedBlackTreeNode` class.
|
|
97
97
|
*/
|
|
98
|
-
isNode(
|
|
99
|
-
return
|
|
98
|
+
isNode(keyNodeEntryOrRaw) {
|
|
99
|
+
return keyNodeEntryOrRaw instanceof RedBlackTreeNode;
|
|
100
100
|
}
|
|
101
101
|
// /**
|
|
102
102
|
// * Time Complexity: O(1)
|
|
@@ -107,29 +107,29 @@ class RedBlackTree extends bst_1.BST {
|
|
|
107
107
|
// * Time Complexity: O(1)
|
|
108
108
|
// * Space Complexity: O(1)
|
|
109
109
|
// *
|
|
110
|
-
// * The function `
|
|
110
|
+
// * The function `keyValueNodeEntryRawToNodeAndValue` takes a key, value, or entry and returns a node if it is
|
|
111
111
|
// * valid, otherwise it returns undefined.
|
|
112
|
-
// * @param {
|
|
113
|
-
// * @param {V} [value] - The value associated with the key (if `
|
|
112
|
+
// * @param {BTNRep<K, V, NODE>} keyNodeEntryOrRaw - The key, value, or entry to convert.
|
|
113
|
+
// * @param {V} [value] - The value associated with the key (if `keyNodeEntryOrRaw` is a key).
|
|
114
114
|
// * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
|
|
115
115
|
// */
|
|
116
|
-
// override
|
|
116
|
+
// override keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): NODE | undefined {
|
|
117
117
|
//
|
|
118
|
-
// if (
|
|
119
|
-
// if (this.isNode(
|
|
118
|
+
// if (keyNodeEntryOrRaw === null || keyNodeEntryOrRaw === undefined) return;
|
|
119
|
+
// if (this.isNode(keyNodeEntryOrRaw)) return keyNodeEntryOrRaw;
|
|
120
120
|
//
|
|
121
121
|
// if (this._toEntryFn) {
|
|
122
|
-
// const [key, entryValue] = this._toEntryFn(
|
|
123
|
-
// if (this.isKey(key)) return this.createNode(key,
|
|
122
|
+
// const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw as R);
|
|
123
|
+
// if (this.isKey(key)) return this.createNode(key, value ?? entryValue, 'RED');
|
|
124
124
|
// }
|
|
125
125
|
//
|
|
126
|
-
// if (this.isEntry(
|
|
127
|
-
// const [key, value] =
|
|
126
|
+
// if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
127
|
+
// const [key, value] = keyNodeEntryOrRaw;
|
|
128
128
|
// if (key === undefined || key === null) return;
|
|
129
129
|
// else return this.createNode(key, value, 'RED');
|
|
130
130
|
// }
|
|
131
131
|
//
|
|
132
|
-
// if (this.isKey(
|
|
132
|
+
// if (this.isKey(keyNodeEntryOrRaw)) return this.createNode(keyNodeEntryOrRaw, value, 'RED');
|
|
133
133
|
//
|
|
134
134
|
// return ;
|
|
135
135
|
// }
|
|
@@ -150,8 +150,8 @@ class RedBlackTree extends bst_1.BST {
|
|
|
150
150
|
*
|
|
151
151
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
152
152
|
* added.
|
|
153
|
-
* @param {
|
|
154
|
-
* `
|
|
153
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
154
|
+
* `keyNodeEntryOrRaw` can accept a value of type `R` or `BTNRep<K, V, NODE>`.
|
|
155
155
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
156
156
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
157
157
|
* structure.
|
|
@@ -159,8 +159,8 @@ class RedBlackTree extends bst_1.BST {
|
|
|
159
159
|
* the method returns true. If the node already exists and its value is updated, the method also
|
|
160
160
|
* returns true. If the node cannot be added or updated, the method returns false.
|
|
161
161
|
*/
|
|
162
|
-
add(
|
|
163
|
-
const newNode = this.
|
|
162
|
+
add(keyNodeEntryOrRaw, value) {
|
|
163
|
+
const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
|
|
164
164
|
if (!this.isRealNode(newNode))
|
|
165
165
|
return false;
|
|
166
166
|
const insertStatus = this._insert(newNode);
|
|
@@ -172,11 +172,17 @@ class RedBlackTree extends bst_1.BST {
|
|
|
172
172
|
else {
|
|
173
173
|
return false;
|
|
174
174
|
}
|
|
175
|
+
if (this._isMapMode)
|
|
176
|
+
this._setValue(newNode.key, newValue);
|
|
175
177
|
this._size++;
|
|
176
178
|
return true;
|
|
177
179
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
+
if (insertStatus === 'UPDATED') {
|
|
181
|
+
if (this._isMapMode)
|
|
182
|
+
this._setValue(newNode.key, newValue);
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
180
186
|
}
|
|
181
187
|
/**
|
|
182
188
|
* Time Complexity: O(log n)
|
|
@@ -184,7 +190,7 @@ class RedBlackTree extends bst_1.BST {
|
|
|
184
190
|
*
|
|
185
191
|
* The function overrides the delete method in a binary tree data structure to remove a node based on
|
|
186
192
|
* a given predicate and maintain the binary search tree properties.
|
|
187
|
-
* @param {
|
|
193
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
|
|
188
194
|
* parameter in the `override delete` method is used to specify the condition or key based on which a
|
|
189
195
|
* node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
|
|
190
196
|
* function that determines which node(s) should be deleted.
|
|
@@ -192,17 +198,15 @@ class RedBlackTree extends bst_1.BST {
|
|
|
192
198
|
* objects. Each object in the array contains information about the deleted node and whether
|
|
193
199
|
* balancing is needed.
|
|
194
200
|
*/
|
|
195
|
-
delete(
|
|
196
|
-
if (
|
|
201
|
+
delete(keyNodeEntryOrRaw) {
|
|
202
|
+
if (keyNodeEntryOrRaw === null)
|
|
197
203
|
return [];
|
|
198
204
|
const results = [];
|
|
199
205
|
let nodeToDelete;
|
|
200
|
-
if (this.
|
|
201
|
-
nodeToDelete = this.getNode(
|
|
206
|
+
if (this._isPredicate(keyNodeEntryOrRaw))
|
|
207
|
+
nodeToDelete = this.getNode(keyNodeEntryOrRaw);
|
|
202
208
|
else
|
|
203
|
-
nodeToDelete = this.isRealNode(
|
|
204
|
-
? keyOrNodeOrEntryOrRaw
|
|
205
|
-
: this.getNode(keyOrNodeOrEntryOrRaw);
|
|
209
|
+
nodeToDelete = this.isRealNode(keyNodeEntryOrRaw) ? keyNodeEntryOrRaw : this.getNode(keyNodeEntryOrRaw);
|
|
206
210
|
if (!nodeToDelete) {
|
|
207
211
|
return results;
|
|
208
212
|
}
|
|
@@ -241,6 +245,8 @@ class RedBlackTree extends bst_1.BST {
|
|
|
241
245
|
successor.color = nodeToDelete.color;
|
|
242
246
|
}
|
|
243
247
|
}
|
|
248
|
+
if (this._isMapMode)
|
|
249
|
+
this._store.delete(nodeToDelete.key);
|
|
244
250
|
this._size--;
|
|
245
251
|
// If the original color was black, fix the tree
|
|
246
252
|
if (originalColor === 'BLACK') {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult,
|
|
8
|
+
import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode, BTNRep, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
|
|
9
9
|
import { IBinaryTree } from '../../interfaces';
|
|
10
10
|
import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
|
|
11
11
|
export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
|
|
@@ -35,17 +35,17 @@ export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMa
|
|
|
35
35
|
*/
|
|
36
36
|
set count(value: number);
|
|
37
37
|
}
|
|
38
|
-
export declare class TreeMultiMap<K = any, V = any, R =
|
|
38
|
+
export declare class TreeMultiMap<K = any, V = any, R = object, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>, TREE extends TreeMultiMap<K, V, R, NODE, TREE> = TreeMultiMap<K, V, R, NODE, TreeMultiMapNested<K, V, R, NODE>>> extends RedBlackTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
39
39
|
/**
|
|
40
40
|
* The constructor function initializes a TreeMultiMap object with optional initial data.
|
|
41
|
-
* @param
|
|
41
|
+
* @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
|
|
42
42
|
* iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
|
|
43
43
|
* TreeMultiMap with initial data.
|
|
44
44
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
45
45
|
* behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
|
|
46
46
|
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
47
47
|
*/
|
|
48
|
-
constructor(
|
|
48
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V, NODE>>, options?: TreeMultiMapOptions<K, V, R>);
|
|
49
49
|
protected _count: number;
|
|
50
50
|
/**
|
|
51
51
|
* The function calculates the sum of the count property of all nodes in a tree structure.
|
|
@@ -85,10 +85,10 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
85
85
|
*/
|
|
86
86
|
createTree(options?: TreeMultiMapOptions<K, V, R>): TREE;
|
|
87
87
|
/**
|
|
88
|
-
* The function `
|
|
88
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
|
|
89
89
|
* node based on the input.
|
|
90
|
-
* @param {
|
|
91
|
-
* `
|
|
90
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
91
|
+
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
92
92
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
93
93
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
94
94
|
* an existing node.
|
|
@@ -96,23 +96,23 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
96
96
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
97
97
|
* @returns either a NODE object or undefined.
|
|
98
98
|
*/
|
|
99
|
-
|
|
99
|
+
keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V, count?: number): [NODE | undefined, V | undefined];
|
|
100
100
|
/**
|
|
101
101
|
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
102
|
-
* @param {
|
|
103
|
-
* `
|
|
104
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
102
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
103
|
+
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
104
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
|
|
105
105
|
* an instance of the `TreeMultiMapNode` class.
|
|
106
106
|
*/
|
|
107
|
-
isNode(
|
|
107
|
+
isNode(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is NODE;
|
|
108
108
|
/**
|
|
109
109
|
* Time Complexity: O(log n)
|
|
110
110
|
* Space Complexity: O(1)
|
|
111
111
|
*
|
|
112
112
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
113
113
|
* the count and returning a boolean indicating success.
|
|
114
|
-
* @param {
|
|
115
|
-
* `
|
|
114
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
115
|
+
* `keyNodeEntryOrRaw` parameter can accept one of the following types:
|
|
116
116
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
117
117
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
118
118
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
@@ -121,14 +121,14 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
121
121
|
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
122
122
|
* was successful, and false otherwise.
|
|
123
123
|
*/
|
|
124
|
-
add(
|
|
124
|
+
add(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V, count?: number): boolean;
|
|
125
125
|
/**
|
|
126
126
|
* Time Complexity: O(log n)
|
|
127
127
|
* Space Complexity: O(1)
|
|
128
128
|
*
|
|
129
129
|
* The function `delete` in TypeScript overrides the deletion operation in a binary tree data
|
|
130
130
|
* structure, handling cases where nodes have children and maintaining balance in the tree.
|
|
131
|
-
* @param {
|
|
131
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `predicate`
|
|
132
132
|
* parameter in the `delete` method is used to specify the condition or key based on which a node
|
|
133
133
|
* should be deleted from the binary tree. It can be a key, a node, or an entry.
|
|
134
134
|
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
@@ -137,7 +137,7 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
137
137
|
* `ignoreCount` is `false
|
|
138
138
|
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
|
|
139
139
|
*/
|
|
140
|
-
delete(
|
|
140
|
+
delete(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
|
|
141
141
|
/**
|
|
142
142
|
* Time Complexity: O(1)
|
|
143
143
|
* Space Complexity: O(1)
|
|
@@ -174,15 +174,15 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
174
174
|
*
|
|
175
175
|
* The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
|
|
176
176
|
* in a binary search tree.
|
|
177
|
-
* @param {R |
|
|
177
|
+
* @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
|
|
178
178
|
* that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
|
|
179
|
-
* instance of the `
|
|
180
|
-
* @param {R |
|
|
179
|
+
* instance of the `BSTNOptKeyOrNode<K, NODE>` class.
|
|
180
|
+
* @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
|
|
181
181
|
* node where the properties will be swapped with the source node.
|
|
182
182
|
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
183
183
|
* If either `srcNode` or `destNode` is undefined, it returns undefined.
|
|
184
184
|
*/
|
|
185
|
-
protected _swapProperties(srcNode: R |
|
|
185
|
+
protected _swapProperties(srcNode: R | BSTNOptKeyOrNode<K, NODE>, destNode: R | BSTNOptKeyOrNode<K, NODE>): NODE | undefined;
|
|
186
186
|
/**
|
|
187
187
|
* Time Complexity: O(1)
|
|
188
188
|
* Space Complexity: O(1)
|
|
@@ -40,18 +40,18 @@ exports.TreeMultiMapNode = TreeMultiMapNode;
|
|
|
40
40
|
class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
41
41
|
/**
|
|
42
42
|
* The constructor function initializes a TreeMultiMap object with optional initial data.
|
|
43
|
-
* @param
|
|
43
|
+
* @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
|
|
44
44
|
* iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
|
|
45
45
|
* TreeMultiMap with initial data.
|
|
46
46
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
47
47
|
* behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
|
|
48
48
|
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
49
49
|
*/
|
|
50
|
-
constructor(
|
|
50
|
+
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
51
51
|
super([], options);
|
|
52
52
|
this._count = 0;
|
|
53
|
-
if (
|
|
54
|
-
this.addMany(
|
|
53
|
+
if (keysNodesEntriesOrRaws)
|
|
54
|
+
this.addMany(keysNodesEntriesOrRaws);
|
|
55
55
|
}
|
|
56
56
|
// TODO the _count is not accurate after nodes count modified
|
|
57
57
|
/**
|
|
@@ -88,7 +88,7 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
88
88
|
* @returns A new instance of the TreeMultiMapNode class, casted as NODE.
|
|
89
89
|
*/
|
|
90
90
|
createNode(key, value, color = 'BLACK', count) {
|
|
91
|
-
return new TreeMultiMapNode(key, value, count, color);
|
|
91
|
+
return new TreeMultiMapNode(key, this._isMapMode ? undefined : value, count, color);
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* The function creates a new instance of a TreeMultiMap with the specified options and returns it.
|
|
@@ -99,13 +99,13 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
99
99
|
* existing `iterationType` property. The returned value is casted as `TREE`.
|
|
100
100
|
*/
|
|
101
101
|
createTree(options) {
|
|
102
|
-
return new TreeMultiMap([], Object.assign({ iterationType: this.iterationType, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
|
|
102
|
+
return new TreeMultiMap([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
|
-
* The function `
|
|
105
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
|
|
106
106
|
* node based on the input.
|
|
107
|
-
* @param {
|
|
108
|
-
* `
|
|
107
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
108
|
+
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
109
109
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
110
110
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
111
111
|
* an existing node.
|
|
@@ -113,36 +113,38 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
113
113
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
114
114
|
* @returns either a NODE object or undefined.
|
|
115
115
|
*/
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
return;
|
|
119
|
-
if (this.isNode(
|
|
120
|
-
return
|
|
121
|
-
if (this.isEntry(
|
|
122
|
-
const [key, entryValue] =
|
|
116
|
+
keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
|
|
117
|
+
if (keyNodeEntryOrRaw === undefined || keyNodeEntryOrRaw === null)
|
|
118
|
+
return [undefined, undefined];
|
|
119
|
+
if (this.isNode(keyNodeEntryOrRaw))
|
|
120
|
+
return [keyNodeEntryOrRaw, value];
|
|
121
|
+
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
122
|
+
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
123
123
|
if (key === undefined || key === null)
|
|
124
|
-
return;
|
|
124
|
+
return [undefined, undefined];
|
|
125
|
+
const finalValue = value !== null && value !== void 0 ? value : entryValue;
|
|
125
126
|
if (this.isKey(key))
|
|
126
|
-
return this.createNode(key,
|
|
127
|
+
return [this.createNode(key, finalValue, 'BLACK', count), finalValue];
|
|
127
128
|
}
|
|
128
129
|
if (this._toEntryFn) {
|
|
129
|
-
const [key, entryValue] = this._toEntryFn(
|
|
130
|
+
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
131
|
+
const finalValue = value !== null && value !== void 0 ? value : entryValue;
|
|
130
132
|
if (this.isKey(key))
|
|
131
|
-
return this.createNode(key,
|
|
133
|
+
return [this.createNode(key, finalValue, 'BLACK', count), finalValue];
|
|
132
134
|
}
|
|
133
|
-
if (this.isKey(
|
|
134
|
-
return this.createNode(
|
|
135
|
-
return;
|
|
135
|
+
if (this.isKey(keyNodeEntryOrRaw))
|
|
136
|
+
return [this.createNode(keyNodeEntryOrRaw, value, 'BLACK', count), value];
|
|
137
|
+
return [undefined, undefined];
|
|
136
138
|
}
|
|
137
139
|
/**
|
|
138
140
|
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
139
|
-
* @param {
|
|
140
|
-
* `
|
|
141
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
141
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
142
|
+
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
143
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
|
|
142
144
|
* an instance of the `TreeMultiMapNode` class.
|
|
143
145
|
*/
|
|
144
|
-
isNode(
|
|
145
|
-
return
|
|
146
|
+
isNode(keyNodeEntryOrRaw) {
|
|
147
|
+
return keyNodeEntryOrRaw instanceof TreeMultiMapNode;
|
|
146
148
|
}
|
|
147
149
|
/**
|
|
148
150
|
* Time Complexity: O(log n)
|
|
@@ -150,8 +152,8 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
150
152
|
*
|
|
151
153
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
152
154
|
* the count and returning a boolean indicating success.
|
|
153
|
-
* @param {
|
|
154
|
-
* `
|
|
155
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
156
|
+
* `keyNodeEntryOrRaw` parameter can accept one of the following types:
|
|
155
157
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
156
158
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
157
159
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
@@ -160,10 +162,10 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
160
162
|
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
161
163
|
* was successful, and false otherwise.
|
|
162
164
|
*/
|
|
163
|
-
add(
|
|
164
|
-
const newNode = this.
|
|
165
|
+
add(keyNodeEntryOrRaw, value, count = 1) {
|
|
166
|
+
const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
|
|
165
167
|
const orgCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
|
|
166
|
-
const isSuccessAdded = super.add(newNode);
|
|
168
|
+
const isSuccessAdded = super.add(newNode, newValue);
|
|
167
169
|
if (isSuccessAdded) {
|
|
168
170
|
this._count += orgCount;
|
|
169
171
|
return true;
|
|
@@ -178,7 +180,7 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
178
180
|
*
|
|
179
181
|
* The function `delete` in TypeScript overrides the deletion operation in a binary tree data
|
|
180
182
|
* structure, handling cases where nodes have children and maintaining balance in the tree.
|
|
181
|
-
* @param {
|
|
183
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `predicate`
|
|
182
184
|
* parameter in the `delete` method is used to specify the condition or key based on which a node
|
|
183
185
|
* should be deleted from the binary tree. It can be a key, a node, or an entry.
|
|
184
186
|
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
@@ -187,17 +189,15 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
187
189
|
* `ignoreCount` is `false
|
|
188
190
|
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
|
|
189
191
|
*/
|
|
190
|
-
delete(
|
|
191
|
-
if (
|
|
192
|
+
delete(keyNodeEntryOrRaw, ignoreCount = false) {
|
|
193
|
+
if (keyNodeEntryOrRaw === null)
|
|
192
194
|
return [];
|
|
193
195
|
const results = [];
|
|
194
196
|
let nodeToDelete;
|
|
195
|
-
if (this.
|
|
196
|
-
nodeToDelete = this.getNode(
|
|
197
|
+
if (this._isPredicate(keyNodeEntryOrRaw))
|
|
198
|
+
nodeToDelete = this.getNode(keyNodeEntryOrRaw);
|
|
197
199
|
else
|
|
198
|
-
nodeToDelete = this.isRealNode(
|
|
199
|
-
? keyOrNodeOrEntryOrRaw
|
|
200
|
-
: this.getNode(keyOrNodeOrEntryOrRaw);
|
|
200
|
+
nodeToDelete = this.isRealNode(keyNodeEntryOrRaw) ? keyNodeEntryOrRaw : this.getNode(keyNodeEntryOrRaw);
|
|
201
201
|
if (!nodeToDelete) {
|
|
202
202
|
return results;
|
|
203
203
|
}
|
|
@@ -315,7 +315,10 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
315
315
|
return;
|
|
316
316
|
const m = l + Math.floor((r - l) / 2);
|
|
317
317
|
const midNode = sorted[m];
|
|
318
|
-
this.
|
|
318
|
+
if (this._isMapMode)
|
|
319
|
+
this.add(midNode.key, undefined, midNode.count);
|
|
320
|
+
else
|
|
321
|
+
this.add(midNode.key, midNode.value, midNode.count);
|
|
319
322
|
buildBalanceBST(l, m - 1);
|
|
320
323
|
buildBalanceBST(m + 1, r);
|
|
321
324
|
};
|
|
@@ -331,7 +334,10 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
331
334
|
if (l <= r) {
|
|
332
335
|
const m = l + Math.floor((r - l) / 2);
|
|
333
336
|
const midNode = sorted[m];
|
|
334
|
-
this.
|
|
337
|
+
if (this._isMapMode)
|
|
338
|
+
this.add(midNode.key, undefined, midNode.count);
|
|
339
|
+
else
|
|
340
|
+
this.add(midNode.key, midNode.value, midNode.count);
|
|
335
341
|
stack.push([m + 1, r]);
|
|
336
342
|
stack.push([l, m - 1]);
|
|
337
343
|
}
|
|
@@ -349,7 +355,9 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
349
355
|
*/
|
|
350
356
|
clone() {
|
|
351
357
|
const cloned = this.createTree();
|
|
352
|
-
this.bfs(node => cloned.add(node.key,
|
|
358
|
+
this.bfs(node => cloned.add(node.key, undefined, node.count));
|
|
359
|
+
if (this._isMapMode)
|
|
360
|
+
cloned._store = this._store;
|
|
353
361
|
return cloned;
|
|
354
362
|
}
|
|
355
363
|
/**
|
|
@@ -358,10 +366,10 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
358
366
|
*
|
|
359
367
|
* The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
|
|
360
368
|
* in a binary search tree.
|
|
361
|
-
* @param {R |
|
|
369
|
+
* @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
|
|
362
370
|
* that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
|
|
363
|
-
* instance of the `
|
|
364
|
-
* @param {R |
|
|
371
|
+
* instance of the `BSTNOptKeyOrNode<K, NODE>` class.
|
|
372
|
+
* @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
|
|
365
373
|
* node where the properties will be swapped with the source node.
|
|
366
374
|
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
367
375
|
* If either `srcNode` or `destNode` is undefined, it returns undefined.
|
|
@@ -375,11 +383,13 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
375
383
|
if (tempNode) {
|
|
376
384
|
tempNode.color = color;
|
|
377
385
|
destNode.key = srcNode.key;
|
|
378
|
-
|
|
386
|
+
if (!this._isMapMode)
|
|
387
|
+
destNode.value = srcNode.value;
|
|
379
388
|
destNode.count = srcNode.count;
|
|
380
389
|
destNode.color = srcNode.color;
|
|
381
390
|
srcNode.key = tempNode.key;
|
|
382
|
-
|
|
391
|
+
if (!this._isMapMode)
|
|
392
|
+
srcNode.value = tempNode.value;
|
|
383
393
|
srcNode.count = tempNode.count;
|
|
384
394
|
srcNode.color = tempNode.color;
|
|
385
395
|
}
|
|
@@ -239,9 +239,9 @@ class Trie extends base_1.IterableElementBase {
|
|
|
239
239
|
*
|
|
240
240
|
*/
|
|
241
241
|
getHeight() {
|
|
242
|
-
const
|
|
242
|
+
const startNode = this.root;
|
|
243
243
|
let maxDepth = 0;
|
|
244
|
-
if (
|
|
244
|
+
if (startNode) {
|
|
245
245
|
const bfs = (node, level) => {
|
|
246
246
|
if (level > maxDepth) {
|
|
247
247
|
maxDepth = level;
|
|
@@ -253,7 +253,7 @@ class Trie extends base_1.IterableElementBase {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
};
|
|
256
|
-
bfs(
|
|
256
|
+
bfs(startNode, 0);
|
|
257
257
|
}
|
|
258
258
|
return maxDepth;
|
|
259
259
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
|
-
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions,
|
|
3
|
-
export interface IBinaryTree<K = any, V = any, R =
|
|
2
|
+
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNRep, NodePredicate } from '../types';
|
|
3
|
+
export interface IBinaryTree<K = any, V = any, R = object, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTreeNested<K, V, R, NODE>> {
|
|
4
4
|
createNode(key: K, value?: NODE['value']): NODE;
|
|
5
5
|
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
|
|
6
|
-
add(keyOrNodeOrEntryOrRawElement:
|
|
7
|
-
addMany(nodes: Iterable<
|
|
8
|
-
delete(predicate: R |
|
|
6
|
+
add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, NODE>, value?: V, count?: number): boolean;
|
|
7
|
+
addMany(nodes: Iterable<BTNRep<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
|
|
8
|
+
delete(predicate: R | BTNRep<K, V, NODE> | NodePredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
|
|
9
9
|
}
|
|
@@ -3,29 +3,29 @@ import { IterationType, OptValue } from '../../common';
|
|
|
3
3
|
import { DFSOperation } from '../../../constants';
|
|
4
4
|
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
5
|
export type BinaryTreeNested<K, V, R, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type ToEntryFn<K, V, R> = (rawElement: R) => BTNEntry<K, V>;
|
|
6
7
|
export type BinaryTreeOptions<K, V, R> = {
|
|
7
8
|
iterationType?: IterationType;
|
|
8
|
-
toEntryFn?:
|
|
9
|
+
toEntryFn?: ToEntryFn<K, V, R>;
|
|
10
|
+
isMapMode?: boolean;
|
|
9
11
|
};
|
|
10
12
|
export type BinaryTreePrintOptions = {
|
|
11
13
|
isShowUndefined?: boolean;
|
|
12
14
|
isShowNull?: boolean;
|
|
13
15
|
isShowRedBlackNIL?: boolean;
|
|
14
16
|
};
|
|
15
|
-
export type
|
|
16
|
-
export type
|
|
17
|
-
export type BTNEntry<K, V> = [
|
|
18
|
-
export type
|
|
19
|
-
export type
|
|
20
|
-
export type BTNPureKeyOrNode<K, NODE> = K | NODE;
|
|
21
|
-
export type BTNPureKeyOrNodeOrEntry<K, V, NODE> = [K, OptValue<V>] | BTNPureKeyOrNode<K, NODE>;
|
|
17
|
+
export type OptNodeOrNull<NODE> = NODE | null | undefined;
|
|
18
|
+
export type BTNOptKeyOrNull<K> = K | null | undefined;
|
|
19
|
+
export type BTNEntry<K, V> = [BTNOptKeyOrNull<K>, OptValue<V>];
|
|
20
|
+
export type BTNOptKeyNodeOrNull<K, NODE> = BTNOptKeyOrNull<K> | NODE;
|
|
21
|
+
export type BTNRep<K, V, NODE> = BTNEntry<K, V> | BTNOptKeyNodeOrNull<K, NODE>;
|
|
22
22
|
export type BinaryTreeDeleteResult<NODE> = {
|
|
23
|
-
deleted:
|
|
24
|
-
needBalanced:
|
|
23
|
+
deleted: OptNodeOrNull<NODE>;
|
|
24
|
+
needBalanced: OptNodeOrNull<NODE>;
|
|
25
25
|
};
|
|
26
|
-
export type
|
|
27
|
-
export type
|
|
26
|
+
export type NodeCallback<NODE, D = any> = (node: NODE) => D;
|
|
27
|
+
export type NodePredicate<NODE> = (node: NODE) => boolean;
|
|
28
28
|
export type DFSStackItem<NODE> = {
|
|
29
29
|
opt: DFSOperation;
|
|
30
|
-
node:
|
|
30
|
+
node: OptNodeOrNull<NODE>;
|
|
31
31
|
};
|
|
@@ -6,6 +6,6 @@ export type BSTNested<K, V, R, NODE extends BSTNode<K, V, NODE>> = BST<K, V, R,
|
|
|
6
6
|
export type BSTOptions<K, V, R> = BinaryTreeOptions<K, V, R> & {
|
|
7
7
|
comparator?: Comparator<K>;
|
|
8
8
|
};
|
|
9
|
-
export type
|
|
10
|
-
export type
|
|
11
|
-
export type
|
|
9
|
+
export type BSTNOptKey<K> = K | undefined;
|
|
10
|
+
export type OptNode<NODE> = NODE | undefined;
|
|
11
|
+
export type BSTNOptKeyOrNode<K, NODE> = BSTNOptKey<K> | NODE;
|