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