min-heap-typed 1.40.0 → 1.41.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.
- package/dist/data-structures/binary-tree/binary-tree.d.ts +14 -3
- package/dist/data-structures/binary-tree/binary-tree.js +52 -10
- package/dist/data-structures/binary-tree/bst.d.ts +2 -2
- package/dist/data-structures/binary-tree/bst.js +3 -3
- package/dist/data-structures/binary-tree/rb-tree.d.ts +96 -9
- package/dist/data-structures/binary-tree/rb-tree.js +377 -12
- package/dist/data-structures/binary-tree/tree-multiset.js +2 -2
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -7
- package/dist/types/data-structures/binary-tree/rb-tree.js +11 -6
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +3 -2
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +87 -17
- package/src/data-structures/binary-tree/bst.ts +10 -7
- package/src/data-structures/binary-tree/rb-tree.ts +396 -349
- package/src/data-structures/binary-tree/tree-multiset.ts +4 -3
- package/src/data-structures/graph/abstract-graph.ts +11 -12
- package/src/data-structures/graph/directed-graph.ts +7 -6
- package/src/data-structures/graph/undirected-graph.ts +7 -6
- package/src/data-structures/hash/hash-map.ts +1 -1
- package/src/data-structures/hash/tree-map.ts +1 -2
- package/src/data-structures/hash/tree-set.ts +1 -2
- package/src/data-structures/heap/heap.ts +2 -2
- package/src/data-structures/heap/max-heap.ts +1 -1
- package/src/data-structures/heap/min-heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/matrix/vector2d.ts +1 -2
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/data-structures/queue/deque.ts +3 -4
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/types/data-structures/binary-tree/rb-tree.ts +6 -6
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +2 -2
|
@@ -1,21 +1,386 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RedBlackTree = exports.SN = exports.RBTreeNode = void 0;
|
|
4
4
|
const types_1 = require("../../types");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.color =
|
|
5
|
+
class RBTreeNode {
|
|
6
|
+
constructor(key, color = types_1.RBTNColor.BLACK) {
|
|
7
|
+
this.color = types_1.RBTNColor.BLACK;
|
|
8
|
+
this.key = key;
|
|
9
|
+
this.color = color;
|
|
10
|
+
this.parent = null;
|
|
11
|
+
this.left = null;
|
|
12
|
+
this.right = null;
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
15
|
exports.RBTreeNode = RBTreeNode;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
exports.SN = new RBTreeNode(0);
|
|
17
|
+
class RedBlackTree {
|
|
18
|
+
constructor() {
|
|
19
|
+
this._root = exports.SN;
|
|
16
20
|
}
|
|
17
|
-
|
|
18
|
-
return
|
|
21
|
+
get root() {
|
|
22
|
+
return this._root;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The `insert` function inserts a new node with a given key into a red-black tree and fixes any
|
|
26
|
+
* violations of the red-black tree properties.
|
|
27
|
+
* @param {number} key - The key parameter is a number that represents the value to be inserted into
|
|
28
|
+
* the RBTree.
|
|
29
|
+
* @returns The function does not explicitly return anything.
|
|
30
|
+
*/
|
|
31
|
+
insert(key) {
|
|
32
|
+
const node = new RBTreeNode(key, types_1.RBTNColor.RED);
|
|
33
|
+
node.left = exports.SN;
|
|
34
|
+
node.right = exports.SN;
|
|
35
|
+
let y = null;
|
|
36
|
+
let x = this.root;
|
|
37
|
+
while (x !== exports.SN) {
|
|
38
|
+
y = x;
|
|
39
|
+
if (node.key < x.key) {
|
|
40
|
+
x = x.left;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
x = x.right;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
node.parent = y;
|
|
47
|
+
if (y === null) {
|
|
48
|
+
this._root = node;
|
|
49
|
+
}
|
|
50
|
+
else if (node.key < y.key) {
|
|
51
|
+
y.left = node;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
y.right = node;
|
|
55
|
+
}
|
|
56
|
+
if (node.parent === null) {
|
|
57
|
+
node.color = types_1.RBTNColor.BLACK;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (node.parent.parent === null) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this._fixInsert(node);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The `delete` function in TypeScript is used to remove a node with a specific key from a red-black
|
|
67
|
+
* tree.
|
|
68
|
+
* @param {RBTreeNode} node - The `node` parameter is of type `RBTreeNode` and represents the current
|
|
69
|
+
* node being processed in the delete operation.
|
|
70
|
+
* @returns The `delete` function does not return anything. It has a return type of `void`.
|
|
71
|
+
*/
|
|
72
|
+
delete(key) {
|
|
73
|
+
const helper = (node) => {
|
|
74
|
+
let z = exports.SN;
|
|
75
|
+
let x, y;
|
|
76
|
+
while (node !== exports.SN) {
|
|
77
|
+
if (node.key === key) {
|
|
78
|
+
z = node;
|
|
79
|
+
}
|
|
80
|
+
if (node.key <= key) {
|
|
81
|
+
node = node.right;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
node = node.left;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (z === exports.SN) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
y = z;
|
|
91
|
+
let yOriginalColor = y.color;
|
|
92
|
+
if (z.left === exports.SN) {
|
|
93
|
+
x = z.right;
|
|
94
|
+
this._rbTransplant(z, z.right);
|
|
95
|
+
}
|
|
96
|
+
else if (z.right === exports.SN) {
|
|
97
|
+
x = z.left;
|
|
98
|
+
this._rbTransplant(z, z.left);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
y = this.getLeftMost(z.right);
|
|
102
|
+
yOriginalColor = y.color;
|
|
103
|
+
x = y.right;
|
|
104
|
+
if (y.parent === z) {
|
|
105
|
+
x.parent = y;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this._rbTransplant(y, y.right);
|
|
109
|
+
y.right = z.right;
|
|
110
|
+
y.right.parent = y;
|
|
111
|
+
}
|
|
112
|
+
this._rbTransplant(z, y);
|
|
113
|
+
y.left = z.left;
|
|
114
|
+
y.left.parent = y;
|
|
115
|
+
y.color = z.color;
|
|
116
|
+
}
|
|
117
|
+
if (yOriginalColor === types_1.RBTNColor.BLACK) {
|
|
118
|
+
this._fixDelete(x);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
helper(this.root);
|
|
122
|
+
}
|
|
123
|
+
isRealNode(node) {
|
|
124
|
+
return node !== exports.SN && node !== null;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The function `getNode` is a recursive depth-first search algorithm that searches for a node with a
|
|
128
|
+
* given key in a red-black tree.
|
|
129
|
+
* @param {number} key - The key parameter is a number that represents the value we are searching for
|
|
130
|
+
* in the RBTree.
|
|
131
|
+
* @param beginRoot - The `beginRoot` parameter is an optional parameter that represents the starting
|
|
132
|
+
* point for the search in the binary search tree. If no value is provided for `beginRoot`, it
|
|
133
|
+
* defaults to the root of the binary search tree (`this.root`).
|
|
134
|
+
* @returns a RBTreeNode.
|
|
135
|
+
*/
|
|
136
|
+
getNode(key, beginRoot = this.root) {
|
|
137
|
+
const dfs = (node) => {
|
|
138
|
+
if (this.isRealNode(node)) {
|
|
139
|
+
if (key === node.key) {
|
|
140
|
+
return node;
|
|
141
|
+
}
|
|
142
|
+
if (key < node.key)
|
|
143
|
+
return dfs(node.left);
|
|
144
|
+
return dfs(node.right);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
return dfs(beginRoot);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The function returns the leftmost node in a red-black tree.
|
|
154
|
+
* @param {RBTreeNode} node - The parameter "node" is of type RBTreeNode, which represents a node in
|
|
155
|
+
* a Red-Black Tree.
|
|
156
|
+
* @returns The leftmost node in the given RBTreeNode.
|
|
157
|
+
*/
|
|
158
|
+
getLeftMost(node = this.root) {
|
|
159
|
+
while (node.left !== null && node.left !== exports.SN) {
|
|
160
|
+
node = node.left;
|
|
161
|
+
}
|
|
162
|
+
return node;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The function returns the rightmost node in a red-black tree.
|
|
166
|
+
* @param {RBTreeNode} node - The parameter "node" is of type RBTreeNode.
|
|
167
|
+
* @returns the rightmost node in a red-black tree.
|
|
168
|
+
*/
|
|
169
|
+
getRightMost(node) {
|
|
170
|
+
while (node.right !== null && node.right !== exports.SN) {
|
|
171
|
+
node = node.right;
|
|
172
|
+
}
|
|
173
|
+
return node;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The function returns the successor of a given node in a red-black tree.
|
|
177
|
+
* @param {RBTreeNode} x - RBTreeNode - The node for which we want to find the successor.
|
|
178
|
+
* @returns the successor of the given RBTreeNode.
|
|
179
|
+
*/
|
|
180
|
+
getSuccessor(x) {
|
|
181
|
+
if (x.right !== exports.SN) {
|
|
182
|
+
return this.getLeftMost(x.right);
|
|
183
|
+
}
|
|
184
|
+
let y = x.parent;
|
|
185
|
+
while (y !== exports.SN && y !== null && x === y.right) {
|
|
186
|
+
x = y;
|
|
187
|
+
y = y.parent;
|
|
188
|
+
}
|
|
189
|
+
return y;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The function returns the predecessor of a given node in a red-black tree.
|
|
193
|
+
* @param {RBTreeNode} x - The parameter `x` is of type `RBTreeNode`, which represents a node in a
|
|
194
|
+
* Red-Black Tree.
|
|
195
|
+
* @returns the predecessor of the given RBTreeNode 'x'.
|
|
196
|
+
*/
|
|
197
|
+
getPredecessor(x) {
|
|
198
|
+
if (x.left !== exports.SN) {
|
|
199
|
+
return this.getRightMost(x.left);
|
|
200
|
+
}
|
|
201
|
+
let y = x.parent;
|
|
202
|
+
while (y !== exports.SN && x === y.left) {
|
|
203
|
+
x = y;
|
|
204
|
+
y = y.parent;
|
|
205
|
+
}
|
|
206
|
+
return y;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* The function performs a left rotation on a red-black tree node.
|
|
210
|
+
* @param {RBTreeNode} x - The parameter `x` is a RBTreeNode object.
|
|
211
|
+
*/
|
|
212
|
+
_leftRotate(x) {
|
|
213
|
+
const y = x.right;
|
|
214
|
+
x.right = y.left;
|
|
215
|
+
if (y.left !== exports.SN) {
|
|
216
|
+
y.left.parent = x;
|
|
217
|
+
}
|
|
218
|
+
y.parent = x.parent;
|
|
219
|
+
if (x.parent === null) {
|
|
220
|
+
this._root = y;
|
|
221
|
+
}
|
|
222
|
+
else if (x === x.parent.left) {
|
|
223
|
+
x.parent.left = y;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
x.parent.right = y;
|
|
227
|
+
}
|
|
228
|
+
y.left = x;
|
|
229
|
+
x.parent = y;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The function performs a right rotation on a red-black tree node.
|
|
233
|
+
* @param {RBTreeNode} x - x is a RBTreeNode, which represents the node that needs to be right
|
|
234
|
+
* rotated.
|
|
235
|
+
*/
|
|
236
|
+
_rightRotate(x) {
|
|
237
|
+
const y = x.left;
|
|
238
|
+
x.left = y.right;
|
|
239
|
+
if (y.right !== exports.SN) {
|
|
240
|
+
y.right.parent = x;
|
|
241
|
+
}
|
|
242
|
+
y.parent = x.parent;
|
|
243
|
+
if (x.parent === null) {
|
|
244
|
+
this._root = y;
|
|
245
|
+
}
|
|
246
|
+
else if (x === x.parent.right) {
|
|
247
|
+
x.parent.right = y;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
x.parent.left = y;
|
|
251
|
+
}
|
|
252
|
+
y.right = x;
|
|
253
|
+
x.parent = y;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* The _fixDelete function is used to rebalance the Red-Black Tree after a node deletion.
|
|
257
|
+
* @param {RBTreeNode} x - The parameter `x` is of type `RBTreeNode`, which represents a node in a
|
|
258
|
+
* red-black tree.
|
|
259
|
+
*/
|
|
260
|
+
_fixDelete(x) {
|
|
261
|
+
let s;
|
|
262
|
+
while (x !== this.root && x.color === types_1.RBTNColor.BLACK) {
|
|
263
|
+
if (x === x.parent.left) {
|
|
264
|
+
s = x.parent.right;
|
|
265
|
+
if (s.color === 1) {
|
|
266
|
+
s.color = types_1.RBTNColor.BLACK;
|
|
267
|
+
x.parent.color = types_1.RBTNColor.RED;
|
|
268
|
+
this._leftRotate(x.parent);
|
|
269
|
+
s = x.parent.right;
|
|
270
|
+
}
|
|
271
|
+
if (s.left !== null && s.left.color === types_1.RBTNColor.BLACK && s.right.color === types_1.RBTNColor.BLACK) {
|
|
272
|
+
s.color = types_1.RBTNColor.RED;
|
|
273
|
+
x = x.parent;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
if (s.right.color === types_1.RBTNColor.BLACK) {
|
|
277
|
+
s.left.color = types_1.RBTNColor.BLACK;
|
|
278
|
+
s.color = types_1.RBTNColor.RED;
|
|
279
|
+
this._rightRotate(s);
|
|
280
|
+
s = x.parent.right;
|
|
281
|
+
}
|
|
282
|
+
s.color = x.parent.color;
|
|
283
|
+
x.parent.color = types_1.RBTNColor.BLACK;
|
|
284
|
+
s.right.color = types_1.RBTNColor.BLACK;
|
|
285
|
+
this._leftRotate(x.parent);
|
|
286
|
+
x = this.root;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
s = x.parent.left;
|
|
291
|
+
if (s.color === 1) {
|
|
292
|
+
s.color = types_1.RBTNColor.BLACK;
|
|
293
|
+
x.parent.color = types_1.RBTNColor.RED;
|
|
294
|
+
this._rightRotate(x.parent);
|
|
295
|
+
s = x.parent.left;
|
|
296
|
+
}
|
|
297
|
+
if (s.right.color === types_1.RBTNColor.BLACK && s.right.color === types_1.RBTNColor.BLACK) {
|
|
298
|
+
s.color = types_1.RBTNColor.RED;
|
|
299
|
+
x = x.parent;
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
if (s.left.color === types_1.RBTNColor.BLACK) {
|
|
303
|
+
s.right.color = types_1.RBTNColor.BLACK;
|
|
304
|
+
s.color = types_1.RBTNColor.RED;
|
|
305
|
+
this._leftRotate(s);
|
|
306
|
+
s = x.parent.left;
|
|
307
|
+
}
|
|
308
|
+
s.color = x.parent.color;
|
|
309
|
+
x.parent.color = types_1.RBTNColor.BLACK;
|
|
310
|
+
s.left.color = types_1.RBTNColor.BLACK;
|
|
311
|
+
this._rightRotate(x.parent);
|
|
312
|
+
x = this.root;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
x.color = types_1.RBTNColor.BLACK;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* The function `_rbTransplant` replaces one node in a red-black tree with another node.
|
|
320
|
+
* @param {RBTreeNode} u - The parameter "u" represents a RBTreeNode object.
|
|
321
|
+
* @param {RBTreeNode} v - The parameter "v" is a RBTreeNode object.
|
|
322
|
+
*/
|
|
323
|
+
_rbTransplant(u, v) {
|
|
324
|
+
if (u.parent === null) {
|
|
325
|
+
this._root = v;
|
|
326
|
+
}
|
|
327
|
+
else if (u === u.parent.left) {
|
|
328
|
+
u.parent.left = v;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
u.parent.right = v;
|
|
332
|
+
}
|
|
333
|
+
v.parent = u.parent;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
|
|
337
|
+
* @param {RBTreeNode} k - The parameter `k` is a RBTreeNode object, which represents a node in a
|
|
338
|
+
* red-black tree.
|
|
339
|
+
*/
|
|
340
|
+
_fixInsert(k) {
|
|
341
|
+
let u;
|
|
342
|
+
while (k.parent.color === 1) {
|
|
343
|
+
if (k.parent === k.parent.parent.right) {
|
|
344
|
+
u = k.parent.parent.left;
|
|
345
|
+
if (u.color === 1) {
|
|
346
|
+
u.color = types_1.RBTNColor.BLACK;
|
|
347
|
+
k.parent.color = types_1.RBTNColor.BLACK;
|
|
348
|
+
k.parent.parent.color = types_1.RBTNColor.RED;
|
|
349
|
+
k = k.parent.parent;
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
if (k === k.parent.left) {
|
|
353
|
+
k = k.parent;
|
|
354
|
+
this._rightRotate(k);
|
|
355
|
+
}
|
|
356
|
+
k.parent.color = types_1.RBTNColor.BLACK;
|
|
357
|
+
k.parent.parent.color = types_1.RBTNColor.RED;
|
|
358
|
+
this._leftRotate(k.parent.parent);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
u = k.parent.parent.right;
|
|
363
|
+
if (u.color === 1) {
|
|
364
|
+
u.color = types_1.RBTNColor.BLACK;
|
|
365
|
+
k.parent.color = types_1.RBTNColor.BLACK;
|
|
366
|
+
k.parent.parent.color = types_1.RBTNColor.RED;
|
|
367
|
+
k = k.parent.parent;
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
if (k === k.parent.right) {
|
|
371
|
+
k = k.parent;
|
|
372
|
+
this._leftRotate(k);
|
|
373
|
+
}
|
|
374
|
+
k.parent.color = types_1.RBTNColor.BLACK;
|
|
375
|
+
k.parent.parent.color = types_1.RBTNColor.RED;
|
|
376
|
+
this._rightRotate(k.parent.parent);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (k === this.root) {
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
this.root.color = types_1.RBTNColor.BLACK;
|
|
19
384
|
}
|
|
20
385
|
}
|
|
21
|
-
exports.
|
|
386
|
+
exports.RedBlackTree = RedBlackTree;
|
|
@@ -159,7 +159,7 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
159
159
|
else if (parent.right === undefined) {
|
|
160
160
|
parent.right = newNode;
|
|
161
161
|
if (newNode !== null) {
|
|
162
|
-
this._size =
|
|
162
|
+
this._size = this.size + 1;
|
|
163
163
|
this._setCount(this.count + newNode.count);
|
|
164
164
|
}
|
|
165
165
|
return parent.right;
|
|
@@ -262,7 +262,7 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
262
262
|
const bstDeletedResult = [];
|
|
263
263
|
if (!this.root)
|
|
264
264
|
return bstDeletedResult;
|
|
265
|
-
const curr = this.
|
|
265
|
+
const curr = this.getNode(identifier, callback);
|
|
266
266
|
if (!curr)
|
|
267
267
|
return bstDeletedResult;
|
|
268
268
|
const parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
RED = "RED",
|
|
5
|
-
BLACK = "BLACK"
|
|
1
|
+
export declare enum RBTNColor {
|
|
2
|
+
RED = 1,
|
|
3
|
+
BLACK = 0
|
|
6
4
|
}
|
|
7
|
-
export type RBTreeNodeNested<T> = RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
8
|
-
export type RBTreeOptions = BinaryTreeOptions & {};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// import {BinaryTreeOptions} from './binary-tree';
|
|
3
|
+
// import {RBTreeNode} from '../../../data-structures';
|
|
2
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
(function (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})(
|
|
5
|
+
exports.RBTNColor = void 0;
|
|
6
|
+
var RBTNColor;
|
|
7
|
+
(function (RBTNColor) {
|
|
8
|
+
RBTNColor[RBTNColor["RED"] = 1] = "RED";
|
|
9
|
+
RBTNColor[RBTNColor["BLACK"] = 0] = "BLACK";
|
|
10
|
+
})(RBTNColor = exports.RBTNColor || (exports.RBTNColor = {}));
|
|
11
|
+
// export type RBTreeNodeNested<T> = RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, RBTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
12
|
+
//
|
|
13
|
+
// export type RBTreeOptions = BinaryTreeOptions & {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "min-heap-typed",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.41.1",
|
|
4
4
|
"description": "Min Heap. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -131,6 +131,6 @@
|
|
|
131
131
|
"typescript": "^4.9.5"
|
|
132
132
|
},
|
|
133
133
|
"dependencies": {
|
|
134
|
-
"data-structure-typed": "^1.
|
|
134
|
+
"data-structure-typed": "^1.41.1"
|
|
135
135
|
}
|
|
136
136
|
}
|
|
@@ -21,7 +21,8 @@ export class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNeste
|
|
|
21
21
|
|
|
22
22
|
export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>>
|
|
23
23
|
extends BST<V, N>
|
|
24
|
-
implements IBinaryTree<V, N>
|
|
24
|
+
implements IBinaryTree<V, N>
|
|
25
|
+
{
|
|
25
26
|
/**
|
|
26
27
|
* This is a constructor function for an AVL tree data structure in TypeScript.
|
|
27
28
|
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
|
|
@@ -160,7 +161,7 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
|
|
|
160
161
|
// Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
|
|
161
162
|
switch (
|
|
162
163
|
this._balanceFactor(A) // second O(1)
|
|
163
|
-
|
|
164
|
+
) {
|
|
164
165
|
case -2:
|
|
165
166
|
if (A && A.left) {
|
|
166
167
|
if (this._balanceFactor(A.left) <= 0) {
|
|
@@ -17,7 +17,7 @@ export class BinaryIndexedTree {
|
|
|
17
17
|
* @param - - `frequency`: The default frequency value. It is optional and has a default
|
|
18
18
|
* value of 0.
|
|
19
19
|
*/
|
|
20
|
-
constructor({frequency = 0, max}: {
|
|
20
|
+
constructor({frequency = 0, max}: {frequency?: number; max: number}) {
|
|
21
21
|
this._freq = frequency;
|
|
22
22
|
this._max = max;
|
|
23
23
|
this._freqMap = {0: 0};
|