data-structure-typed 1.51.1 → 1.51.3
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 +208 -185
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +158 -146
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +16 -10
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +31 -25
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +27 -1
- package/dist/cjs/data-structures/binary-tree/bst.js +29 -0
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +1 -47
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +6 -61
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +16 -10
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +31 -25
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +27 -1
- package/dist/mjs/data-structures/binary-tree/bst.js +28 -0
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +1 -47
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +6 -60
- package/dist/umd/data-structure-typed.js +66 -86
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +92 -69
- package/src/data-structures/binary-tree/binary-tree.ts +33 -28
- package/src/data-structures/binary-tree/bst.ts +36 -1
- package/src/data-structures/binary-tree/rb-tree.ts +6 -72
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -0
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +4 -0
- package/test/unit/data-structures/binary-tree/overall.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +40 -40
|
@@ -47,19 +47,11 @@ class RedBlackTree extends bst_1.BST {
|
|
|
47
47
|
*/
|
|
48
48
|
constructor(keysOrNodesOrEntries = [], options) {
|
|
49
49
|
super([], options);
|
|
50
|
-
this.
|
|
51
|
-
this._root = this.SENTINEL;
|
|
50
|
+
this._root = this.NIL;
|
|
52
51
|
if (keysOrNodesOrEntries) {
|
|
53
52
|
this.addMany(keysOrNodesOrEntries);
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
|
-
/**
|
|
57
|
-
* The function returns the value of the _SENTINEL property.
|
|
58
|
-
* @returns The method is returning the value of the `_SENTINEL` property.
|
|
59
|
-
*/
|
|
60
|
-
get SENTINEL() {
|
|
61
|
-
return this._SENTINEL;
|
|
62
|
-
}
|
|
63
55
|
/**
|
|
64
56
|
* The function returns the root node of a tree or undefined if there is no root.
|
|
65
57
|
* @returns The root node of the tree structure, or undefined if there is no root node.
|
|
@@ -147,53 +139,6 @@ class RedBlackTree extends bst_1.BST {
|
|
|
147
139
|
isNode(keyOrNodeOrEntry) {
|
|
148
140
|
return keyOrNodeOrEntry instanceof RedBlackTreeNode;
|
|
149
141
|
}
|
|
150
|
-
/**
|
|
151
|
-
* Time Complexity: O(1)
|
|
152
|
-
* Space Complexity: O(1)
|
|
153
|
-
*/
|
|
154
|
-
/**
|
|
155
|
-
* Time Complexity: O(1)
|
|
156
|
-
* Space Complexity: O(1)
|
|
157
|
-
*
|
|
158
|
-
* The function checks if a given node is a real node in a Red-Black Tree.
|
|
159
|
-
* @param {NODE | undefined} node - The `node` parameter is of type `NODE | undefined`, which means
|
|
160
|
-
* it can either be of type `NODE` or `undefined`.
|
|
161
|
-
* @returns a boolean value.
|
|
162
|
-
*/
|
|
163
|
-
isRealNode(node) {
|
|
164
|
-
if (node === this.SENTINEL || node === undefined)
|
|
165
|
-
return false;
|
|
166
|
-
return node instanceof RedBlackTreeNode;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Time Complexity: O(log n)
|
|
170
|
-
* Space Complexity: O(1)
|
|
171
|
-
*/
|
|
172
|
-
/**
|
|
173
|
-
* Time Complexity: O(log n)
|
|
174
|
-
* Space Complexity: O(1)
|
|
175
|
-
*
|
|
176
|
-
* The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
|
|
177
|
-
* callback function.
|
|
178
|
-
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
|
|
179
|
-
* that you want to search for in the binary search tree. It can be of any type that is compatible
|
|
180
|
-
* with the type of nodes in the tree.
|
|
181
|
-
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
182
|
-
* the tree. It is used to determine whether a node matches the given identifier. The `callback`
|
|
183
|
-
* function should take a node as its parameter and return a value that can be compared to the
|
|
184
|
-
* `identifier` parameter.
|
|
185
|
-
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
|
|
186
|
-
* search tree. It can be either a key or a node. If it is a key, it will be converted to a node
|
|
187
|
-
* using the `ensureNode` method. If it is not provided, the `root`
|
|
188
|
-
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
|
|
189
|
-
* be performed when searching for nodes in the binary search tree. It is an optional parameter and
|
|
190
|
-
* its default value is taken from the `iterationType` property of the class.
|
|
191
|
-
* @returns The method is returning a value of type `NODE | null | undefined`.
|
|
192
|
-
*/
|
|
193
|
-
getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
|
|
194
|
-
var _a;
|
|
195
|
-
return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) !== null && _a !== void 0 ? _a : undefined;
|
|
196
|
-
}
|
|
197
142
|
/**
|
|
198
143
|
* Time Complexity: O(1)
|
|
199
144
|
* Space Complexity: O(1)
|
|
@@ -207,7 +152,7 @@ class RedBlackTree extends bst_1.BST {
|
|
|
207
152
|
*/
|
|
208
153
|
clear() {
|
|
209
154
|
super.clear();
|
|
210
|
-
this._root = this.
|
|
155
|
+
this._root = this.NIL;
|
|
211
156
|
}
|
|
212
157
|
/**
|
|
213
158
|
* Time Complexity: O(log n)
|
|
@@ -369,10 +314,10 @@ class RedBlackTree extends bst_1.BST {
|
|
|
369
314
|
while (this.isRealNode(current)) {
|
|
370
315
|
parent = current;
|
|
371
316
|
if (node.key < current.key) {
|
|
372
|
-
current = (_a = current.left) !== null && _a !== void 0 ? _a : this.
|
|
317
|
+
current = (_a = current.left) !== null && _a !== void 0 ? _a : this.NIL;
|
|
373
318
|
}
|
|
374
319
|
else if (node.key > current.key) {
|
|
375
|
-
current = (_b = current.right) !== null && _b !== void 0 ? _b : this.
|
|
320
|
+
current = (_b = current.right) !== null && _b !== void 0 ? _b : this.NIL;
|
|
376
321
|
}
|
|
377
322
|
else {
|
|
378
323
|
this._replaceNode(current, node);
|
|
@@ -389,8 +334,8 @@ class RedBlackTree extends bst_1.BST {
|
|
|
389
334
|
else {
|
|
390
335
|
parent.right = node;
|
|
391
336
|
}
|
|
392
|
-
node.left = this.
|
|
393
|
-
node.right = this.
|
|
337
|
+
node.left = this.NIL;
|
|
338
|
+
node.right = this.NIL;
|
|
394
339
|
node.color = 'RED';
|
|
395
340
|
this._insertFixup(node);
|
|
396
341
|
return 'CREATED';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rb-tree.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/rb-tree.ts"],"names":[],"mappings":";;;AAWA,+BAAqC;AAGrC,MAAa,gBAIX,SAAQ,aAAmB;IAC3B;;;;;;;;;;OAUG;IACH,YAAY,GAAM,EAAE,KAAS,EAAE,QAAmB,OAAO;QACvD,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAID;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,IAAI,KAAK,CAAC,KAAgB;QACxB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;CACF;AAtCD,4CAsCC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AAC,KAAK,CAAC,EAAE,CAAC;YAC7B,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACrB,CAAC;QAED,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;QAEpB,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YACd,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACnB,CAAC;aAAM,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAC/B,CAAC,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,CAAC,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;QACrB,CAAC;QAED,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;QACZ,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACf,CAAC;CACF;AA9lBD,oCA8lBC"}
|
|
@@ -97,6 +97,12 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
97
97
|
* @returns The size of the object, which is a number.
|
|
98
98
|
*/
|
|
99
99
|
get size(): number;
|
|
100
|
+
protected _NIL: NODE;
|
|
101
|
+
/**
|
|
102
|
+
* The function returns the value of the _NIL property.
|
|
103
|
+
* @returns The method is returning the value of the `_NIL` property.
|
|
104
|
+
*/
|
|
105
|
+
get NIL(): NODE;
|
|
100
106
|
/**
|
|
101
107
|
* Creates a new instance of BinaryTreeNode with the given key and value.
|
|
102
108
|
* @param {K} key - The key for the new node.
|
|
@@ -140,19 +146,18 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
140
146
|
* itself if it is not a valid node key.
|
|
141
147
|
*/
|
|
142
148
|
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* The function checks if a given node is a real node or null.
|
|
151
|
+
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
152
|
+
* @returns a boolean value.
|
|
153
|
+
*/
|
|
154
|
+
isNodeOrNull(node: KeyOrNodeOrEntry<K, V, NODE>): node is NODE | null;
|
|
143
155
|
/**
|
|
144
156
|
* The function "isNode" checks if an keyOrNodeOrEntry is an instance of the BinaryTreeNode class.
|
|
145
157
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V,NODE>`.
|
|
146
158
|
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the class NODE.
|
|
147
159
|
*/
|
|
148
160
|
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
|
|
149
|
-
/**
|
|
150
|
-
* The function checks if a given value is an entry in a binary tree node.
|
|
151
|
-
* @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,NODE> - A generic type representing a node in a binary tree. It has
|
|
152
|
-
* two type parameters V and NODE, representing the value and node type respectively.
|
|
153
|
-
* @returns a boolean value.
|
|
154
|
-
*/
|
|
155
|
-
isEntry(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is BTNEntry<K, V>;
|
|
156
161
|
/**
|
|
157
162
|
* The function checks if a given node is a real node by verifying if it is an instance of
|
|
158
163
|
* BinaryTreeNode and its key is not NaN.
|
|
@@ -167,11 +172,12 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
167
172
|
*/
|
|
168
173
|
isNIL(node: KeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
169
174
|
/**
|
|
170
|
-
* The function checks if a given
|
|
171
|
-
* @param
|
|
175
|
+
* The function checks if a given value is an entry in a binary tree node.
|
|
176
|
+
* @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,NODE> - A generic type representing a node in a binary tree. It has
|
|
177
|
+
* two type parameters V and NODE, representing the value and node type respectively.
|
|
172
178
|
* @returns a boolean value.
|
|
173
179
|
*/
|
|
174
|
-
|
|
180
|
+
isEntry(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is BTNEntry<K, V>;
|
|
175
181
|
/**
|
|
176
182
|
* Time Complexity O(n)
|
|
177
183
|
* Space Complexity O(1)
|
|
@@ -143,6 +143,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
143
143
|
get size() {
|
|
144
144
|
return this._size;
|
|
145
145
|
}
|
|
146
|
+
_NIL = new BinaryTreeNode(NaN);
|
|
147
|
+
/**
|
|
148
|
+
* The function returns the value of the _NIL property.
|
|
149
|
+
* @returns The method is returning the value of the `_NIL` property.
|
|
150
|
+
*/
|
|
151
|
+
get NIL() {
|
|
152
|
+
return this._NIL;
|
|
153
|
+
}
|
|
146
154
|
/**
|
|
147
155
|
* Creates a new instance of BinaryTreeNode with the given key and value.
|
|
148
156
|
* @param {K} key - The key for the new node.
|
|
@@ -237,6 +245,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
237
245
|
return this.getNodeByKey(keyOrNodeOrEntry, iterationType);
|
|
238
246
|
}
|
|
239
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* The function checks if a given node is a real node or null.
|
|
250
|
+
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
251
|
+
* @returns a boolean value.
|
|
252
|
+
*/
|
|
253
|
+
isNodeOrNull(node) {
|
|
254
|
+
return this.isRealNode(node) || node === null;
|
|
255
|
+
}
|
|
240
256
|
/**
|
|
241
257
|
* The function "isNode" checks if an keyOrNodeOrEntry is an instance of the BinaryTreeNode class.
|
|
242
258
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V,NODE>`.
|
|
@@ -245,15 +261,6 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
245
261
|
isNode(keyOrNodeOrEntry) {
|
|
246
262
|
return keyOrNodeOrEntry instanceof BinaryTreeNode;
|
|
247
263
|
}
|
|
248
|
-
/**
|
|
249
|
-
* The function checks if a given value is an entry in a binary tree node.
|
|
250
|
-
* @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,NODE> - A generic type representing a node in a binary tree. It has
|
|
251
|
-
* two type parameters V and NODE, representing the value and node type respectively.
|
|
252
|
-
* @returns a boolean value.
|
|
253
|
-
*/
|
|
254
|
-
isEntry(keyOrNodeOrEntry) {
|
|
255
|
-
return Array.isArray(keyOrNodeOrEntry) && keyOrNodeOrEntry.length === 2;
|
|
256
|
-
}
|
|
257
264
|
/**
|
|
258
265
|
* The function checks if a given node is a real node by verifying if it is an instance of
|
|
259
266
|
* BinaryTreeNode and its key is not NaN.
|
|
@@ -261,7 +268,9 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
261
268
|
* @returns a boolean value.
|
|
262
269
|
*/
|
|
263
270
|
isRealNode(node) {
|
|
264
|
-
|
|
271
|
+
if (!this.isNode(node))
|
|
272
|
+
return false;
|
|
273
|
+
return node !== this.NIL;
|
|
265
274
|
}
|
|
266
275
|
/**
|
|
267
276
|
* The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
|
|
@@ -269,15 +278,16 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
269
278
|
* @returns a boolean value.
|
|
270
279
|
*/
|
|
271
280
|
isNIL(node) {
|
|
272
|
-
return node
|
|
281
|
+
return node === this.NIL;
|
|
273
282
|
}
|
|
274
283
|
/**
|
|
275
|
-
* The function checks if a given
|
|
276
|
-
* @param
|
|
284
|
+
* The function checks if a given value is an entry in a binary tree node.
|
|
285
|
+
* @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,NODE> - A generic type representing a node in a binary tree. It has
|
|
286
|
+
* two type parameters V and NODE, representing the value and node type respectively.
|
|
277
287
|
* @returns a boolean value.
|
|
278
288
|
*/
|
|
279
|
-
|
|
280
|
-
return
|
|
289
|
+
isEntry(keyOrNodeOrEntry) {
|
|
290
|
+
return Array.isArray(keyOrNodeOrEntry) && keyOrNodeOrEntry.length === 2;
|
|
281
291
|
}
|
|
282
292
|
/**
|
|
283
293
|
* Time Complexity O(n)
|
|
@@ -504,10 +514,10 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
504
514
|
if (onlyOne)
|
|
505
515
|
return;
|
|
506
516
|
}
|
|
507
|
-
if (!cur.left && !cur.right)
|
|
517
|
+
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
|
|
508
518
|
return;
|
|
509
|
-
cur.left && dfs(cur.left);
|
|
510
|
-
cur.right && dfs(cur.right);
|
|
519
|
+
this.isRealNode(cur.left) && dfs(cur.left);
|
|
520
|
+
this.isRealNode(cur.right) && dfs(cur.right);
|
|
511
521
|
};
|
|
512
522
|
dfs(beginRoot);
|
|
513
523
|
}
|
|
@@ -515,14 +525,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
515
525
|
const stack = [beginRoot];
|
|
516
526
|
while (stack.length > 0) {
|
|
517
527
|
const cur = stack.pop();
|
|
518
|
-
if (cur) {
|
|
528
|
+
if (this.isRealNode(cur)) {
|
|
519
529
|
if (callback(cur) === identifier) {
|
|
520
530
|
ans.push(cur);
|
|
521
531
|
if (onlyOne)
|
|
522
532
|
return ans;
|
|
523
533
|
}
|
|
524
|
-
cur.left && stack.push(cur.left);
|
|
525
|
-
cur.right && stack.push(cur.right);
|
|
534
|
+
this.isRealNode(cur.left) && stack.push(cur.left);
|
|
535
|
+
this.isRealNode(cur.right) && stack.push(cur.right);
|
|
526
536
|
}
|
|
527
537
|
}
|
|
528
538
|
}
|
|
@@ -554,8 +564,6 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
554
564
|
* @returns a value of type `NODE | null | undefined`.
|
|
555
565
|
*/
|
|
556
566
|
getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
|
|
557
|
-
if ((!callback || callback === this._DEFAULT_CALLBACK) && identifier instanceof BinaryTreeNode)
|
|
558
|
-
callback = (node => node);
|
|
559
567
|
return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? null;
|
|
560
568
|
}
|
|
561
569
|
/**
|
|
@@ -632,8 +640,6 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
632
640
|
* found, `undefined` is returned.
|
|
633
641
|
*/
|
|
634
642
|
get(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
|
|
635
|
-
if ((!callback || callback === this._DEFAULT_CALLBACK) && identifier instanceof BinaryTreeNode)
|
|
636
|
-
callback = (node => node);
|
|
637
643
|
return this.getNode(identifier, callback, beginRoot, iterationType)?.value ?? undefined;
|
|
638
644
|
}
|
|
639
645
|
/**
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { BSTNested, BSTNodeNested, BSTOptions, BTNCallback, KeyOrNodeOrEntry } from '../../types';
|
|
9
|
-
import { BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
|
|
9
|
+
import { BSTNKeyOrNode, BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
|
|
10
10
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
12
|
export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
|
|
@@ -209,6 +209,32 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
|
|
|
209
209
|
* @returns The method returns an array of nodes (`NODE[]`).
|
|
210
210
|
*/
|
|
211
211
|
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
212
|
+
/**
|
|
213
|
+
* Time Complexity: O(log n)
|
|
214
|
+
* Space Complexity: O(1)
|
|
215
|
+
*/
|
|
216
|
+
/**
|
|
217
|
+
* Time Complexity: O(log n)
|
|
218
|
+
* Space Complexity: O(1)
|
|
219
|
+
*
|
|
220
|
+
* The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
|
|
221
|
+
* callback function.
|
|
222
|
+
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
|
|
223
|
+
* that you want to search for in the binary search tree. It can be of any type that is compatible
|
|
224
|
+
* with the type of nodes in the tree.
|
|
225
|
+
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
226
|
+
* the tree. It is used to determine whether a node matches the given identifier. The `callback`
|
|
227
|
+
* function should take a node as its parameter and return a value that can be compared to the
|
|
228
|
+
* `identifier` parameter.
|
|
229
|
+
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
|
|
230
|
+
* search tree. It can be either a key or a node. If it is a key, it will be converted to a node
|
|
231
|
+
* using the `ensureNode` method. If it is not provided, the `root`
|
|
232
|
+
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
|
|
233
|
+
* be performed when searching for nodes in the binary search tree. It is an optional parameter and
|
|
234
|
+
* its default value is taken from the `iterationType` property of the class.
|
|
235
|
+
* @returns The method is returning a value of type `NODE | null | undefined`.
|
|
236
|
+
*/
|
|
237
|
+
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): NODE | undefined;
|
|
212
238
|
/**
|
|
213
239
|
* Time complexity: O(n)
|
|
214
240
|
* Space complexity: O(n)
|
|
@@ -486,6 +486,34 @@ export class BST extends BinaryTree {
|
|
|
486
486
|
}
|
|
487
487
|
return ans;
|
|
488
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* Time Complexity: O(log n)
|
|
491
|
+
* Space Complexity: O(1)
|
|
492
|
+
*/
|
|
493
|
+
/**
|
|
494
|
+
* Time Complexity: O(log n)
|
|
495
|
+
* Space Complexity: O(1)
|
|
496
|
+
*
|
|
497
|
+
* The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
|
|
498
|
+
* callback function.
|
|
499
|
+
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
|
|
500
|
+
* that you want to search for in the binary search tree. It can be of any type that is compatible
|
|
501
|
+
* with the type of nodes in the tree.
|
|
502
|
+
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
503
|
+
* the tree. It is used to determine whether a node matches the given identifier. The `callback`
|
|
504
|
+
* function should take a node as its parameter and return a value that can be compared to the
|
|
505
|
+
* `identifier` parameter.
|
|
506
|
+
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
|
|
507
|
+
* search tree. It can be either a key or a node. If it is a key, it will be converted to a node
|
|
508
|
+
* using the `ensureNode` method. If it is not provided, the `root`
|
|
509
|
+
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
|
|
510
|
+
* be performed when searching for nodes in the binary search tree. It is an optional parameter and
|
|
511
|
+
* its default value is taken from the `iterationType` property of the class.
|
|
512
|
+
* @returns The method is returning a value of type `NODE | null | undefined`.
|
|
513
|
+
*/
|
|
514
|
+
getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
|
|
515
|
+
return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? undefined;
|
|
516
|
+
}
|
|
489
517
|
/**
|
|
490
518
|
* Time complexity: O(n)
|
|
491
519
|
* Space complexity: O(n)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BinaryTreeDeleteResult,
|
|
1
|
+
import type { BinaryTreeDeleteResult, BTNCallback, KeyOrNodeOrEntry, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
|
|
2
2
|
import { CRUD, RBTNColor } from '../../types';
|
|
3
3
|
import { BST, BSTNode } from './bst';
|
|
4
4
|
import { IBinaryTree } from '../../interfaces';
|
|
@@ -39,12 +39,6 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
39
39
|
* should compare keys and
|
|
40
40
|
*/
|
|
41
41
|
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K>);
|
|
42
|
-
protected _SENTINEL: NODE;
|
|
43
|
-
/**
|
|
44
|
-
* The function returns the value of the _SENTINEL property.
|
|
45
|
-
* @returns The method is returning the value of the `_SENTINEL` property.
|
|
46
|
-
*/
|
|
47
|
-
get SENTINEL(): NODE;
|
|
48
42
|
protected _root: NODE | undefined;
|
|
49
43
|
/**
|
|
50
44
|
* The function returns the root node of a tree or undefined if there is no root.
|
|
@@ -101,46 +95,6 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
101
95
|
* @returns {boolean} - `true` if the object is a Red-Black Tree node, `false` otherwise.
|
|
102
96
|
*/
|
|
103
97
|
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
|
|
104
|
-
/**
|
|
105
|
-
* Time Complexity: O(1)
|
|
106
|
-
* Space Complexity: O(1)
|
|
107
|
-
*/
|
|
108
|
-
/**
|
|
109
|
-
* Time Complexity: O(1)
|
|
110
|
-
* Space Complexity: O(1)
|
|
111
|
-
*
|
|
112
|
-
* The function checks if a given node is a real node in a Red-Black Tree.
|
|
113
|
-
* @param {NODE | undefined} node - The `node` parameter is of type `NODE | undefined`, which means
|
|
114
|
-
* it can either be of type `NODE` or `undefined`.
|
|
115
|
-
* @returns a boolean value.
|
|
116
|
-
*/
|
|
117
|
-
isRealNode(node: NODE | undefined): node is NODE;
|
|
118
|
-
/**
|
|
119
|
-
* Time Complexity: O(log n)
|
|
120
|
-
* Space Complexity: O(1)
|
|
121
|
-
*/
|
|
122
|
-
/**
|
|
123
|
-
* Time Complexity: O(log n)
|
|
124
|
-
* Space Complexity: O(1)
|
|
125
|
-
*
|
|
126
|
-
* The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
|
|
127
|
-
* callback function.
|
|
128
|
-
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
|
|
129
|
-
* that you want to search for in the binary search tree. It can be of any type that is compatible
|
|
130
|
-
* with the type of nodes in the tree.
|
|
131
|
-
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
132
|
-
* the tree. It is used to determine whether a node matches the given identifier. The `callback`
|
|
133
|
-
* function should take a node as its parameter and return a value that can be compared to the
|
|
134
|
-
* `identifier` parameter.
|
|
135
|
-
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
|
|
136
|
-
* search tree. It can be either a key or a node. If it is a key, it will be converted to a node
|
|
137
|
-
* using the `ensureNode` method. If it is not provided, the `root`
|
|
138
|
-
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
|
|
139
|
-
* be performed when searching for nodes in the binary search tree. It is an optional parameter and
|
|
140
|
-
* its default value is taken from the `iterationType` property of the class.
|
|
141
|
-
* @returns The method is returning a value of type `NODE | null | undefined`.
|
|
142
|
-
*/
|
|
143
|
-
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
144
98
|
/**
|
|
145
99
|
* Time Complexity: O(1)
|
|
146
100
|
* Space Complexity: O(1)
|
|
@@ -44,19 +44,11 @@ export class RedBlackTree extends BST {
|
|
|
44
44
|
*/
|
|
45
45
|
constructor(keysOrNodesOrEntries = [], options) {
|
|
46
46
|
super([], options);
|
|
47
|
-
this._root = this.
|
|
47
|
+
this._root = this.NIL;
|
|
48
48
|
if (keysOrNodesOrEntries) {
|
|
49
49
|
this.addMany(keysOrNodesOrEntries);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
_SENTINEL = new RedBlackTreeNode(NaN);
|
|
53
|
-
/**
|
|
54
|
-
* The function returns the value of the _SENTINEL property.
|
|
55
|
-
* @returns The method is returning the value of the `_SENTINEL` property.
|
|
56
|
-
*/
|
|
57
|
-
get SENTINEL() {
|
|
58
|
-
return this._SENTINEL;
|
|
59
|
-
}
|
|
60
52
|
_root;
|
|
61
53
|
/**
|
|
62
54
|
* The function returns the root node of a tree or undefined if there is no root.
|
|
@@ -148,52 +140,6 @@ export class RedBlackTree extends BST {
|
|
|
148
140
|
isNode(keyOrNodeOrEntry) {
|
|
149
141
|
return keyOrNodeOrEntry instanceof RedBlackTreeNode;
|
|
150
142
|
}
|
|
151
|
-
/**
|
|
152
|
-
* Time Complexity: O(1)
|
|
153
|
-
* Space Complexity: O(1)
|
|
154
|
-
*/
|
|
155
|
-
/**
|
|
156
|
-
* Time Complexity: O(1)
|
|
157
|
-
* Space Complexity: O(1)
|
|
158
|
-
*
|
|
159
|
-
* The function checks if a given node is a real node in a Red-Black Tree.
|
|
160
|
-
* @param {NODE | undefined} node - The `node` parameter is of type `NODE | undefined`, which means
|
|
161
|
-
* it can either be of type `NODE` or `undefined`.
|
|
162
|
-
* @returns a boolean value.
|
|
163
|
-
*/
|
|
164
|
-
isRealNode(node) {
|
|
165
|
-
if (node === this.SENTINEL || node === undefined)
|
|
166
|
-
return false;
|
|
167
|
-
return node instanceof RedBlackTreeNode;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Time Complexity: O(log n)
|
|
171
|
-
* Space Complexity: O(1)
|
|
172
|
-
*/
|
|
173
|
-
/**
|
|
174
|
-
* Time Complexity: O(log n)
|
|
175
|
-
* Space Complexity: O(1)
|
|
176
|
-
*
|
|
177
|
-
* The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
|
|
178
|
-
* callback function.
|
|
179
|
-
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
|
|
180
|
-
* that you want to search for in the binary search tree. It can be of any type that is compatible
|
|
181
|
-
* with the type of nodes in the tree.
|
|
182
|
-
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
183
|
-
* the tree. It is used to determine whether a node matches the given identifier. The `callback`
|
|
184
|
-
* function should take a node as its parameter and return a value that can be compared to the
|
|
185
|
-
* `identifier` parameter.
|
|
186
|
-
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
|
|
187
|
-
* search tree. It can be either a key or a node. If it is a key, it will be converted to a node
|
|
188
|
-
* using the `ensureNode` method. If it is not provided, the `root`
|
|
189
|
-
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
|
|
190
|
-
* be performed when searching for nodes in the binary search tree. It is an optional parameter and
|
|
191
|
-
* its default value is taken from the `iterationType` property of the class.
|
|
192
|
-
* @returns The method is returning a value of type `NODE | null | undefined`.
|
|
193
|
-
*/
|
|
194
|
-
getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
|
|
195
|
-
return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? undefined;
|
|
196
|
-
}
|
|
197
143
|
/**
|
|
198
144
|
* Time Complexity: O(1)
|
|
199
145
|
* Space Complexity: O(1)
|
|
@@ -207,7 +153,7 @@ export class RedBlackTree extends BST {
|
|
|
207
153
|
*/
|
|
208
154
|
clear() {
|
|
209
155
|
super.clear();
|
|
210
|
-
this._root = this.
|
|
156
|
+
this._root = this.NIL;
|
|
211
157
|
}
|
|
212
158
|
/**
|
|
213
159
|
* Time Complexity: O(log n)
|
|
@@ -368,10 +314,10 @@ export class RedBlackTree extends BST {
|
|
|
368
314
|
while (this.isRealNode(current)) {
|
|
369
315
|
parent = current;
|
|
370
316
|
if (node.key < current.key) {
|
|
371
|
-
current = current.left ?? this.
|
|
317
|
+
current = current.left ?? this.NIL;
|
|
372
318
|
}
|
|
373
319
|
else if (node.key > current.key) {
|
|
374
|
-
current = current.right ?? this.
|
|
320
|
+
current = current.right ?? this.NIL;
|
|
375
321
|
}
|
|
376
322
|
else {
|
|
377
323
|
this._replaceNode(current, node);
|
|
@@ -388,8 +334,8 @@ export class RedBlackTree extends BST {
|
|
|
388
334
|
else {
|
|
389
335
|
parent.right = node;
|
|
390
336
|
}
|
|
391
|
-
node.left = this.
|
|
392
|
-
node.right = this.
|
|
337
|
+
node.left = this.NIL;
|
|
338
|
+
node.right = this.NIL;
|
|
393
339
|
node.color = 'RED';
|
|
394
340
|
this._insertFixup(node);
|
|
395
341
|
return 'CREATED';
|