binary-tree-typed 1.53.8 → 1.54.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/data-structures/base/iterable-entry-base.js +4 -4
  2. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
  3. package/dist/data-structures/binary-tree/avl-tree-counter.js +407 -0
  4. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -170
  5. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +133 -328
  6. package/dist/data-structures/binary-tree/avl-tree.d.ts +103 -69
  7. package/dist/data-structures/binary-tree/avl-tree.js +130 -70
  8. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.js +3 -0
  10. package/dist/data-structures/binary-tree/binary-tree.d.ts +268 -202
  11. package/dist/data-structures/binary-tree/binary-tree.js +311 -263
  12. package/dist/data-structures/binary-tree/bst.d.ts +145 -121
  13. package/dist/data-structures/binary-tree/bst.js +195 -145
  14. package/dist/data-structures/binary-tree/index.d.ts +2 -0
  15. package/dist/data-structures/binary-tree/index.js +2 -0
  16. package/dist/data-structures/binary-tree/red-black-tree.d.ts +100 -72
  17. package/dist/data-structures/binary-tree/red-black-tree.js +127 -107
  18. package/dist/data-structures/binary-tree/tree-counter.d.ts +212 -0
  19. package/dist/data-structures/binary-tree/tree-counter.js +444 -0
  20. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +78 -170
  21. package/dist/data-structures/binary-tree/tree-multi-map.js +140 -362
  22. package/dist/data-structures/graph/abstract-graph.js +2 -2
  23. package/dist/data-structures/graph/directed-graph.d.ts +3 -0
  24. package/dist/data-structures/graph/directed-graph.js +3 -0
  25. package/dist/data-structures/graph/map-graph.d.ts +3 -0
  26. package/dist/data-structures/graph/map-graph.js +3 -0
  27. package/dist/data-structures/graph/undirected-graph.d.ts +3 -0
  28. package/dist/data-structures/graph/undirected-graph.js +3 -0
  29. package/dist/data-structures/hash/hash-map.d.ts +1 -1
  30. package/dist/data-structures/hash/hash-map.js +5 -5
  31. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +10 -10
  32. package/dist/data-structures/linked-list/doubly-linked-list.js +12 -12
  33. package/dist/data-structures/linked-list/singly-linked-list.d.ts +13 -10
  34. package/dist/data-structures/linked-list/singly-linked-list.js +19 -16
  35. package/dist/data-structures/linked-list/skip-linked-list.d.ts +3 -0
  36. package/dist/data-structures/linked-list/skip-linked-list.js +3 -0
  37. package/dist/data-structures/matrix/matrix.d.ts +3 -0
  38. package/dist/data-structures/matrix/matrix.js +3 -0
  39. package/dist/data-structures/matrix/navigator.d.ts +3 -0
  40. package/dist/data-structures/matrix/navigator.js +3 -0
  41. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
  42. package/dist/data-structures/priority-queue/max-priority-queue.js +3 -0
  43. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
  44. package/dist/data-structures/priority-queue/min-priority-queue.js +3 -0
  45. package/dist/data-structures/trie/trie.d.ts +0 -4
  46. package/dist/data-structures/trie/trie.js +0 -4
  47. package/dist/interfaces/binary-tree.d.ts +8 -8
  48. package/dist/types/data-structures/base/base.d.ts +1 -1
  49. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  50. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
  51. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -4
  52. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -3
  53. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -3
  54. package/dist/types/data-structures/binary-tree/bst.d.ts +4 -4
  55. package/dist/types/data-structures/binary-tree/index.d.ts +2 -0
  56. package/dist/types/data-structures/binary-tree/index.js +2 -0
  57. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -5
  58. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  59. package/dist/types/data-structures/binary-tree/tree-counter.js +2 -0
  60. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -5
  61. package/package.json +2 -2
  62. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  63. package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
  64. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +151 -370
  65. package/src/data-structures/binary-tree/avl-tree.ts +162 -105
  66. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
  67. package/src/data-structures/binary-tree/binary-tree.ts +488 -416
  68. package/src/data-structures/binary-tree/bst.ts +270 -234
  69. package/src/data-structures/binary-tree/index.ts +2 -0
  70. package/src/data-structures/binary-tree/red-black-tree.ts +170 -145
  71. package/src/data-structures/binary-tree/tree-counter.ts +504 -0
  72. package/src/data-structures/binary-tree/tree-multi-map.ts +159 -401
  73. package/src/data-structures/graph/abstract-graph.ts +2 -2
  74. package/src/data-structures/graph/directed-graph.ts +3 -0
  75. package/src/data-structures/graph/map-graph.ts +3 -0
  76. package/src/data-structures/graph/undirected-graph.ts +3 -0
  77. package/src/data-structures/hash/hash-map.ts +7 -7
  78. package/src/data-structures/linked-list/doubly-linked-list.ts +13 -13
  79. package/src/data-structures/linked-list/singly-linked-list.ts +20 -17
  80. package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
  81. package/src/data-structures/matrix/matrix.ts +3 -0
  82. package/src/data-structures/matrix/navigator.ts +3 -0
  83. package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
  84. package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
  85. package/src/data-structures/trie/trie.ts +0 -4
  86. package/src/interfaces/binary-tree.ts +10 -21
  87. package/src/types/data-structures/base/base.ts +1 -1
  88. package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
  89. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -6
  90. package/src/types/data-structures/binary-tree/avl-tree.ts +0 -5
  91. package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
  92. package/src/types/data-structures/binary-tree/bst.ts +6 -6
  93. package/src/types/data-structures/binary-tree/index.ts +2 -0
  94. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -7
  95. package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
  96. package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -7
