graph-typed 1.50.5 → 1.50.6
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/binary-tree.js +19 -19
- package/dist/data-structures/binary-tree/rb-tree.d.ts +158 -135
- package/dist/data-structures/binary-tree/rb-tree.js +415 -386
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
- package/dist/data-structures/binary-tree/tree-multi-map.js +84 -76
- package/package.json +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +19 -19
- package/src/data-structures/binary-tree/rb-tree.ts +437 -395
- package/src/data-structures/binary-tree/tree-multi-map.ts +85 -82
|
@@ -736,7 +736,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
736
736
|
return true;
|
|
737
737
|
if (iterationType === types_1.IterationType.RECURSIVE) {
|
|
738
738
|
const dfs = (cur, min, max) => {
|
|
739
|
-
if (!cur)
|
|
739
|
+
if (!this.isRealNode(cur))
|
|
740
740
|
return true;
|
|
741
741
|
const numKey = this.extractor(cur.key);
|
|
742
742
|
if (numKey <= min || numKey >= max)
|
|
@@ -753,14 +753,14 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
753
753
|
let prev = checkMax ? Number.MAX_SAFE_INTEGER : Number.MIN_SAFE_INTEGER;
|
|
754
754
|
// @ts-ignore
|
|
755
755
|
let curr = beginRoot;
|
|
756
|
-
while (curr || stack.length > 0) {
|
|
757
|
-
while (curr) {
|
|
756
|
+
while (this.isRealNode(curr) || stack.length > 0) {
|
|
757
|
+
while (this.isRealNode(curr)) {
|
|
758
758
|
stack.push(curr);
|
|
759
759
|
curr = curr.left;
|
|
760
760
|
}
|
|
761
761
|
curr = stack.pop();
|
|
762
762
|
const numKey = this.extractor(curr.key);
|
|
763
|
-
if (!curr || (!checkMax && prev >= numKey) || (checkMax && prev <= numKey))
|
|
763
|
+
if (!this.isRealNode(curr) || (!checkMax && prev >= numKey) || (checkMax && prev <= numKey))
|
|
764
764
|
return false;
|
|
765
765
|
prev = numKey;
|
|
766
766
|
curr = curr.right;
|
|
@@ -825,7 +825,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
825
825
|
return -1;
|
|
826
826
|
if (iterationType === types_1.IterationType.RECURSIVE) {
|
|
827
827
|
const _getMaxHeight = (cur) => {
|
|
828
|
-
if (!cur)
|
|
828
|
+
if (!this.isRealNode(cur))
|
|
829
829
|
return -1;
|
|
830
830
|
const leftHeight = _getMaxHeight(cur.left);
|
|
831
831
|
const rightHeight = _getMaxHeight(cur.right);
|
|
@@ -838,9 +838,9 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
838
838
|
let maxHeight = 0;
|
|
839
839
|
while (stack.length > 0) {
|
|
840
840
|
const { node, depth } = stack.pop();
|
|
841
|
-
if (node.left)
|
|
841
|
+
if (this.isRealNode(node.left))
|
|
842
842
|
stack.push({ node: node.left, depth: depth + 1 });
|
|
843
|
-
if (node.right)
|
|
843
|
+
if (this.isRealNode(node.right))
|
|
844
844
|
stack.push({ node: node.right, depth: depth + 1 });
|
|
845
845
|
maxHeight = Math.max(maxHeight, depth);
|
|
846
846
|
}
|
|
@@ -1117,48 +1117,48 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1117
1117
|
switch (pattern) {
|
|
1118
1118
|
case 'in':
|
|
1119
1119
|
if (includeNull) {
|
|
1120
|
-
if (node && this.isNodeOrNull(node.left))
|
|
1120
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.left))
|
|
1121
1121
|
_traverse(node.left);
|
|
1122
1122
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1123
|
-
if (node && this.isNodeOrNull(node.right))
|
|
1123
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.right))
|
|
1124
1124
|
_traverse(node.right);
|
|
1125
1125
|
}
|
|
1126
1126
|
else {
|
|
1127
|
-
if (node && node.left)
|
|
1127
|
+
if (this.isRealNode(node) && this.isRealNode(node.left))
|
|
1128
1128
|
_traverse(node.left);
|
|
1129
1129
|
this.isRealNode(node) && ans.push(callback(node));
|
|
1130
|
-
if (node && node.right)
|
|
1130
|
+
if (this.isRealNode(node) && this.isRealNode(node.right))
|
|
1131
1131
|
_traverse(node.right);
|
|
1132
1132
|
}
|
|
1133
1133
|
break;
|
|
1134
1134
|
case 'pre':
|
|
1135
1135
|
if (includeNull) {
|
|
1136
1136
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1137
|
-
if (node && this.isNodeOrNull(node.left))
|
|
1137
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.left))
|
|
1138
1138
|
_traverse(node.left);
|
|
1139
|
-
if (node && this.isNodeOrNull(node.right))
|
|
1139
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.right))
|
|
1140
1140
|
_traverse(node.right);
|
|
1141
1141
|
}
|
|
1142
1142
|
else {
|
|
1143
1143
|
this.isRealNode(node) && ans.push(callback(node));
|
|
1144
|
-
if (node && node.left)
|
|
1144
|
+
if (this.isRealNode(node) && this.isRealNode(node.left))
|
|
1145
1145
|
_traverse(node.left);
|
|
1146
|
-
if (node && node.right)
|
|
1146
|
+
if (this.isRealNode(node) && this.isRealNode(node.right))
|
|
1147
1147
|
_traverse(node.right);
|
|
1148
1148
|
}
|
|
1149
1149
|
break;
|
|
1150
1150
|
case 'post':
|
|
1151
1151
|
if (includeNull) {
|
|
1152
|
-
if (node && this.isNodeOrNull(node.left))
|
|
1152
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.left))
|
|
1153
1153
|
_traverse(node.left);
|
|
1154
|
-
if (node && this.isNodeOrNull(node.right))
|
|
1154
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.right))
|
|
1155
1155
|
_traverse(node.right);
|
|
1156
1156
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1157
1157
|
}
|
|
1158
1158
|
else {
|
|
1159
|
-
if (node && node.left)
|
|
1159
|
+
if (this.isRealNode(node) && this.isRealNode(node.left))
|
|
1160
1160
|
_traverse(node.left);
|
|
1161
|
-
if (node && node.right)
|
|
1161
|
+
if (this.isRealNode(node) && this.isRealNode(node.right))
|
|
1162
1162
|
_traverse(node.right);
|
|
1163
1163
|
this.isRealNode(node) && ans.push(callback(node));
|
|
1164
1164
|
}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* @author Tyler Zeng
|
|
5
|
-
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
-
* @license MIT License
|
|
7
|
-
*/
|
|
8
|
-
import { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
|
|
1
|
+
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
|
|
2
|
+
import { RBTNColor } from '../../types';
|
|
9
3
|
import { BST, BSTNode } from './bst';
|
|
10
4
|
import { IBinaryTree } from '../../interfaces';
|
|
11
5
|
export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
|
|
@@ -24,7 +18,7 @@ export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTre
|
|
|
24
18
|
protected _color: RBTNColor;
|
|
25
19
|
/**
|
|
26
20
|
* The function returns the color value of a variable.
|
|
27
|
-
* @returns The color value stored in the
|
|
21
|
+
* @returns The color value stored in the private variable `_color`.
|
|
28
22
|
*/
|
|
29
23
|
get color(): RBTNColor;
|
|
30
24
|
/**
|
|
@@ -33,38 +27,30 @@ export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTre
|
|
|
33
27
|
*/
|
|
34
28
|
set color(value: RBTNColor);
|
|
35
29
|
}
|
|
36
|
-
/**
|
|
37
|
-
* 1. Each node is either red or black.
|
|
38
|
-
* 2. The root node is always black.
|
|
39
|
-
* 3. Leaf nodes are typically Sentinel nodes and are considered black.
|
|
40
|
-
* 4. Red nodes must have black children.
|
|
41
|
-
* 5. Black balance: Every path from any node to each of its leaf nodes contains the same number of black nodes.
|
|
42
|
-
*/
|
|
43
30
|
export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, NODE, TREE> = RedBlackTree<K, V, NODE, RedBlackTreeNested<K, V, NODE>>> extends BST<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
|
|
44
31
|
/**
|
|
45
|
-
* This is the constructor function for a Red-Black Tree data structure in TypeScript
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* only a subset of the properties defined in the `RBTreeOptions` interface.
|
|
32
|
+
* This is the constructor function for a Red-Black Tree data structure in TypeScript.
|
|
33
|
+
* @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
|
|
34
|
+
* contain keys, nodes, or entries. It is used to initialize the RBTree with the provided keys,
|
|
35
|
+
* nodes, or entries.
|
|
36
|
+
* @param [options] - The `options` parameter is an optional object that can be passed to the
|
|
37
|
+
* constructor. It allows you to customize the behavior of the RBTree. It can include properties such
|
|
38
|
+
* as `compareKeys`, `compareValues`, `allowDuplicates`, etc. These properties define how the RBTree
|
|
39
|
+
* should compare keys and
|
|
54
40
|
*/
|
|
55
41
|
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K>);
|
|
56
|
-
protected
|
|
42
|
+
protected _SENTINEL: NODE;
|
|
57
43
|
/**
|
|
58
|
-
* The function returns the value of the
|
|
59
|
-
* @returns The method is returning the value of the `
|
|
44
|
+
* The function returns the value of the _SENTINEL property.
|
|
45
|
+
* @returns The method is returning the value of the `_SENTINEL` property.
|
|
60
46
|
*/
|
|
61
|
-
get
|
|
62
|
-
protected _root: NODE;
|
|
47
|
+
get SENTINEL(): NODE;
|
|
48
|
+
protected _root: NODE | undefined;
|
|
63
49
|
/**
|
|
64
|
-
* The function returns the root node.
|
|
65
|
-
* @returns The root node of the
|
|
50
|
+
* The function returns the root node of a tree or undefined if there is no root.
|
|
51
|
+
* @returns The root node of the tree structure, or undefined if there is no root node.
|
|
66
52
|
*/
|
|
67
|
-
get root(): NODE;
|
|
53
|
+
get root(): NODE | undefined;
|
|
68
54
|
protected _size: number;
|
|
69
55
|
/**
|
|
70
56
|
* The function returns the size of an object.
|
|
@@ -73,42 +59,62 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
73
59
|
get size(): number;
|
|
74
60
|
/**
|
|
75
61
|
* The function creates a new Red-Black Tree node with the specified key, value, and color.
|
|
76
|
-
* @param {K} key - The key parameter
|
|
77
|
-
*
|
|
62
|
+
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
63
|
+
* which is a generic type representing the key's data type.
|
|
78
64
|
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
79
|
-
* associated with the node. It is
|
|
80
|
-
* specific type when using the `createNode` method.
|
|
65
|
+
* associated with the key in the node. It is not required and can be omitted if not needed.
|
|
81
66
|
* @param {RBTNColor} color - The "color" parameter is used to specify the color of the node in a
|
|
82
|
-
* Red-Black Tree. It
|
|
67
|
+
* Red-Black Tree. It is an optional parameter with a default value of "RBTNColor.BLACK". The color
|
|
68
|
+
* can be either "RBTNColor.RED" or "RBTNColor.BLACK".
|
|
83
69
|
* @returns The method is returning a new instance of a RedBlackTreeNode with the specified key,
|
|
84
70
|
* value, and color.
|
|
85
71
|
*/
|
|
86
72
|
createNode(key: K, value?: V, color?: RBTNColor): NODE;
|
|
87
73
|
/**
|
|
88
|
-
* The function creates a Red-Black Tree with the
|
|
89
|
-
* @param
|
|
90
|
-
*
|
|
91
|
-
*
|
|
74
|
+
* The function creates a Red-Black Tree with the given options and returns it.
|
|
75
|
+
* @param [options] - The `options` parameter is an optional object that contains configuration
|
|
76
|
+
* options for creating the Red-Black Tree. It is of type `RBTreeOptions<K>`, where `K` represents
|
|
77
|
+
* the type of keys in the tree.
|
|
92
78
|
* @returns a new instance of a RedBlackTree object.
|
|
93
79
|
*/
|
|
94
80
|
createTree(options?: RBTreeOptions<K>): TREE;
|
|
95
81
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
*
|
|
101
|
-
*
|
|
82
|
+
* Time Complexity: O(1)
|
|
83
|
+
* Space Complexity: O(1)
|
|
84
|
+
*/
|
|
85
|
+
/**
|
|
86
|
+
* Time Complexity: O(1)
|
|
87
|
+
* Space Complexity: O(1)
|
|
88
|
+
*
|
|
89
|
+
* The function `keyValueOrEntryToNode` takes a key, value, or entry and returns a node if it is
|
|
90
|
+
* valid, otherwise it returns undefined.
|
|
91
|
+
* @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntry - The key, value, or entry to convert.
|
|
92
|
+
* @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntry` is a key).
|
|
93
|
+
* @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
|
|
102
94
|
*/
|
|
103
95
|
keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined;
|
|
104
96
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
|
|
97
|
+
* Time Complexity: O(1)
|
|
98
|
+
* Space Complexity: O(1)
|
|
99
|
+
* /
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Time Complexity: O(1)
|
|
103
|
+
* Space Complexity: O(1)
|
|
104
|
+
*
|
|
105
|
+
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
106
|
+
* @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntry - The object to check.
|
|
107
|
+
* @returns {boolean} - `true` if the object is a Red-Black Tree node, `false` otherwise.
|
|
109
108
|
*/
|
|
110
109
|
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
|
|
111
110
|
/**
|
|
111
|
+
* Time Complexity: O(1)
|
|
112
|
+
* Space Complexity: O(1)
|
|
113
|
+
*/
|
|
114
|
+
/**
|
|
115
|
+
* Time Complexity: O(1)
|
|
116
|
+
* Space Complexity: O(1)
|
|
117
|
+
*
|
|
112
118
|
* The function checks if a given node is a real node in a Red-Black Tree.
|
|
113
119
|
* @param {NODE | undefined} node - The `node` parameter is of type `NODE | undefined`, which means
|
|
114
120
|
* it can either be of type `NODE` or `undefined`.
|
|
@@ -118,21 +124,41 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
118
124
|
/**
|
|
119
125
|
* Time Complexity: O(log n)
|
|
120
126
|
* Space Complexity: O(1)
|
|
121
|
-
* On average (where n is the number of nodes in the tree)
|
|
122
127
|
*/
|
|
123
128
|
/**
|
|
124
129
|
* Time Complexity: O(log n)
|
|
125
130
|
* Space Complexity: O(1)
|
|
126
131
|
*
|
|
127
|
-
* The `
|
|
128
|
-
*
|
|
129
|
-
* @param
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
132
|
+
* The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
|
|
133
|
+
* callback function.
|
|
134
|
+
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
|
|
135
|
+
* that you want to search for in the binary search tree. It can be of any type that is compatible
|
|
136
|
+
* with the type of nodes in the tree.
|
|
137
|
+
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
138
|
+
* the tree. It is used to determine whether a node matches the given identifier. The `callback`
|
|
139
|
+
* function should take a node as its parameter and return a value that can be compared to the
|
|
140
|
+
* `identifier` parameter.
|
|
141
|
+
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
|
|
142
|
+
* search tree. It can be either a key or a node. If it is a key, it will be converted to a node
|
|
143
|
+
* using the `ensureNode` method. If it is not provided, the `root`
|
|
144
|
+
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
|
|
145
|
+
* be performed when searching for nodes in the binary search tree. It is an optional parameter and
|
|
146
|
+
* its default value is taken from the `iterationType` property of the class.
|
|
147
|
+
* @returns The method is returning a value of type `NODE | null | undefined`.
|
|
134
148
|
*/
|
|
135
|
-
|
|
149
|
+
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: BSTNKeyOrNode<K, NODE>, iterationType?: import("../../types").IterationType): NODE | null | undefined;
|
|
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 "clear" function sets the root node of a data structure to a sentinel value and resets the
|
|
159
|
+
* size counter to zero.
|
|
160
|
+
*/
|
|
161
|
+
clear(): void;
|
|
136
162
|
/**
|
|
137
163
|
* Time Complexity: O(log n)
|
|
138
164
|
* Space Complexity: O(1)
|
|
@@ -141,18 +167,16 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
141
167
|
* Time Complexity: O(log n)
|
|
142
168
|
* Space Complexity: O(1)
|
|
143
169
|
*
|
|
144
|
-
* The
|
|
145
|
-
* the
|
|
146
|
-
* @param
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* @
|
|
151
|
-
*
|
|
152
|
-
* on its identifier. The `callback` function is optional and defaults to `this._defaultOneParam
|
|
153
|
-
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
|
|
170
|
+
* The function adds a new node to a Red-Black Tree data structure and returns a boolean indicating
|
|
171
|
+
* whether the operation was successful.
|
|
172
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
|
|
173
|
+
* entry.
|
|
174
|
+
* @param {V} [value] - The `value` parameter is the value associated with the key that is being
|
|
175
|
+
* added to the tree.
|
|
176
|
+
* @returns The method is returning a boolean value. It returns true if the node was successfully
|
|
177
|
+
* added or updated, and false otherwise.
|
|
154
178
|
*/
|
|
155
|
-
|
|
179
|
+
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
|
|
156
180
|
/**
|
|
157
181
|
* Time Complexity: O(log n)
|
|
158
182
|
* Space Complexity: O(1)
|
|
@@ -161,24 +185,25 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
161
185
|
* Time Complexity: O(log n)
|
|
162
186
|
* Space Complexity: O(1)
|
|
163
187
|
*
|
|
164
|
-
* The function `
|
|
165
|
-
*
|
|
166
|
-
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the
|
|
167
|
-
*
|
|
168
|
-
* callback function
|
|
169
|
-
*
|
|
170
|
-
* @param {C} callback - The `callback` parameter is a function that
|
|
171
|
-
* the binary tree. It is
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* provided, the search will start from the root of the binary tree.
|
|
176
|
-
* @param iterationType - The `iterationType` parameter is a variable that determines the type of
|
|
177
|
-
* iteration to be performed when searching for nodes in the binary tree. It is used in the
|
|
178
|
-
* `getNodes` method, which is called within the `getNode` method.
|
|
179
|
-
* @returns a value of type `NODE`, `null`, or `undefined`.
|
|
188
|
+
* The function `delete` in a binary tree class deletes a node from the tree and fixes the tree if
|
|
189
|
+
* necessary.
|
|
190
|
+
* @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the
|
|
191
|
+
* identifier of the node that needs to be deleted from the binary tree. It can be of any type that
|
|
192
|
+
* is returned by the callback function `C`. It can also be `null` or `undefined` if the node to be
|
|
193
|
+
* deleted is not found.
|
|
194
|
+
* @param {C} callback - The `callback` parameter is a function that is used to retrieve a node from
|
|
195
|
+
* the binary tree based on its identifier. It is an optional parameter and if not provided, the
|
|
196
|
+
* `_defaultOneParamCallback` function is used as the default callback. The callback function should
|
|
197
|
+
* return the identifier of the node to
|
|
198
|
+
* @returns an array of BinaryTreeDeleteResult<NODE> objects.
|
|
180
199
|
*/
|
|
181
|
-
|
|
200
|
+
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C): BinaryTreeDeleteResult<NODE>[];
|
|
201
|
+
/**
|
|
202
|
+
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
203
|
+
* root.
|
|
204
|
+
* @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
|
|
205
|
+
*/
|
|
206
|
+
protected _setRoot(v: NODE | undefined): void;
|
|
182
207
|
/**
|
|
183
208
|
* Time Complexity: O(1)
|
|
184
209
|
* Space Complexity: O(1)
|
|
@@ -187,9 +212,15 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
187
212
|
* Time Complexity: O(1)
|
|
188
213
|
* Space Complexity: O(1)
|
|
189
214
|
*
|
|
190
|
-
* The
|
|
215
|
+
* The function replaces an old node with a new node while preserving the color of the old node.
|
|
216
|
+
* @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
|
|
217
|
+
* the data structure.
|
|
218
|
+
* @param {NODE} newNode - The `newNode` parameter is the new node that will replace the old node in
|
|
219
|
+
* the data structure.
|
|
220
|
+
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
221
|
+
* superclass, with the `oldNode` and `newNode` parameters.
|
|
191
222
|
*/
|
|
192
|
-
|
|
223
|
+
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
193
224
|
/**
|
|
194
225
|
* Time Complexity: O(log n)
|
|
195
226
|
* Space Complexity: O(1)
|
|
@@ -198,19 +229,14 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
198
229
|
* Time Complexity: O(log n)
|
|
199
230
|
* Space Complexity: O(1)
|
|
200
231
|
*
|
|
201
|
-
* The function
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* The function sets the root node of a tree structure and updates the parent property of the new
|
|
209
|
-
* root node.
|
|
210
|
-
* @param {NODE} v - The parameter "v" is of type "NODE", which represents a node in a data
|
|
211
|
-
* structure.
|
|
232
|
+
* The `_insert` function inserts or updates a node in a binary search tree and performs necessary
|
|
233
|
+
* fix-ups to maintain the red-black tree properties.
|
|
234
|
+
* @param {NODE} node - The `node` parameter represents the node that needs to be inserted into a
|
|
235
|
+
* binary search tree. It contains a `key` property that is used to determine the position of the
|
|
236
|
+
* node in the tree.
|
|
237
|
+
* @returns {'inserted' | 'updated'} - The result of the insertion.
|
|
212
238
|
*/
|
|
213
|
-
protected
|
|
239
|
+
protected _insert(node: NODE): 'inserted' | 'updated';
|
|
214
240
|
/**
|
|
215
241
|
* Time Complexity: O(1)
|
|
216
242
|
* Space Complexity: O(1)
|
|
@@ -219,23 +245,25 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
219
245
|
* Time Complexity: O(1)
|
|
220
246
|
* Space Complexity: O(1)
|
|
221
247
|
*
|
|
222
|
-
* The function
|
|
223
|
-
* @param {
|
|
248
|
+
* The function `_transplant` is used to replace a node `u` with another node `v` in a binary tree.
|
|
249
|
+
* @param {NODE} u - The parameter "u" represents a node in a binary tree.
|
|
250
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`, which means it can
|
|
251
|
+
* either be a `NODE` object or `undefined`.
|
|
224
252
|
*/
|
|
225
|
-
protected
|
|
253
|
+
protected _transplant(u: NODE, v: NODE | undefined): void;
|
|
226
254
|
/**
|
|
227
|
-
* Time Complexity: O(
|
|
255
|
+
* Time Complexity: O(log n)
|
|
228
256
|
* Space Complexity: O(1)
|
|
229
257
|
*/
|
|
230
258
|
/**
|
|
231
|
-
* Time Complexity: O(
|
|
259
|
+
* Time Complexity: O(log n)
|
|
232
260
|
* Space Complexity: O(1)
|
|
233
261
|
*
|
|
234
|
-
* The function
|
|
235
|
-
* @param {
|
|
236
|
-
*
|
|
262
|
+
* The `_insertFixup` function is used to fix the Red-Black Tree after inserting a new node.
|
|
263
|
+
* @param {NODE | undefined} z - The parameter `z` represents a node in the Red-Black Tree. It can
|
|
264
|
+
* either be a valid node object or `undefined`.
|
|
237
265
|
*/
|
|
238
|
-
protected
|
|
266
|
+
protected _insertFixup(z: NODE | undefined): void;
|
|
239
267
|
/**
|
|
240
268
|
* Time Complexity: O(log n)
|
|
241
269
|
* Space Complexity: O(1)
|
|
@@ -244,23 +272,27 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
244
272
|
* Time Complexity: O(log n)
|
|
245
273
|
* Space Complexity: O(1)
|
|
246
274
|
*
|
|
247
|
-
* The `
|
|
248
|
-
*
|
|
249
|
-
*
|
|
275
|
+
* The `_deleteFixup` function is used to fix the red-black tree after a node deletion by adjusting
|
|
276
|
+
* the colors and performing rotations.
|
|
277
|
+
* @param {NODE | undefined} node - The `node` parameter represents a node in a Red-Black Tree data
|
|
278
|
+
* structure. It can be either a valid node object or `undefined`.
|
|
279
|
+
* @returns The function does not return any value. It has a return type of `void`.
|
|
250
280
|
*/
|
|
251
|
-
protected
|
|
281
|
+
protected _deleteFixup(node: NODE | undefined): void;
|
|
252
282
|
/**
|
|
253
|
-
* Time Complexity: O(
|
|
283
|
+
* Time Complexity: O(1)
|
|
254
284
|
* Space Complexity: O(1)
|
|
255
285
|
*/
|
|
256
286
|
/**
|
|
257
|
-
* Time Complexity: O(
|
|
287
|
+
* Time Complexity: O(1)
|
|
258
288
|
* Space Complexity: O(1)
|
|
259
289
|
*
|
|
260
|
-
* The
|
|
261
|
-
* @param {
|
|
290
|
+
* The `_leftRotate` function performs a left rotation on a given node in a binary tree.
|
|
291
|
+
* @param {NODE | undefined} x - The parameter `x` is of type `NODE | undefined`. It represents a
|
|
292
|
+
* node in a binary tree or `undefined` if there is no node.
|
|
293
|
+
* @returns void, which means it does not return any value.
|
|
262
294
|
*/
|
|
263
|
-
protected
|
|
295
|
+
protected _leftRotate(x: NODE | undefined): void;
|
|
264
296
|
/**
|
|
265
297
|
* Time Complexity: O(1)
|
|
266
298
|
* Space Complexity: O(1)
|
|
@@ -269,19 +301,10 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
269
301
|
* Time Complexity: O(1)
|
|
270
302
|
* Space Complexity: O(1)
|
|
271
303
|
*
|
|
272
|
-
* The
|
|
273
|
-
* @param {
|
|
274
|
-
*
|
|
275
|
-
|
|
276
|
-
protected _rbTransplant(u: NODE, v: NODE): void;
|
|
277
|
-
/**
|
|
278
|
-
* The function replaces an old node with a new node while preserving the color of the old node.
|
|
279
|
-
* @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in a
|
|
280
|
-
* data structure. It is of type `NODE`, which is the type of the nodes in the data structure.
|
|
281
|
-
* @param {NODE} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
|
|
282
|
-
* data structure.
|
|
283
|
-
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
284
|
-
* superclass, passing in the `oldNode` and `newNode` as arguments.
|
|
304
|
+
* The `_rightRotate` function performs a right rotation on a given node in a binary tree.
|
|
305
|
+
* @param {NODE | undefined} y - The parameter `y` is of type `NODE | undefined`. It represents a
|
|
306
|
+
* node in a binary tree or `undefined` if there is no node.
|
|
307
|
+
* @returns void, which means it does not return any value.
|
|
285
308
|
*/
|
|
286
|
-
protected
|
|
309
|
+
protected _rightRotate(y: NODE | undefined): void;
|
|
287
310
|
}
|