queue-typed 2.0.5 → 2.1.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/README.md +1 -1
- package/dist/data-structures/base/iterable-element-base.d.ts +186 -83
- package/dist/data-structures/base/iterable-element-base.js +149 -107
- package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
- package/dist/data-structures/base/iterable-entry-base.js +59 -116
- package/dist/data-structures/base/linear-base.d.ts +250 -192
- package/dist/data-structures/base/linear-base.js +137 -274
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
- package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
- package/dist/data-structures/binary-tree/avl-tree.js +208 -195
- package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
- package/dist/data-structures/binary-tree/binary-tree.js +598 -869
- package/dist/data-structures/binary-tree/bst.d.ts +258 -306
- package/dist/data-structures/binary-tree/bst.js +505 -481
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
- package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
- package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
- package/dist/data-structures/binary-tree/tree-counter.js +172 -203
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
- package/dist/data-structures/graph/abstract-graph.js +267 -237
- package/dist/data-structures/graph/directed-graph.d.ts +108 -224
- package/dist/data-structures/graph/directed-graph.js +146 -233
- package/dist/data-structures/graph/map-graph.d.ts +49 -55
- package/dist/data-structures/graph/map-graph.js +56 -59
- package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
- package/dist/data-structures/graph/undirected-graph.js +129 -149
- package/dist/data-structures/hash/hash-map.d.ts +164 -338
- package/dist/data-structures/hash/hash-map.js +270 -457
- package/dist/data-structures/heap/heap.d.ts +214 -289
- package/dist/data-structures/heap/heap.js +340 -349
- package/dist/data-structures/heap/max-heap.d.ts +11 -47
- package/dist/data-structures/heap/max-heap.js +11 -66
- package/dist/data-structures/heap/min-heap.d.ts +12 -47
- package/dist/data-structures/heap/min-heap.js +11 -66
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
- package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
- package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
- package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
- package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
- package/dist/data-structures/priority-queue/priority-queue.js +8 -83
- package/dist/data-structures/queue/deque.d.ts +227 -254
- package/dist/data-structures/queue/deque.js +309 -348
- package/dist/data-structures/queue/queue.d.ts +180 -201
- package/dist/data-structures/queue/queue.js +265 -248
- package/dist/data-structures/stack/stack.d.ts +124 -102
- package/dist/data-structures/stack/stack.js +181 -125
- package/dist/data-structures/trie/trie.d.ts +164 -165
- package/dist/data-structures/trie/trie.js +189 -172
- package/dist/interfaces/binary-tree.d.ts +56 -6
- package/dist/interfaces/graph.d.ts +16 -0
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.js +2 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +238 -115
- package/src/data-structures/base/iterable-entry-base.ts +96 -120
- package/src/data-structures/base/linear-base.ts +271 -277
- package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
- package/src/data-structures/binary-tree/avl-tree.ts +239 -206
- package/src/data-structures/binary-tree/binary-tree.ts +664 -893
- package/src/data-structures/binary-tree/bst.ts +568 -570
- package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
- package/src/data-structures/binary-tree/tree-counter.ts +199 -218
- package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
- package/src/data-structures/graph/abstract-graph.ts +339 -264
- package/src/data-structures/graph/directed-graph.ts +146 -236
- package/src/data-structures/graph/map-graph.ts +63 -60
- package/src/data-structures/graph/undirected-graph.ts +129 -152
- package/src/data-structures/hash/hash-map.ts +274 -496
- package/src/data-structures/heap/heap.ts +389 -402
- package/src/data-structures/heap/max-heap.ts +12 -76
- package/src/data-structures/heap/min-heap.ts +13 -76
- package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
- package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
- package/src/data-structures/priority-queue/priority-queue.ts +3 -92
- package/src/data-structures/queue/deque.ts +381 -357
- package/src/data-structures/queue/queue.ts +310 -264
- package/src/data-structures/stack/stack.ts +217 -131
- package/src/data-structures/trie/trie.ts +240 -175
- package/src/interfaces/binary-tree.ts +240 -6
- package/src/interfaces/graph.ts +37 -0
- package/src/types/data-structures/base/base.ts +5 -5
- package/src/types/data-structures/graph/abstract-graph.ts +5 -0
- package/src/types/utils/utils.ts +2 -0
- package/src/utils/utils.ts +9 -14
|
@@ -1,27 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import type { BinaryTreeDeleteResult, BinaryTreeOptions, CRUD, EntryCallback, RBTNColor, RedBlackTreeOptions } from '../../types';
|
|
2
9
|
import { BST, BSTNode } from './bst';
|
|
3
10
|
import { IBinaryTree } from '../../interfaces';
|
|
4
11
|
export declare class RedBlackTreeNode<K = any, V = any> extends BSTNode<K, V> {
|
|
5
12
|
parent?: RedBlackTreeNode<K, V>;
|
|
6
13
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
9
|
-
*
|
|
10
|
-
* @param
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
13
|
-
* color of the node in a Red-Black Tree. It has a default value of 'BLACK' if not provided
|
|
14
|
-
* explicitly.
|
|
14
|
+
* Create a Red-Black Tree and optionally bulk-insert items.
|
|
15
|
+
* @remarks Time O(n log n), Space O(n)
|
|
16
|
+
* @param key - See parameter type for details.
|
|
17
|
+
* @param [value]- See parameter type for details.
|
|
18
|
+
* @param color - See parameter type for details.
|
|
19
|
+
* @returns New RedBlackTree instance.
|
|
15
20
|
*/
|
|
16
21
|
constructor(key: K, value?: V, color?: RBTNColor);
|
|
17
22
|
_left?: RedBlackTreeNode<K, V> | null | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Get the left child pointer.
|
|
25
|
+
* @remarks Time O(1), Space O(1)
|
|
26
|
+
* @returns Left child node, or null/undefined.
|
|
27
|
+
*/
|
|
18
28
|
get left(): RedBlackTreeNode<K, V> | null | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Set the left child and update its parent pointer.
|
|
31
|
+
* @remarks Time O(1), Space O(1)
|
|
32
|
+
* @param v - New left node, or null/undefined.
|
|
33
|
+
* @returns void
|
|
34
|
+
*/
|
|
19
35
|
set left(v: RedBlackTreeNode<K, V> | null | undefined);
|
|
20
36
|
_right?: RedBlackTreeNode<K, V> | null | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Get the right child pointer.
|
|
39
|
+
* @remarks Time O(1), Space O(1)
|
|
40
|
+
* @returns Right child node, or null/undefined.
|
|
41
|
+
*/
|
|
21
42
|
get right(): RedBlackTreeNode<K, V> | null | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Set the right child and update its parent pointer.
|
|
45
|
+
* @remarks Time O(1), Space O(1)
|
|
46
|
+
* @param v - New right node, or null/undefined.
|
|
47
|
+
* @returns void
|
|
48
|
+
*/
|
|
22
49
|
set right(v: RedBlackTreeNode<K, V> | null | undefined);
|
|
23
50
|
}
|
|
24
51
|
/**
|
|
52
|
+
* RRRRed-Black Tree (self-balancing BST) supporting map-like mode and stable O(log n) updates.
|
|
53
|
+
* @remarks Time O(1), Space O(1)
|
|
54
|
+
* @template K
|
|
55
|
+
* @template V
|
|
56
|
+
* @template R
|
|
25
57
|
* 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.
|
|
26
58
|
* 2. It is BST itself. Compared with Heap which is not completely ordered, RedBlackTree is completely ordered.
|
|
27
59
|
* @example
|
|
@@ -68,213 +100,109 @@ export declare class RedBlackTreeNode<K = any, V = any> extends BSTNode<K, V> {
|
|
|
68
100
|
* );
|
|
69
101
|
* console.log(stocksInRange); // ['GOOGL', 'META', 'MSFT']
|
|
70
102
|
*/
|
|
71
|
-
export declare class RedBlackTree<K = any, V = any, R
|
|
72
|
-
/**
|
|
73
|
-
* This TypeScript constructor initializes a Red-Black Tree with optional keys, nodes, entries, or
|
|
74
|
-
* raw data.
|
|
75
|
-
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
76
|
-
* iterable that can contain either `K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined` objects or `R` objects. It
|
|
77
|
-
* is used to initialize the Red-Black Tree with keys, nodes, entries, or
|
|
78
|
-
* @param [options] - The `options` parameter in the constructor is of type `RedBlackTreeOptions<K,
|
|
79
|
-
* V, R>`. It is an optional parameter that allows you to specify additional options for the
|
|
80
|
-
* RedBlackTree class. These options could include configuration settings, behavior customization, or
|
|
81
|
-
* any other parameters that are specific to
|
|
82
|
-
*/
|
|
103
|
+
export declare class RedBlackTree<K = any, V = any, R extends object = object> extends BST<K, V, R> implements IBinaryTree<K, V, R> {
|
|
83
104
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: RedBlackTreeOptions<K, V, R>);
|
|
84
105
|
protected _root: RedBlackTreeNode<K, V> | undefined;
|
|
85
|
-
get root(): RedBlackTreeNode<K, V> | undefined;
|
|
86
106
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* The function creates a new Red-Black Tree node with the specified key, value, and color.
|
|
91
|
-
* @param {K} key - The key parameter represents the key value of the node being created. It is of
|
|
92
|
-
* type K, which is a generic type that can be replaced with any specific type when using the
|
|
93
|
-
* function.
|
|
94
|
-
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
95
|
-
* associated with the key in the node. It is not required and can be omitted if you only need to
|
|
96
|
-
* create a node with a key.
|
|
97
|
-
* @param {RBTNColor} [color=BLACK] - The "color" parameter is used to specify the color of the node
|
|
98
|
-
* in a Red-Black Tree. It can have two possible values: "RED" or "BLACK". By default, the color is
|
|
99
|
-
* set to "BLACK" if not specified.
|
|
100
|
-
* @returns A new instance of a RedBlackTreeNode with the specified key, value, and color is being
|
|
101
|
-
* returned.
|
|
107
|
+
* Get the current root node.
|
|
108
|
+
* @remarks Time O(1), Space O(1)
|
|
109
|
+
* @returns Root node, or undefined.
|
|
102
110
|
*/
|
|
103
|
-
|
|
111
|
+
get root(): RedBlackTreeNode<K, V> | undefined;
|
|
104
112
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* @param
|
|
110
|
-
*
|
|
111
|
-
* @returns a new instance of a RedBlackTree object.
|
|
113
|
+
* Create a red-black node for the given key/value (value ignored in map mode).
|
|
114
|
+
* @remarks Time O(1), Space O(1)
|
|
115
|
+
* @param key - See parameter type for details.
|
|
116
|
+
* @param [value] - See parameter type for details.
|
|
117
|
+
* @param color - See parameter type for details.
|
|
118
|
+
* @returns A new RedBlackTreeNode instance.
|
|
112
119
|
*/
|
|
113
|
-
|
|
120
|
+
_createNode(key: K, value?: V, color?: RBTNColor): RedBlackTreeNode<K, V>;
|
|
114
121
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* @param {K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
120
|
-
* `keyNodeOrEntry` can be of type `R` or `K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
121
|
-
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
122
|
-
* an instance of the `RedBlackTreeNode` class.
|
|
122
|
+
* Type guard: check whether the input is a RedBlackTreeNode.
|
|
123
|
+
* @remarks Time O(1), Space O(1)
|
|
124
|
+
* @param keyNodeOrEntry - See parameter type for details.
|
|
125
|
+
* @returns True if the value is a RedBlackTreeNode.
|
|
123
126
|
*/
|
|
124
127
|
isNode(keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is RedBlackTreeNode<K, V>;
|
|
125
128
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* The "clear" function sets the root node of a data structure to a sentinel value and resets the
|
|
130
|
-
* size counter to zero.
|
|
129
|
+
* Remove all nodes and clear the key→value store (if in map mode).
|
|
130
|
+
* @remarks Time O(n), Space O(1)
|
|
131
|
+
* @returns void
|
|
131
132
|
*/
|
|
132
133
|
clear(): void;
|
|
133
134
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* @param {K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
140
|
-
* `keyNodeOrEntry` can accept a value of type `R` or `K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
141
|
-
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
142
|
-
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
143
|
-
* structure.
|
|
144
|
-
* @returns The method is returning a boolean value. If a new node is successfully added to the tree,
|
|
145
|
-
* the method returns true. If the node already exists and its value is updated, the method also
|
|
146
|
-
* returns true. If the node cannot be added or updated, the method returns false.
|
|
135
|
+
* Insert or replace an entry using BST order and red-black fix-up.
|
|
136
|
+
* @remarks Time O(log n), Space O(1)
|
|
137
|
+
* @param keyNodeOrEntry - Key, node, or [key, value] entry to insert.
|
|
138
|
+
* @param [value]- See parameter type for details.
|
|
139
|
+
* @returns True if inserted or updated; false if ignored.
|
|
147
140
|
*/
|
|
148
141
|
add(keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
|
|
149
142
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* a given predicate and maintain the binary search tree properties.
|
|
155
|
-
* @param {K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
156
|
-
* parameter in the `override delete` method is used to specify the condition or key based on which a
|
|
157
|
-
* node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
|
|
158
|
-
* function that determines which node(s) should be deleted.
|
|
159
|
-
* @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>`
|
|
160
|
-
* objects. Each object in the array contains information about the deleted node and whether
|
|
161
|
-
* balancing is needed.
|
|
143
|
+
* Delete a node by key/node/entry and rebalance as needed.
|
|
144
|
+
* @remarks Time O(log n), Space O(1)
|
|
145
|
+
* @param keyNodeOrEntry - Key, node, or [key, value] entry identifying the node to delete.
|
|
146
|
+
* @returns Array with deletion metadata (removed node, rebalancing hint if any).
|
|
162
147
|
*/
|
|
163
148
|
delete(keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>[];
|
|
164
149
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* @param callback -
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* @
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
179
|
-
* (value of `this`) for the callback function. This can be useful when you want to access properties
|
|
180
|
-
* or
|
|
181
|
-
* @returns A new Red-Black Tree is being returned, where each entry has been transformed using the
|
|
182
|
-
* provided callback function.
|
|
183
|
-
*/
|
|
184
|
-
map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: RedBlackTreeOptions<MK, MV, MR>, thisArg?: any): RedBlackTree<MK, MV, MR>;
|
|
185
|
-
/**
|
|
186
|
-
* Time Complexity: O(n)
|
|
187
|
-
* Space Complexity: O(n)
|
|
188
|
-
*
|
|
189
|
-
* The function `clone` overrides the default cloning behavior to create a deep copy of a tree
|
|
190
|
-
* structure.
|
|
191
|
-
* @returns The `cloned` object is being returned.
|
|
192
|
-
*/
|
|
193
|
-
clone(): RedBlackTree<K, V, R, MK, MV, MR>;
|
|
194
|
-
/**
|
|
195
|
-
* Time Complexity: O(1)
|
|
196
|
-
* Space Complexity: O(1)
|
|
197
|
-
*
|
|
198
|
-
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
199
|
-
* root.
|
|
200
|
-
* @param {RedBlackTreeNode<K, V> | undefined} v - v is a parameter of type RedBlackTreeNode<K, V> or undefined.
|
|
201
|
-
*/
|
|
150
|
+
* Transform entries into a like-kind red-black tree with possibly different key/value types.
|
|
151
|
+
* @remarks Time O(n), Space O(n)
|
|
152
|
+
* @template MK
|
|
153
|
+
* @template MV
|
|
154
|
+
* @template MR
|
|
155
|
+
* @param callback - Mapping function from (key, value, index, tree) to a new [key, value].
|
|
156
|
+
* @param [options] - See parameter type for details.
|
|
157
|
+
* @param [thisArg] - See parameter type for details.
|
|
158
|
+
* @returns A new RedBlackTree with mapped entries.
|
|
159
|
+
*/
|
|
160
|
+
map<MK = K, MV = V, MR extends object = object>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): RedBlackTree<MK, MV, MR>;
|
|
161
|
+
protected _createInstance<TK = K, TV = V, TR extends object = R>(options?: Partial<RedBlackTreeOptions<TK, TV, TR>>): this;
|
|
162
|
+
protected _createLike<TK = K, TV = V, TR extends object = R>(iter?: Iterable<TK | RedBlackTreeNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<RedBlackTreeOptions<TK, TV, TR>>): RedBlackTree<TK, TV, TR>;
|
|
202
163
|
protected _setRoot(v: RedBlackTreeNode<K, V> | undefined): void;
|
|
203
|
-
/**
|
|
204
|
-
* Time Complexity: O(1)
|
|
205
|
-
* Space Complexity: O(1)
|
|
206
|
-
*
|
|
207
|
-
* The function replaces an old node with a new node while preserving the color of the old node.
|
|
208
|
-
* @param {RedBlackTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
|
|
209
|
-
* the data structure.
|
|
210
|
-
* @param {RedBlackTreeNode<K, V>} newNode - The `newNode` parameter is of type `RedBlackTreeNode<K, V>`, which represents a node in a
|
|
211
|
-
* data structure.
|
|
212
|
-
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
213
|
-
* superclass, with the `oldNode` and `newNode` parameters.
|
|
214
|
-
*/
|
|
215
164
|
protected _replaceNode(oldNode: RedBlackTreeNode<K, V>, newNode: RedBlackTreeNode<K, V>): RedBlackTreeNode<K, V>;
|
|
216
165
|
/**
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* maintain the red-black tree properties.
|
|
222
|
-
* @param {RedBlackTreeNode<K, V>} node - The `node` parameter represents the node that needs to be inserted into the
|
|
223
|
-
* binary search tree.
|
|
224
|
-
* @returns a string value indicating the result of the insertion operation. It can return either
|
|
225
|
-
* 'UPDATED' if the node with the same key already exists and was updated, or 'CREATED' if a new node
|
|
226
|
-
* was created and inserted into the tree.
|
|
166
|
+
* (Protected) Standard BST insert followed by red-black fix-up.
|
|
167
|
+
* @remarks Time O(log n), Space O(1)
|
|
168
|
+
* @param node - Node to insert.
|
|
169
|
+
* @returns Status string: 'CREATED' or 'UPDATED'.
|
|
227
170
|
*/
|
|
228
171
|
protected _insert(node: RedBlackTreeNode<K, V>): CRUD;
|
|
229
172
|
/**
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* @
|
|
235
|
-
* @param {RedBlackTreeNode<K, V> | undefined} v - The parameter `v` is of type `RedBlackTreeNode<K, V> | undefined`, which means it can
|
|
236
|
-
* either be a `RedBlackTreeNode<K, V>` object or `undefined`.
|
|
173
|
+
* (Protected) Transplant a subtree in place of another during deletion.
|
|
174
|
+
* @remarks Time O(1), Space O(1)
|
|
175
|
+
* @param u - Node to replace.
|
|
176
|
+
* @param v - Replacement subtree root (may be undefined).
|
|
177
|
+
* @returns void
|
|
237
178
|
*/
|
|
238
179
|
protected _transplant(u: RedBlackTreeNode<K, V>, v: RedBlackTreeNode<K, V> | undefined): void;
|
|
239
180
|
/**
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
* @param {RedBlackTreeNode<K, V> | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
|
|
245
|
-
* structure. It can either be a valid node or `undefined`.
|
|
181
|
+
* (Protected) Restore red-black properties after insertion (recolor/rotate).
|
|
182
|
+
* @remarks Time O(log n), Space O(1)
|
|
183
|
+
* @param z - Recently inserted node.
|
|
184
|
+
* @returns void
|
|
246
185
|
*/
|
|
247
186
|
protected _insertFixup(z: RedBlackTreeNode<K, V> | undefined): void;
|
|
248
187
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
* the colors and performing rotations.
|
|
254
|
-
* @param {RedBlackTreeNode<K, V> | undefined} node - The `node` parameter represents a node in a binary tree. It can
|
|
255
|
-
* be either a valid node object or `undefined`.
|
|
256
|
-
* @returns The function does not return any value. It has a return type of `void`, which means it
|
|
257
|
-
* does not return anything.
|
|
188
|
+
* (Protected) Restore red-black properties after deletion (recolor/rotate).
|
|
189
|
+
* @remarks Time O(log n), Space O(1)
|
|
190
|
+
* @param node - Child that replaced the deleted node (may be undefined).
|
|
191
|
+
* @returns void
|
|
258
192
|
*/
|
|
259
193
|
protected _deleteFixup(node: RedBlackTreeNode<K, V> | undefined): void;
|
|
260
194
|
/**
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* @param {RedBlackTreeNode<K, V> | undefined} x - The parameter `x` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
|
|
266
|
-
* node in a binary tree or `undefined` if there is no node.
|
|
267
|
-
* @returns void, which means it does not return any value.
|
|
195
|
+
* (Protected) Perform a left rotation around x.
|
|
196
|
+
* @remarks Time O(1), Space O(1)
|
|
197
|
+
* @param x - Pivot node to rotate around.
|
|
198
|
+
* @returns void
|
|
268
199
|
*/
|
|
269
200
|
protected _leftRotate(x: RedBlackTreeNode<K, V> | undefined): void;
|
|
270
201
|
/**
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
* @param {RedBlackTreeNode<K, V> | undefined} y - The parameter `y` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
|
|
276
|
-
* node in a binary tree or `undefined` if there is no node.
|
|
277
|
-
* @returns void, which means it does not return any value.
|
|
202
|
+
* (Protected) Perform a right rotation around y.
|
|
203
|
+
* @remarks Time O(1), Space O(1)
|
|
204
|
+
* @param y - Pivot node to rotate around.
|
|
205
|
+
* @returns void
|
|
278
206
|
*/
|
|
279
207
|
protected _rightRotate(y: RedBlackTreeNode<K, V> | undefined): void;
|
|
280
208
|
}
|