@@ -6,3 +6,5 @@ export * from './avl-tree';
6
6
  export * from './red-black-tree';
7
7
  export * from './avl-tree-multi-map';
8
8
  export * from './tree-multi-map';
9
+ export * from './tree-counter';
10
+ export * from './avl-tree-counter';
@@ -22,3 +22,5 @@ __exportStar(require("./avl-tree"), exports);
22
22
  __exportStar(require("./red-black-tree"), exports);
23
23
  __exportStar(require("./avl-tree-multi-map"), exports);
24
24
  __exportStar(require("./tree-multi-map"), exports);
25
+ __exportStar(require("./tree-counter"), exports);
26
+ __exportStar(require("./avl-tree-counter"), exports);
@@ -1,30 +1,25 @@
1
- import type { BinaryTreeDeleteResult, BTNRep, CRUD, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
1
+ import type { BinaryTreeDeleteResult, BTNRep, CRUD, EntryCallback, OptNodeOrNull, RBTNColor, RedBlackTreeOptions } from '../../types';
2
2
  import { BST, BSTNode } from './bst';
3
3
  import { IBinaryTree } from '../../interfaces';
4
- export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
4
+ export declare class RedBlackTreeNode<K = any, V = any> extends BSTNode<K, V> {
5
5
  /**
6
- * The constructor function initializes a Red-Black Tree Node with a key, an optional value, and a
7
- * color.
8
- * @param {K} key - The key parameter is of type K and represents the key of the node in the
9
- * Red-Black Tree.
10
- * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
11
- * associated with the key in the Red-Black Tree Node. It is not required and can be omitted when
12
- * creating a new instance of the Red-Black Tree Node.
13
- * @param {RBTNColor} color - The `color` parameter is used to specify the color of the Red-Black
14
- * Tree Node. It is an optional parameter with a default value of `'BLACK'`.
6
+ * The constructor initializes a node with a key, value, and color for a Red-Black Tree.
7
+ * @param {K} key - The `key` parameter is a key of type `K` that is used to identify the node in a
8
+ * Red-Black Tree data structure.
9
+ * @param {V} [value] - The `value` parameter in the constructor is an optional parameter of type
10
+ * `V`. It represents the value associated with the key in the data structure being constructed.
11
+ * @param {RBTNColor} [color=BLACK] - The `color` parameter in the constructor is used to specify the
12
+ * color of the node in a Red-Black Tree. It has a default value of 'BLACK' if not provided
13
+ * explicitly.
15
14
  */
16
15
  constructor(key: K, value?: V, color?: RBTNColor);
17
- protected _color: RBTNColor;
18
- /**
19
- * The function returns the color value of a variable.
20
- * @returns The color value stored in the private variable `_color`.
21
- */
22
- get color(): RBTNColor;
23
- /**
24
- * The function sets the color property to the specified value.
25
- * @param {RBTNColor} value - The value parameter is of type RBTNColor.
26
- */
27
- set color(value: RBTNColor);
16
+ parent?: RedBlackTreeNode<K, V>;
17
+ _left?: OptNodeOrNull<RedBlackTreeNode<K, V>>;
18
+ get left(): OptNodeOrNull<RedBlackTreeNode<K, V>>;
19
+ set left(v: OptNodeOrNull<RedBlackTreeNode<K, V>>);
20
+ _right?: OptNodeOrNull<RedBlackTreeNode<K, V>>;
21
+ get right(): OptNodeOrNull<RedBlackTreeNode<K, V>>;
22
+ set right(v: OptNodeOrNull<RedBlackTreeNode<K, V>>);
28
23
  }
29
24
  /**
30
25
  * 1. Efficient self-balancing, but not completely balanced. Compared with AVLTree, the addition and deletion efficiency is high but the query efficiency is slightly lower.
@@ -79,25 +74,25 @@ export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTre
79
74
  * );
80
75
  * console.log(stocksInRange); // ['GOOGL', 'MSFT', 'META']
81
76
  */
82
- export declare class RedBlackTree<K = any, V = any, R = object, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
83
- /**
84
- * This is the constructor function for a Red-Black Tree data structure in TypeScript.
85
- * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
86
- * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
87
- * initialize the RBTree with the provided elements.
88
- * @param [options] - The `options` parameter is an optional object that can be passed to the
89
- * constructor. It is of type `RBTreeOptions<K, V, R>`. This object can contain various options for
90
- * configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
91
- * depend on the implementation
92
- */
93
- constructor(keysNodesEntriesOrRaws?: Iterable<R | BTNRep<K, V, NODE>>, options?: RBTreeOptions<K, V, R>);
94
- protected _root: NODE | undefined;
77
+ export declare class RedBlackTree<K = any, V = any, R = object, MK = any, MV = any, MR = object> extends BST<K, V, R, MK, MV, MR> implements IBinaryTree<K, V, R, MK, MV, MR> {
95
78
  /**
96
- * The function returns the root node of a tree or undefined if there is no root.
97
- * @returns The root node of the tree structure, or undefined if there is no root node.
79
+ * This TypeScript constructor initializes a Red-Black Tree with optional keys, nodes, entries, or
80
+ * raw data.
81
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
82
+ * iterable that can contain either `BTNRep<K, V, RedBlackTreeNode<K, V>>` objects or `R` objects. It
83
+ * is used to initialize the Red-Black Tree with keys, nodes, entries, or
84
+ * @param [options] - The `options` parameter in the constructor is of type `RedBlackTreeOptions<K,
85
+ * V, R>`. It is an optional parameter that allows you to specify additional options for the
86
+ * RedBlackTree class. These options could include configuration settings, behavior customization, or
87
+ * any other parameters that are specific to
98
88
  */
99
- get root(): NODE | undefined;
89
+ constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V, RedBlackTreeNode<K, V>> | R>, options?: RedBlackTreeOptions<K, V, R>);
90
+ protected _root: RedBlackTreeNode<K, V> | undefined;
91
+ get root(): RedBlackTreeNode<K, V> | undefined;
100
92
  /**
93
+ * Time Complexity: O(1)
94
+ * Space Complexity: O(1)
95
+ *
101
96
  * The function creates a new Red-Black Tree node with the specified key, value, and color.
102
97
  * @param {K} key - The key parameter represents the key value of the node being created. It is of
103
98
  * type K, which is a generic type that can be replaced with any specific type when using the
@@ -111,25 +106,28 @@ export declare class RedBlackTree<K = any, V = any, R = object, NODE extends Red
111
106
  * @returns A new instance of a RedBlackTreeNode with the specified key, value, and color is being
112
107
  * returned.
113
108
  */
114
- createNode(key: K, value?: V, color?: RBTNColor): NODE;
109
+ createNode(key: K, value?: V, color?: RBTNColor): RedBlackTreeNode<K, V>;
115
110
  /**
111
+ * Time Complexity: O(1)
112
+ * Space Complexity: O(1)
113
+ *
116
114
  * The function creates a new Red-Black Tree with the specified options.
117
115
  * @param [options] - The `options` parameter is an optional object that contains additional
118
116
  * configuration options for creating the Red-Black Tree. It has the following properties:
119
117
  * @returns a new instance of a RedBlackTree object.
120
118
  */
121
- createTree(options?: RBTreeOptions<K, V, R>): TREE;
119
+ createTree(options?: RedBlackTreeOptions<K, V, R>): RedBlackTree<K, V, R, MK, MV, MR>;
122
120
  /**
123
121
  * Time Complexity: O(1)
124
122
  * Space Complexity: O(1)
125
123
  *
126
124
  * The function checks if the input is an instance of the RedBlackTreeNode class.
127
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
128
- * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
129
- * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
125
+ * @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
126
+ * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
127
+ * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
130
128
  * an instance of the `RedBlackTreeNode` class.
131
129
  */
132
- isNode(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is NODE;
130
+ isNode(keyNodeOrEntry: BTNRep<K, V, RedBlackTreeNode<K, V>>): keyNodeOrEntry is RedBlackTreeNode<K, V>;
133
131
  /**
134
132
  * Time Complexity: O(1)
135
133
  * Space Complexity: O(1)
@@ -140,12 +138,12 @@ export declare class RedBlackTree<K = any, V = any, R = object, NODE extends Red
140
138
  clear(): void;
141
139
  /**
142
140
  * Time Complexity: O(log n)
143
- * Space Complexity: O(1)
141
+ * Space Complexity: O(log n)
144
142
  *
145
143
  * The function adds a new node to a binary search tree and returns true if the node was successfully
146
144
  * added.
147
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
148
- * `keyNodeEntryOrRaw` can accept a value of type `R` or `BTNRep<K, V, NODE>`.
145
+ * @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
146
+ * `keyNodeOrEntry` can accept a value of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
149
147
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
150
148
  * the key in the data structure. It represents the value that you want to add or update in the data
151
149
  * structure.
@@ -153,106 +151,136 @@ export declare class RedBlackTree<K = any, V = any, R = object, NODE extends Red
153
151
  * the method returns true. If the node already exists and its value is updated, the method also
154
152
  * returns true. If the node cannot be added or updated, the method returns false.
155
153
  */
156
- add(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): boolean;
154
+ add(keyNodeOrEntry: BTNRep<K, V, RedBlackTreeNode<K, V>>, value?: V): boolean;
157
155
  /**
158
156
  * Time Complexity: O(log n)
159
- * Space Complexity: O(1)
157
+ * Space Complexity: O(log n)
160
158
  *
161
159
  * The function overrides the delete method in a binary tree data structure to remove a node based on
162
160
  * a given predicate and maintain the binary search tree properties.
163
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
161
+ * @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
164
162
  * parameter in the `override delete` method is used to specify the condition or key based on which a
165
163
  * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
166
164
  * function that determines which node(s) should be deleted.
167
- * @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<NODE>`
165
+ * @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>`
168
166
  * objects. Each object in the array contains information about the deleted node and whether
169
167
  * balancing is needed.
170
168
  */
171
- delete(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[];
169
+ delete(keyNodeOrEntry: BTNRep<K, V, RedBlackTreeNode<K, V>>): BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>[];
170
+ /**
171
+ * Time Complexity: O(n)
172
+ * Space Complexity: O(n)
173
+ *
174
+ * The `map` function in TypeScript overrides the default behavior to create a new Red-Black Tree by
175
+ * applying a callback to each entry in the original tree.
176
+ * @param callback - A function that will be called for each entry in the tree, with parameters
177
+ * representing the key, value, index, and the tree itself. It should return an entry for the new
178
+ * tree.
179
+ * @param [options] - The `options` parameter in the `map` method is of type `RedBlackTreeOptions<MK, MV,
180
+ * MR>`. This parameter allows you to specify additional options or configurations for the Red-Black
181
+ * Tree that will be created during the mapping process. These options could include things like
182
+ * custom comparators
183
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
184
+ * the value of `this` when executing the `callback` function. It allows you to set the context
185
+ * (value of `this`) for the callback function. This can be useful when you want to access properties
186
+ * or
187
+ * @returns A new Red-Black Tree is being returned, where each entry has been transformed using the
188
+ * provided callback function.
189
+ */
190
+ map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: RedBlackTreeOptions<MK, MV, MR>, thisArg?: any): RedBlackTree<MK, MV, MR>;
191
+ /**
192
+ * Time Complexity: O(n)
193
+ * Space Complexity: O(n)
194
+ *
195
+ * The function `clone` overrides the default cloning behavior to create a deep copy of a tree
196
+ * structure.
197
+ * @returns The `cloned` object is being returned.
198
+ */
199
+ clone(): RedBlackTree<K, V, R, MK, MV, MR>;
172
200
  /**
173
201
  * Time Complexity: O(1)
174
202
  * Space Complexity: O(1)
175
203
  *
176
204
  * The function sets the root of a tree-like structure and updates the parent property of the new
177
205
  * root.
178
- * @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
206
+ * @param {RedBlackTreeNode<K, V> | undefined} v - v is a parameter of type RedBlackTreeNode<K, V> or undefined.
179
207
  */
180
- protected _setRoot(v: NODE | undefined): void;
208
+ protected _setRoot(v: RedBlackTreeNode<K, V> | undefined): void;
181
209
  /**
182
210
  * Time Complexity: O(1)
183
211
  * Space Complexity: O(1)
184
212
  *
185
213
  * The function replaces an old node with a new node while preserving the color of the old node.
186
- * @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
214
+ * @param {RedBlackTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
187
215
  * the data structure.
188
- * @param {NODE} newNode - The `newNode` parameter is of type `NODE`, which represents a node in a
216
+ * @param {RedBlackTreeNode<K, V>} newNode - The `newNode` parameter is of type `RedBlackTreeNode<K, V>`, which represents a node in a
189
217
  * data structure.
190
218
  * @returns The method is returning the result of calling the `_replaceNode` method from the
191
219
  * superclass, with the `oldNode` and `newNode` parameters.
192
220
  */
193
- protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
221
+ protected _replaceNode(oldNode: RedBlackTreeNode<K, V>, newNode: RedBlackTreeNode<K, V>): RedBlackTreeNode<K, V>;
194
222
  /**
195
223
  * Time Complexity: O(log n)
196
- * Space Complexity: O(1)
224
+ * Space Complexity: O(log n)
197
225
  *
198
226
  * The `_insert` function inserts a node into a binary search tree and performs necessary fix-ups to
199
227
  * maintain the red-black tree properties.
200
- * @param {NODE} node - The `node` parameter represents the node that needs to be inserted into the
228
+ * @param {RedBlackTreeNode<K, V>} node - The `node` parameter represents the node that needs to be inserted into the
201
229
  * binary search tree.
202
230
  * @returns a string value indicating the result of the insertion operation. It can return either
203
231
  * 'UPDATED' if the node with the same key already exists and was updated, or 'CREATED' if a new node
204
232
  * was created and inserted into the tree.
205
233
  */
206
- protected _insert(node: NODE): CRUD;
234
+ protected _insert(node: RedBlackTreeNode<K, V>): CRUD;
207
235
  /**
208
236
  * Time Complexity: O(1)
209
237
  * Space Complexity: O(1)
210
238
  *
211
239
  * The function `_transplant` is used to replace a node `u` with another node `v` in a binary tree.
212
- * @param {NODE} u - The parameter "u" represents a node in a binary tree.
213
- * @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`, which means it can
214
- * either be a `NODE` object or `undefined`.
240
+ * @param {RedBlackTreeNode<K, V>} u - The parameter "u" represents a node in a binary tree.
241
+ * @param {RedBlackTreeNode<K, V> | undefined} v - The parameter `v` is of type `RedBlackTreeNode<K, V> | undefined`, which means it can
242
+ * either be a `RedBlackTreeNode<K, V>` object or `undefined`.
215
243
  */
216
- protected _transplant(u: NODE, v: NODE | undefined): void;
244
+ protected _transplant(u: RedBlackTreeNode<K, V>, v: RedBlackTreeNode<K, V> | undefined): void;
217
245
  /**
218
246
  * Time Complexity: O(log n)
219
247
  * Space Complexity: O(1)
220
248
  *
221
249
  * The `_insertFixup` function is used to fix the Red-Black Tree after inserting a new node.
222
- * @param {NODE | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
250
+ * @param {RedBlackTreeNode<K, V> | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
223
251
  * structure. It can either be a valid node or `undefined`.
224
252
  */
225
- protected _insertFixup(z: NODE | undefined): void;
253
+ protected _insertFixup(z: RedBlackTreeNode<K, V> | undefined): void;
226
254
  /**
227
255
  * Time Complexity: O(log n)
228
256
  * Space Complexity: O(1)
229
257
  *
230
258
  * The `_deleteFixup` function is used to fix the red-black tree after a node deletion by adjusting
231
259
  * the colors and performing rotations.
232
- * @param {NODE | undefined} node - The `node` parameter represents a node in a binary tree. It can
260
+ * @param {RedBlackTreeNode<K, V> | undefined} node - The `node` parameter represents a node in a binary tree. It can
233
261
  * be either a valid node object or `undefined`.
234
262
  * @returns The function does not return any value. It has a return type of `void`, which means it
235
263
  * does not return anything.
236
264
  */
237
- protected _deleteFixup(node: NODE | undefined): void;
265
+ protected _deleteFixup(node: RedBlackTreeNode<K, V> | undefined): void;
238
266
  /**
239
267
  * Time Complexity: O(1)
240
268
  * Space Complexity: O(1)
241
269
  *
242
270
  * The `_leftRotate` function performs a left rotation on a given node in a binary tree.
243
- * @param {NODE | undefined} x - The parameter `x` is of type `NODE | undefined`. It represents a
271
+ * @param {RedBlackTreeNode<K, V> | undefined} x - The parameter `x` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
244
272
  * node in a binary tree or `undefined` if there is no node.
245
273
  * @returns void, which means it does not return any value.
246
274
  */
247
- protected _leftRotate(x: NODE | undefined): void;
275
+ protected _leftRotate(x: RedBlackTreeNode<K, V> | undefined): void;
248
276
  /**
249
277
  * Time Complexity: O(1)
250
278
  * Space Complexity: O(1)
251
279
  *
252
280
  * The `_rightRotate` function performs a right rotation on a given node in a binary tree.
253
- * @param {NODE | undefined} y - The parameter `y` is of type `NODE | undefined`. It represents a
281
+ * @param {RedBlackTreeNode<K, V> | undefined} y - The parameter `y` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
254
282
  * node in a binary tree or `undefined` if there is no node.
255
283
  * @returns void, which means it does not return any value.
256
284
  */
257
- protected _rightRotate(y: NODE | undefined): void;
285
+ protected _rightRotate(y: RedBlackTreeNode<K, V> | undefined): void;
258
286
  }