min-heap-typed 1.50.2 → 1.50.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/data-structures/binary-tree/avl-tree.js +33 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/data-structures/binary-tree/bst.js +46 -13
- package/dist/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/data-structures/binary-tree/rb-tree.js +73 -15
- package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +35 -2
- package/dist/data-structures/binary-tree/tree-multimap.js +38 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/data-structures/graph/abstract-graph.js +0 -189
- package/dist/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/data-structures/graph/directed-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/data-structures/graph/undirected-graph.js +126 -18
- package/dist/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/data-structures/hash/hash-map.js +196 -62
- package/dist/data-structures/heap/heap.d.ts +29 -19
- package/dist/data-structures/heap/heap.js +29 -20
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/data-structures/linked-list/doubly-linked-list.js +83 -25
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/data-structures/linked-list/singly-linked-list.js +34 -3
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/data-structures/matrix/matrix.js +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/data-structures/queue/deque.d.ts +95 -21
- package/dist/data-structures/queue/deque.js +100 -16
- package/dist/data-structures/queue/queue.d.ts +65 -45
- package/dist/data-structures/queue/queue.js +65 -45
- package/dist/data-structures/stack/stack.d.ts +36 -22
- package/dist/data-structures/stack/stack.js +36 -22
- package/dist/data-structures/tree/tree.d.ts +57 -3
- package/dist/data-structures/tree/tree.js +77 -11
- package/dist/data-structures/trie/trie.d.ts +100 -36
- package/dist/data-structures/trie/trie.js +115 -36
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +12 -0
- package/src/data-structures/binary-tree/avl-tree.ts +37 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/data-structures/binary-tree/bst.ts +46 -13
- package/src/data-structures/binary-tree/rb-tree.ts +79 -18
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multimap.ts +42 -3
- package/src/data-structures/graph/abstract-graph.ts +0 -211
- package/src/data-structures/graph/directed-graph.ts +122 -0
- package/src/data-structures/graph/undirected-graph.ts +143 -19
- package/src/data-structures/hash/hash-map.ts +228 -76
- package/src/data-structures/heap/heap.ts +31 -20
- package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
- package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +118 -22
- package/src/data-structures/queue/queue.ts +68 -45
- package/src/data-structures/stack/stack.ts +39 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +131 -40
|
@@ -11,9 +11,34 @@ exports.RedBlackTree = exports.RedBlackTreeNode = void 0;
|
|
|
11
11
|
const types_1 = require("../../types");
|
|
12
12
|
const bst_1 = require("./bst");
|
|
13
13
|
class RedBlackTreeNode extends bst_1.BSTNode {
|
|
14
|
+
/**
|
|
15
|
+
* The constructor function initializes a Red-Black Tree Node with a key, an optional value, and a
|
|
16
|
+
* color.
|
|
17
|
+
* @param {K} key - The key parameter is of type K and represents the key of the node in the
|
|
18
|
+
* Red-Black Tree.
|
|
19
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
20
|
+
* associated with the key in the Red-Black Tree Node. It is not required and can be omitted when
|
|
21
|
+
* creating a new instance of the Red-Black Tree Node.
|
|
22
|
+
* @param {RBTNColor} color - The `color` parameter is used to specify the color of the Red-Black
|
|
23
|
+
* Tree Node. It is an optional parameter with a default value of `RBTNColor.BLACK`.
|
|
24
|
+
*/
|
|
14
25
|
constructor(key, value, color = types_1.RBTNColor.BLACK) {
|
|
15
26
|
super(key, value);
|
|
16
|
-
this.
|
|
27
|
+
this._color = color;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The function returns the color value of a variable.
|
|
31
|
+
* @returns The color value stored in the protected variable `_color`.
|
|
32
|
+
*/
|
|
33
|
+
get color() {
|
|
34
|
+
return this._color;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The function sets the color property to the specified value.
|
|
38
|
+
* @param {RBTNColor} value - The value parameter is of type RBTNColor.
|
|
39
|
+
*/
|
|
40
|
+
set color(value) {
|
|
41
|
+
this._color = value;
|
|
17
42
|
}
|
|
18
43
|
}
|
|
19
44
|
exports.RedBlackTreeNode = RedBlackTreeNode;
|
|
@@ -38,15 +63,30 @@ class RedBlackTree extends bst_1.BST {
|
|
|
38
63
|
*/
|
|
39
64
|
constructor(keysOrNodesOrEntries = [], options) {
|
|
40
65
|
super([], options);
|
|
41
|
-
this.
|
|
66
|
+
this._Sentinel = new RedBlackTreeNode(NaN);
|
|
42
67
|
this._size = 0;
|
|
43
|
-
this._root = this.
|
|
68
|
+
this._root = this._Sentinel;
|
|
44
69
|
if (keysOrNodesOrEntries)
|
|
45
70
|
super.addMany(keysOrNodesOrEntries);
|
|
46
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* The function returns the value of the `_Sentinel` property.
|
|
74
|
+
* @returns The method is returning the value of the `_Sentinel` property.
|
|
75
|
+
*/
|
|
76
|
+
get Sentinel() {
|
|
77
|
+
return this._Sentinel;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The function returns the root node.
|
|
81
|
+
* @returns The root node of the data structure.
|
|
82
|
+
*/
|
|
47
83
|
get root() {
|
|
48
84
|
return this._root;
|
|
49
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* The function returns the size of an object.
|
|
88
|
+
* @returns The size of the object, which is a number.
|
|
89
|
+
*/
|
|
50
90
|
get size() {
|
|
51
91
|
return this._size;
|
|
52
92
|
}
|
|
@@ -117,8 +157,14 @@ class RedBlackTree extends bst_1.BST {
|
|
|
117
157
|
isNode(keyOrNodeOrEntry) {
|
|
118
158
|
return keyOrNodeOrEntry instanceof RedBlackTreeNode;
|
|
119
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* The function checks if a given node is a real node in a Red-Black Tree.
|
|
162
|
+
* @param {NODE | undefined} node - The `node` parameter is of type `NODE | undefined`, which means
|
|
163
|
+
* it can either be of type `NODE` or `undefined`.
|
|
164
|
+
* @returns a boolean value.
|
|
165
|
+
*/
|
|
120
166
|
isRealNode(node) {
|
|
121
|
-
if (node === this.
|
|
167
|
+
if (node === this._Sentinel || node === undefined)
|
|
122
168
|
return false;
|
|
123
169
|
return node instanceof RedBlackTreeNode;
|
|
124
170
|
}
|
|
@@ -143,11 +189,11 @@ class RedBlackTree extends bst_1.BST {
|
|
|
143
189
|
const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
|
|
144
190
|
if (newNode === undefined)
|
|
145
191
|
return false;
|
|
146
|
-
newNode.left = this.
|
|
147
|
-
newNode.right = this.
|
|
192
|
+
newNode.left = this._Sentinel;
|
|
193
|
+
newNode.right = this._Sentinel;
|
|
148
194
|
let y = undefined;
|
|
149
195
|
let x = this.root;
|
|
150
|
-
while (x !== this.
|
|
196
|
+
while (x !== this._Sentinel) {
|
|
151
197
|
y = x;
|
|
152
198
|
if (x) {
|
|
153
199
|
if (newNode.key < x.key) {
|
|
@@ -211,9 +257,9 @@ class RedBlackTree extends bst_1.BST {
|
|
|
211
257
|
if (identifier === null)
|
|
212
258
|
return ans;
|
|
213
259
|
const helper = (node) => {
|
|
214
|
-
let z = this.
|
|
260
|
+
let z = this._Sentinel;
|
|
215
261
|
let x, y;
|
|
216
|
-
while (node !== this.
|
|
262
|
+
while (node !== this._Sentinel) {
|
|
217
263
|
if (node && callback(node) === identifier) {
|
|
218
264
|
z = node;
|
|
219
265
|
}
|
|
@@ -224,17 +270,17 @@ class RedBlackTree extends bst_1.BST {
|
|
|
224
270
|
node = node === null || node === void 0 ? void 0 : node.left;
|
|
225
271
|
}
|
|
226
272
|
}
|
|
227
|
-
if (z === this.
|
|
273
|
+
if (z === this._Sentinel) {
|
|
228
274
|
this._size--;
|
|
229
275
|
return;
|
|
230
276
|
}
|
|
231
277
|
y = z;
|
|
232
278
|
let yOriginalColor = y.color;
|
|
233
|
-
if (z.left === this.
|
|
279
|
+
if (z.left === this._Sentinel) {
|
|
234
280
|
x = z.right;
|
|
235
281
|
this._rbTransplant(z, z.right);
|
|
236
282
|
}
|
|
237
|
-
else if (z.right === this.
|
|
283
|
+
else if (z.right === this._Sentinel) {
|
|
238
284
|
x = z.left;
|
|
239
285
|
this._rbTransplant(z, z.left);
|
|
240
286
|
}
|
|
@@ -300,8 +346,14 @@ class RedBlackTree extends bst_1.BST {
|
|
|
300
346
|
* Time Complexity: O(1)
|
|
301
347
|
* Space Complexity: O(1)
|
|
302
348
|
*/
|
|
349
|
+
/**
|
|
350
|
+
* Time Complexity: O(1)
|
|
351
|
+
* Space Complexity: O(1)
|
|
352
|
+
*
|
|
353
|
+
* The "clear" function sets the root node to the sentinel node and resets the size to 0.
|
|
354
|
+
*/
|
|
303
355
|
clear() {
|
|
304
|
-
this._root = this.
|
|
356
|
+
this._root = this._Sentinel;
|
|
305
357
|
this._size = 0;
|
|
306
358
|
}
|
|
307
359
|
/**
|
|
@@ -328,6 +380,12 @@ class RedBlackTree extends bst_1.BST {
|
|
|
328
380
|
}
|
|
329
381
|
return y;
|
|
330
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* The function sets the root node of a tree structure and updates the parent property of the new
|
|
385
|
+
* root node.
|
|
386
|
+
* @param {NODE} v - The parameter "v" is of type "NODE", which represents a node in a data
|
|
387
|
+
* structure.
|
|
388
|
+
*/
|
|
331
389
|
_setRoot(v) {
|
|
332
390
|
if (v) {
|
|
333
391
|
v.parent = undefined;
|
|
@@ -349,7 +407,7 @@ class RedBlackTree extends bst_1.BST {
|
|
|
349
407
|
if (x.right) {
|
|
350
408
|
const y = x.right;
|
|
351
409
|
x.right = y.left;
|
|
352
|
-
if (y.left !== this.
|
|
410
|
+
if (y.left !== this._Sentinel) {
|
|
353
411
|
if (y.left)
|
|
354
412
|
y.left.parent = x;
|
|
355
413
|
}
|
|
@@ -383,7 +441,7 @@ class RedBlackTree extends bst_1.BST {
|
|
|
383
441
|
if (x.left) {
|
|
384
442
|
const y = x.left;
|
|
385
443
|
x.left = y.right;
|
|
386
|
-
if (y.right !== this.
|
|
444
|
+
if (y.right !== this._Sentinel) {
|
|
387
445
|
if (y.right)
|
|
388
446
|
y.right.parent = x;
|
|
389
447
|
}
|
|
@@ -7,13 +7,90 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { SegmentTreeNodeVal } from '../../types';
|
|
9
9
|
export declare class SegmentTreeNode {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The constructor initializes the properties of a SegmentTreeNode object.
|
|
12
|
+
* @param {number} start - The `start` parameter represents the starting index of the segment covered
|
|
13
|
+
* by this node in a segment tree.
|
|
14
|
+
* @param {number} end - The `end` parameter represents the end index of the segment covered by this
|
|
15
|
+
* node in a segment tree.
|
|
16
|
+
* @param {number} sum - The `sum` parameter represents the sum of the values in the range covered by
|
|
17
|
+
* the segment tree node.
|
|
18
|
+
* @param {SegmentTreeNodeVal | undefined} [value] - The `value` parameter is an optional parameter
|
|
19
|
+
* of type `SegmentTreeNodeVal`. It represents the value associated with the segment tree node.
|
|
20
|
+
*/
|
|
16
21
|
constructor(start: number, end: number, sum: number, value?: SegmentTreeNodeVal | undefined);
|
|
22
|
+
protected _start: number;
|
|
23
|
+
/**
|
|
24
|
+
* The function returns the value of the protected variable _start.
|
|
25
|
+
* @returns The start value, which is of type number.
|
|
26
|
+
*/
|
|
27
|
+
get start(): number;
|
|
28
|
+
/**
|
|
29
|
+
* The above function sets the value of the "start" property.
|
|
30
|
+
* @param {number} value - The value parameter is of type number.
|
|
31
|
+
*/
|
|
32
|
+
set start(value: number);
|
|
33
|
+
protected _end: number;
|
|
34
|
+
/**
|
|
35
|
+
* The function returns the value of the protected variable `_end`.
|
|
36
|
+
* @returns The value of the protected property `_end`.
|
|
37
|
+
*/
|
|
38
|
+
get end(): number;
|
|
39
|
+
/**
|
|
40
|
+
* The above function sets the value of the "end" property.
|
|
41
|
+
* @param {number} value - The value parameter is a number that represents the new value for the end
|
|
42
|
+
* property.
|
|
43
|
+
*/
|
|
44
|
+
set end(value: number);
|
|
45
|
+
protected _value: SegmentTreeNodeVal | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* The function returns the value of a segment tree node.
|
|
48
|
+
* @returns The value being returned is either a `SegmentTreeNodeVal` object or `undefined`.
|
|
49
|
+
*/
|
|
50
|
+
get value(): SegmentTreeNodeVal | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* The function sets the value of a segment tree node.
|
|
53
|
+
* @param {SegmentTreeNodeVal | undefined} value - The `value` parameter is of type
|
|
54
|
+
* `SegmentTreeNodeVal` or `undefined`.
|
|
55
|
+
*/
|
|
56
|
+
set value(value: SegmentTreeNodeVal | undefined);
|
|
57
|
+
protected _sum: number;
|
|
58
|
+
/**
|
|
59
|
+
* The function returns the value of the sum property.
|
|
60
|
+
* @returns The method is returning the value of the variable `_sum`.
|
|
61
|
+
*/
|
|
62
|
+
get sum(): number;
|
|
63
|
+
/**
|
|
64
|
+
* The above function sets the value of the sum property.
|
|
65
|
+
* @param {number} value - The parameter "value" is of type "number".
|
|
66
|
+
*/
|
|
67
|
+
set sum(value: number);
|
|
68
|
+
protected _left: SegmentTreeNode | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* The function returns the left child of a segment tree node.
|
|
71
|
+
* @returns The `left` property of the `SegmentTreeNode` object is being returned. It is of type
|
|
72
|
+
* `SegmentTreeNode` or `undefined`.
|
|
73
|
+
*/
|
|
74
|
+
get left(): SegmentTreeNode | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* The function sets the value of the left property of a SegmentTreeNode object.
|
|
77
|
+
* @param {SegmentTreeNode | undefined} value - The value parameter is of type SegmentTreeNode or
|
|
78
|
+
* undefined.
|
|
79
|
+
*/
|
|
80
|
+
set left(value: SegmentTreeNode | undefined);
|
|
81
|
+
protected _right: SegmentTreeNode | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* The function returns the right child of a segment tree node.
|
|
84
|
+
* @returns The `getRight()` method is returning a value of type `SegmentTreeNode` or `undefined`.
|
|
85
|
+
*/
|
|
86
|
+
get right(): SegmentTreeNode | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* The function sets the right child of a segment tree node.
|
|
89
|
+
* @param {SegmentTreeNode | undefined} value - The `value` parameter is of type `SegmentTreeNode |
|
|
90
|
+
* undefined`. This means that it can accept either a `SegmentTreeNode` object or `undefined` as its
|
|
91
|
+
* value.
|
|
92
|
+
*/
|
|
93
|
+
set right(value: SegmentTreeNode | undefined);
|
|
17
94
|
}
|
|
18
95
|
export declare class SegmentTree {
|
|
19
96
|
/**
|
|
@@ -27,12 +104,28 @@ export declare class SegmentTree {
|
|
|
27
104
|
*/
|
|
28
105
|
constructor(values: number[], start?: number, end?: number);
|
|
29
106
|
protected _values: number[];
|
|
107
|
+
/**
|
|
108
|
+
* The function returns an array of numbers.
|
|
109
|
+
* @returns An array of numbers is being returned.
|
|
110
|
+
*/
|
|
30
111
|
get values(): number[];
|
|
31
112
|
protected _start: number;
|
|
113
|
+
/**
|
|
114
|
+
* The function returns the value of the protected variable _start.
|
|
115
|
+
* @returns The start value, which is of type number.
|
|
116
|
+
*/
|
|
32
117
|
get start(): number;
|
|
33
118
|
protected _end: number;
|
|
119
|
+
/**
|
|
120
|
+
* The function returns the value of the protected variable `_end`.
|
|
121
|
+
* @returns The value of the protected property `_end`.
|
|
122
|
+
*/
|
|
34
123
|
get end(): number;
|
|
35
124
|
protected _root: SegmentTreeNode | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* The function returns the root node of a segment tree.
|
|
127
|
+
* @returns The `root` property of the class `SegmentTreeNode` or `undefined` if it is not defined.
|
|
128
|
+
*/
|
|
36
129
|
get root(): SegmentTreeNode | undefined;
|
|
37
130
|
/**
|
|
38
131
|
* The build function creates a segment tree by recursively dividing the given range into smaller segments and assigning
|
|
@@ -9,17 +9,118 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.SegmentTree = exports.SegmentTreeNode = void 0;
|
|
11
11
|
class SegmentTreeNode {
|
|
12
|
+
/**
|
|
13
|
+
* The constructor initializes the properties of a SegmentTreeNode object.
|
|
14
|
+
* @param {number} start - The `start` parameter represents the starting index of the segment covered
|
|
15
|
+
* by this node in a segment tree.
|
|
16
|
+
* @param {number} end - The `end` parameter represents the end index of the segment covered by this
|
|
17
|
+
* node in a segment tree.
|
|
18
|
+
* @param {number} sum - The `sum` parameter represents the sum of the values in the range covered by
|
|
19
|
+
* the segment tree node.
|
|
20
|
+
* @param {SegmentTreeNodeVal | undefined} [value] - The `value` parameter is an optional parameter
|
|
21
|
+
* of type `SegmentTreeNodeVal`. It represents the value associated with the segment tree node.
|
|
22
|
+
*/
|
|
12
23
|
constructor(start, end, sum, value) {
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
24
|
+
this._start = 0;
|
|
25
|
+
this._end = 0;
|
|
26
|
+
this._value = undefined;
|
|
27
|
+
this._sum = 0;
|
|
28
|
+
this._left = undefined;
|
|
29
|
+
this._right = undefined;
|
|
30
|
+
this._start = start;
|
|
31
|
+
this._end = end;
|
|
32
|
+
this._sum = sum;
|
|
33
|
+
this._value = value || undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The function returns the value of the protected variable _start.
|
|
37
|
+
* @returns The start value, which is of type number.
|
|
38
|
+
*/
|
|
39
|
+
get start() {
|
|
40
|
+
return this._start;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The above function sets the value of the "start" property.
|
|
44
|
+
* @param {number} value - The value parameter is of type number.
|
|
45
|
+
*/
|
|
46
|
+
set start(value) {
|
|
47
|
+
this._start = value;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The function returns the value of the protected variable `_end`.
|
|
51
|
+
* @returns The value of the protected property `_end`.
|
|
52
|
+
*/
|
|
53
|
+
get end() {
|
|
54
|
+
return this._end;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The above function sets the value of the "end" property.
|
|
58
|
+
* @param {number} value - The value parameter is a number that represents the new value for the end
|
|
59
|
+
* property.
|
|
60
|
+
*/
|
|
61
|
+
set end(value) {
|
|
62
|
+
this._end = value;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The function returns the value of a segment tree node.
|
|
66
|
+
* @returns The value being returned is either a `SegmentTreeNodeVal` object or `undefined`.
|
|
67
|
+
*/
|
|
68
|
+
get value() {
|
|
69
|
+
return this._value;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The function sets the value of a segment tree node.
|
|
73
|
+
* @param {SegmentTreeNodeVal | undefined} value - The `value` parameter is of type
|
|
74
|
+
* `SegmentTreeNodeVal` or `undefined`.
|
|
75
|
+
*/
|
|
76
|
+
set value(value) {
|
|
77
|
+
this._value = value;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The function returns the value of the sum property.
|
|
81
|
+
* @returns The method is returning the value of the variable `_sum`.
|
|
82
|
+
*/
|
|
83
|
+
get sum() {
|
|
84
|
+
return this._sum;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The above function sets the value of the sum property.
|
|
88
|
+
* @param {number} value - The parameter "value" is of type "number".
|
|
89
|
+
*/
|
|
90
|
+
set sum(value) {
|
|
91
|
+
this._sum = value;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The function returns the left child of a segment tree node.
|
|
95
|
+
* @returns The `left` property of the `SegmentTreeNode` object is being returned. It is of type
|
|
96
|
+
* `SegmentTreeNode` or `undefined`.
|
|
97
|
+
*/
|
|
98
|
+
get left() {
|
|
99
|
+
return this._left;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The function sets the value of the left property of a SegmentTreeNode object.
|
|
103
|
+
* @param {SegmentTreeNode | undefined} value - The value parameter is of type SegmentTreeNode or
|
|
104
|
+
* undefined.
|
|
105
|
+
*/
|
|
106
|
+
set left(value) {
|
|
107
|
+
this._left = value;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The function returns the right child of a segment tree node.
|
|
111
|
+
* @returns The `getRight()` method is returning a value of type `SegmentTreeNode` or `undefined`.
|
|
112
|
+
*/
|
|
113
|
+
get right() {
|
|
114
|
+
return this._right;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The function sets the right child of a segment tree node.
|
|
118
|
+
* @param {SegmentTreeNode | undefined} value - The `value` parameter is of type `SegmentTreeNode |
|
|
119
|
+
* undefined`. This means that it can accept either a `SegmentTreeNode` object or `undefined` as its
|
|
120
|
+
* value.
|
|
121
|
+
*/
|
|
122
|
+
set right(value) {
|
|
123
|
+
this._right = value;
|
|
23
124
|
}
|
|
24
125
|
}
|
|
25
126
|
exports.SegmentTreeNode = SegmentTreeNode;
|
|
@@ -49,15 +150,31 @@ class SegmentTree {
|
|
|
49
150
|
this._values = [];
|
|
50
151
|
}
|
|
51
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* The function returns an array of numbers.
|
|
155
|
+
* @returns An array of numbers is being returned.
|
|
156
|
+
*/
|
|
52
157
|
get values() {
|
|
53
158
|
return this._values;
|
|
54
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* The function returns the value of the protected variable _start.
|
|
162
|
+
* @returns The start value, which is of type number.
|
|
163
|
+
*/
|
|
55
164
|
get start() {
|
|
56
165
|
return this._start;
|
|
57
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* The function returns the value of the protected variable `_end`.
|
|
169
|
+
* @returns The value of the protected property `_end`.
|
|
170
|
+
*/
|
|
58
171
|
get end() {
|
|
59
172
|
return this._end;
|
|
60
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* The function returns the root node of a segment tree.
|
|
176
|
+
* @returns The `root` property of the class `SegmentTreeNode` or `undefined` if it is not defined.
|
|
177
|
+
*/
|
|
61
178
|
get root() {
|
|
62
179
|
return this._root;
|
|
63
180
|
}
|
|
@@ -10,7 +10,6 @@ import { IterationType } from '../../types';
|
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
12
12
|
export declare class TreeMultimapNode<K = any, V = any, NODE extends TreeMultimapNode<K, V, NODE> = TreeMultimapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
|
|
13
|
-
count: number;
|
|
14
13
|
/**
|
|
15
14
|
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
16
15
|
* @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
|
|
@@ -22,13 +21,30 @@ export declare class TreeMultimapNode<K = any, V = any, NODE extends TreeMultima
|
|
|
22
21
|
* parameter when creating a new instance of the `BinaryTreeNode` class.
|
|
23
22
|
*/
|
|
24
23
|
constructor(key: K, value?: V, count?: number);
|
|
24
|
+
protected _count: number;
|
|
25
|
+
/**
|
|
26
|
+
* The function returns the value of the protected variable _count.
|
|
27
|
+
* @returns The count property of the object, which is of type number.
|
|
28
|
+
*/
|
|
29
|
+
get count(): number;
|
|
30
|
+
/**
|
|
31
|
+
* The above function sets the value of the count property.
|
|
32
|
+
* @param {number} value - The value parameter is of type number, which means it can accept any
|
|
33
|
+
* numeric value.
|
|
34
|
+
*/
|
|
35
|
+
set count(value: number);
|
|
25
36
|
}
|
|
26
37
|
/**
|
|
27
38
|
* The only distinction between a TreeMultimap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
28
39
|
*/
|
|
29
40
|
export declare class TreeMultimap<K = any, V = any, NODE extends TreeMultimapNode<K, V, NODE> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>, TREE extends TreeMultimap<K, V, NODE, TREE> = TreeMultimap<K, V, NODE, TreeMultimapNested<K, V, NODE>>> extends AVLTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
|
|
30
41
|
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultimapOptions<K>);
|
|
31
|
-
|
|
42
|
+
protected _count: number;
|
|
43
|
+
/**
|
|
44
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
45
|
+
* search.
|
|
46
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
47
|
+
*/
|
|
32
48
|
get count(): number;
|
|
33
49
|
/**
|
|
34
50
|
* The function creates a new BSTNode with the given key, value, and count.
|
|
@@ -40,6 +56,15 @@ export declare class TreeMultimap<K = any, V = any, NODE extends TreeMultimapNod
|
|
|
40
56
|
* @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
|
|
41
57
|
*/
|
|
42
58
|
createNode(key: K, value?: V, count?: number): NODE;
|
|
59
|
+
/**
|
|
60
|
+
* The function creates a new TreeMultimap object with the specified options and returns it.
|
|
61
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
62
|
+
* configuration options for creating the `TreeMultimap` object. It can include properties such as
|
|
63
|
+
* `iterationType` and `variant`, which are used to specify the type of iteration and the variant of
|
|
64
|
+
* the tree, respectively. These properties can be
|
|
65
|
+
* @returns a new instance of the `TreeMultimap` class, with the provided options merged with the
|
|
66
|
+
* default options. The returned value is casted as `TREE`.
|
|
67
|
+
*/
|
|
43
68
|
createTree(options?: TreeMultimapOptions<K>): TREE;
|
|
44
69
|
/**
|
|
45
70
|
* The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
|
|
@@ -154,5 +179,13 @@ export declare class TreeMultimap<K = any, V = any, NODE extends TreeMultimapNod
|
|
|
154
179
|
* if either `srcNode` or `destNode` is undefined.
|
|
155
180
|
*/
|
|
156
181
|
protected _swapProperties(srcNode: BSTNKeyOrNode<K, NODE>, destNode: BSTNKeyOrNode<K, NODE>): NODE | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
184
|
+
* @param {NODE} oldNode - The `oldNode` parameter is of type `NODE` and represents the node that
|
|
185
|
+
* needs to be replaced in a data structure.
|
|
186
|
+
* @param {NODE} newNode - The `newNode` parameter is an object of type `NODE`.
|
|
187
|
+
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
188
|
+
* superclass, after updating the `count` property of the `newNode` object.
|
|
189
|
+
*/
|
|
157
190
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
158
191
|
}
|
|
@@ -16,8 +16,24 @@ class TreeMultimapNode extends avl_tree_1.AVLTreeNode {
|
|
|
16
16
|
*/
|
|
17
17
|
constructor(key, value, count = 1) {
|
|
18
18
|
super(key, value);
|
|
19
|
+
this._count = 1;
|
|
19
20
|
this.count = count;
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* The function returns the value of the protected variable _count.
|
|
24
|
+
* @returns The count property of the object, which is of type number.
|
|
25
|
+
*/
|
|
26
|
+
get count() {
|
|
27
|
+
return this._count;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The above function sets the value of the count property.
|
|
31
|
+
* @param {number} value - The value parameter is of type number, which means it can accept any
|
|
32
|
+
* numeric value.
|
|
33
|
+
*/
|
|
34
|
+
set count(value) {
|
|
35
|
+
this._count = value;
|
|
36
|
+
}
|
|
21
37
|
}
|
|
22
38
|
exports.TreeMultimapNode = TreeMultimapNode;
|
|
23
39
|
/**
|
|
@@ -31,6 +47,11 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
31
47
|
this.addMany(keysOrNodesOrEntries);
|
|
32
48
|
}
|
|
33
49
|
// TODO the _count is not accurate after nodes count modified
|
|
50
|
+
/**
|
|
51
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
52
|
+
* search.
|
|
53
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
54
|
+
*/
|
|
34
55
|
get count() {
|
|
35
56
|
let sum = 0;
|
|
36
57
|
this.dfs(node => (sum += node.count));
|
|
@@ -48,6 +69,15 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
48
69
|
createNode(key, value, count) {
|
|
49
70
|
return new TreeMultimapNode(key, value, count);
|
|
50
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* The function creates a new TreeMultimap object with the specified options and returns it.
|
|
74
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
75
|
+
* configuration options for creating the `TreeMultimap` object. It can include properties such as
|
|
76
|
+
* `iterationType` and `variant`, which are used to specify the type of iteration and the variant of
|
|
77
|
+
* the tree, respectively. These properties can be
|
|
78
|
+
* @returns a new instance of the `TreeMultimap` class, with the provided options merged with the
|
|
79
|
+
* default options. The returned value is casted as `TREE`.
|
|
80
|
+
*/
|
|
51
81
|
createTree(options) {
|
|
52
82
|
return new TreeMultimap([], Object.assign({ iterationType: this.iterationType, variant: this.variant }, options));
|
|
53
83
|
}
|
|
@@ -319,6 +349,14 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
319
349
|
}
|
|
320
350
|
return undefined;
|
|
321
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
354
|
+
* @param {NODE} oldNode - The `oldNode` parameter is of type `NODE` and represents the node that
|
|
355
|
+
* needs to be replaced in a data structure.
|
|
356
|
+
* @param {NODE} newNode - The `newNode` parameter is an object of type `NODE`.
|
|
357
|
+
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
358
|
+
* superclass, after updating the `count` property of the `newNode` object.
|
|
359
|
+
*/
|
|
322
360
|
_replaceNode(oldNode, newNode) {
|
|
323
361
|
newNode.count = oldNode.count + newNode.count;
|
|
324
362
|
return super._replaceNode(oldNode, newNode);
|
|
@@ -362,84 +362,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
362
362
|
costs: number[][];
|
|
363
363
|
predecessor: (VO | undefined)[][];
|
|
364
364
|
};
|
|
365
|
-
/**
|
|
366
|
-
* Time Complexity: O(V + E) - Linear time (Tarjan's algorithm).
|
|
367
|
-
* Space Complexity: O(V) - Linear space (Tarjan's algorithm).
|
|
368
|
-
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
369
|
-
* Tarjan can find cycles in directed or undirected graph
|
|
370
|
-
* Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time,
|
|
371
|
-
* Tarjan solve the bi-connected components of undirected graphs;
|
|
372
|
-
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
373
|
-
* /
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Time Complexity: O(V + E) - Linear time (Tarjan's algorithm).
|
|
377
|
-
* Space Complexity: O(V) - Linear space (Tarjan's algorithm).
|
|
378
|
-
*
|
|
379
|
-
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
380
|
-
* Tarjan can find cycles in directed or undirected graph
|
|
381
|
-
* Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time,
|
|
382
|
-
* Tarjan solve the bi-connected components of undirected graphs;
|
|
383
|
-
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
384
|
-
* The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
|
|
385
|
-
* strongly connected components (SCCs), and cycles in a graph.
|
|
386
|
-
* @param {boolean} [needCutVertexes] - A boolean value indicating whether or not to calculate and return the
|
|
387
|
-
* articulation points in the graph. Articulation points are the vertexMap in a graph whose removal would increase the
|
|
388
|
-
* number of connected components in the graph.
|
|
389
|
-
* @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
|
|
390
|
-
* (edgeMap whose removal would increase the number of connected components in the graph).
|
|
391
|
-
* @param {boolean} [needSCCs] - A boolean value indicating whether the Strongly Connected Components (SCCs) of the
|
|
392
|
-
* graph are needed. If set to true, the function will calculate and return the SCCs of the graph. If set to false, the
|
|
393
|
-
* SCCs will not be calculated or returned.
|
|
394
|
-
* @param {boolean} [needCycles] - A boolean flag indicating whether the algorithm should find cycles in the graph. If
|
|
395
|
-
* set to true, the algorithm will return a map of cycles, where the keys are the low values of the SCCs and the values
|
|
396
|
-
* are arrays of vertexMap that form cycles within the SCCs.
|
|
397
|
-
* @returns The function `tarjan` returns an object with the following properties:
|
|
398
|
-
*/
|
|
399
|
-
tarjan(needCutVertexes?: boolean, needBridges?: boolean, needSCCs?: boolean, needCycles?: boolean): {
|
|
400
|
-
dfnMap: Map<VO, number>;
|
|
401
|
-
lowMap: Map<VO, number>;
|
|
402
|
-
bridges: EO[];
|
|
403
|
-
cutVertexes: VO[];
|
|
404
|
-
SCCs: Map<number, VO[]>;
|
|
405
|
-
cycles: Map<number, VO[]>;
|
|
406
|
-
};
|
|
407
|
-
/**
|
|
408
|
-
* Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
|
|
409
|
-
* Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
|
|
410
|
-
*/
|
|
411
|
-
/**
|
|
412
|
-
* Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
|
|
413
|
-
* Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
|
|
414
|
-
*
|
|
415
|
-
* The function returns a map that associates each vertex object with its corresponding depth-first
|
|
416
|
-
* number.
|
|
417
|
-
* @returns A Map object with keys of type VO and values of type number.
|
|
418
|
-
*/
|
|
419
|
-
getDFNMap(): Map<VO, number>;
|
|
420
|
-
/**
|
|
421
|
-
* The function returns a Map object that contains the low values of each vertex in a Tarjan
|
|
422
|
-
* algorithm.
|
|
423
|
-
* @returns The method `getLowMap()` is returning a `Map` object with keys of type `VO` and values of
|
|
424
|
-
* type `number`.
|
|
425
|
-
*/
|
|
426
|
-
getLowMap(): Map<VO, number>;
|
|
427
|
-
/**
|
|
428
|
-
* The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
|
|
429
|
-
* @returns an array of VO objects, specifically the cut vertexes.
|
|
430
|
-
*/
|
|
431
|
-
getCutVertexes(): VO[];
|
|
432
|
-
/**
|
|
433
|
-
* The function "getSCCs" returns a map of strongly connected components (SCCs) using the Tarjan
|
|
434
|
-
* algorithm.
|
|
435
|
-
* @returns a map where the keys are numbers and the values are arrays of VO objects.
|
|
436
|
-
*/
|
|
437
|
-
getSCCs(): Map<number, VO[]>;
|
|
438
|
-
/**
|
|
439
|
-
* The function "getBridges" returns an array of bridges using the Tarjan algorithm.
|
|
440
|
-
* @returns the bridges found using the Tarjan algorithm.
|
|
441
|
-
*/
|
|
442
|
-
getBridges(): EO[];
|
|
443
365
|
/**
|
|
444
366
|
* O(V+E+C)
|
|
445
367
|
* O(V+C)
|