data-structure-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/CHANGELOG.md +1 -1
- package/README.md +17 -15
- package/README_zh-CN.md +1 -1
- package/SPECIFICATION.md +56 -0
- package/SPONSOR-zh-CN.md +90 -0
- package/SPONSOR.md +54 -0
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +149 -155
- package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +33 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/cjs/data-structures/binary-tree/bst.js +46 -13
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +73 -15
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +35 -2
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +38 -0
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/cjs/data-structures/graph/abstract-graph.js +0 -189
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +105 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/cjs/data-structures/graph/undirected-graph.js +126 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/cjs/data-structures/hash/hash-map.js +196 -62
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +29 -19
- package/dist/cjs/data-structures/heap/heap.js +29 -20
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +83 -25
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +34 -3
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/cjs/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/cjs/data-structures/matrix/matrix.js +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +95 -21
- package/dist/cjs/data-structures/queue/deque.js +100 -16
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +65 -45
- package/dist/cjs/data-structures/queue/queue.js +65 -45
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +36 -22
- package/dist/cjs/data-structures/stack/stack.js +36 -22
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/cjs/data-structures/tree/tree.js +77 -11
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +100 -36
- package/dist/cjs/data-structures/trie/trie.js +115 -36
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +34 -2
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/mjs/data-structures/binary-tree/bst.js +46 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +74 -16
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +35 -2
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +38 -1
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/mjs/data-structures/graph/abstract-graph.js +0 -188
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/mjs/data-structures/graph/directed-graph.js +105 -0
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/mjs/data-structures/graph/undirected-graph.js +127 -19
- package/dist/mjs/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/mjs/data-structures/hash/hash-map.js +204 -70
- package/dist/mjs/data-structures/heap/heap.d.ts +29 -19
- package/dist/mjs/data-structures/heap/heap.js +29 -20
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +86 -28
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +36 -5
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/mjs/data-structures/matrix/matrix.js +1 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/mjs/data-structures/queue/deque.d.ts +95 -21
- package/dist/mjs/data-structures/queue/deque.js +105 -21
- package/dist/mjs/data-structures/queue/queue.d.ts +65 -45
- package/dist/mjs/data-structures/queue/queue.js +65 -45
- package/dist/mjs/data-structures/stack/stack.d.ts +36 -22
- package/dist/mjs/data-structures/stack/stack.js +36 -22
- package/dist/mjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/mjs/data-structures/tree/tree.js +80 -14
- package/dist/mjs/data-structures/trie/trie.d.ts +100 -36
- package/dist/mjs/data-structures/trie/trie.js +118 -39
- package/dist/umd/data-structure-typed.js +1445 -595
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +59 -58
- 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
- package/test/performance/data-structures/graph/directed-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/abstract-graph.test.ts +3 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +189 -253
- package/test/unit/data-structures/graph/undirected-graph.test.ts +263 -18
- package/test/unit/data-structures/queue/queue.test.ts +2 -0
|
@@ -6,17 +6,118 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
export class SegmentTreeNode {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The constructor initializes the properties of a SegmentTreeNode object.
|
|
11
|
+
* @param {number} start - The `start` parameter represents the starting index of the segment covered
|
|
12
|
+
* by this node in a segment tree.
|
|
13
|
+
* @param {number} end - The `end` parameter represents the end index of the segment covered by this
|
|
14
|
+
* node in a segment tree.
|
|
15
|
+
* @param {number} sum - The `sum` parameter represents the sum of the values in the range covered by
|
|
16
|
+
* the segment tree node.
|
|
17
|
+
* @param {SegmentTreeNodeVal | undefined} [value] - The `value` parameter is an optional parameter
|
|
18
|
+
* of type `SegmentTreeNodeVal`. It represents the value associated with the segment tree node.
|
|
19
|
+
*/
|
|
15
20
|
constructor(start, end, sum, value) {
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
21
|
+
this._start = start;
|
|
22
|
+
this._end = end;
|
|
23
|
+
this._sum = sum;
|
|
24
|
+
this._value = value || undefined;
|
|
25
|
+
}
|
|
26
|
+
_start = 0;
|
|
27
|
+
/**
|
|
28
|
+
* The function returns the value of the protected variable _start.
|
|
29
|
+
* @returns The start value, which is of type number.
|
|
30
|
+
*/
|
|
31
|
+
get start() {
|
|
32
|
+
return this._start;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The above function sets the value of the "start" property.
|
|
36
|
+
* @param {number} value - The value parameter is of type number.
|
|
37
|
+
*/
|
|
38
|
+
set start(value) {
|
|
39
|
+
this._start = value;
|
|
40
|
+
}
|
|
41
|
+
_end = 0;
|
|
42
|
+
/**
|
|
43
|
+
* The function returns the value of the protected variable `_end`.
|
|
44
|
+
* @returns The value of the protected property `_end`.
|
|
45
|
+
*/
|
|
46
|
+
get end() {
|
|
47
|
+
return this._end;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The above function sets the value of the "end" property.
|
|
51
|
+
* @param {number} value - The value parameter is a number that represents the new value for the end
|
|
52
|
+
* property.
|
|
53
|
+
*/
|
|
54
|
+
set end(value) {
|
|
55
|
+
this._end = value;
|
|
56
|
+
}
|
|
57
|
+
_value = undefined;
|
|
58
|
+
/**
|
|
59
|
+
* The function returns the value of a segment tree node.
|
|
60
|
+
* @returns The value being returned is either a `SegmentTreeNodeVal` object or `undefined`.
|
|
61
|
+
*/
|
|
62
|
+
get value() {
|
|
63
|
+
return this._value;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The function sets the value of a segment tree node.
|
|
67
|
+
* @param {SegmentTreeNodeVal | undefined} value - The `value` parameter is of type
|
|
68
|
+
* `SegmentTreeNodeVal` or `undefined`.
|
|
69
|
+
*/
|
|
70
|
+
set value(value) {
|
|
71
|
+
this._value = value;
|
|
72
|
+
}
|
|
73
|
+
_sum = 0;
|
|
74
|
+
/**
|
|
75
|
+
* The function returns the value of the sum property.
|
|
76
|
+
* @returns The method is returning the value of the variable `_sum`.
|
|
77
|
+
*/
|
|
78
|
+
get sum() {
|
|
79
|
+
return this._sum;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The above function sets the value of the sum property.
|
|
83
|
+
* @param {number} value - The parameter "value" is of type "number".
|
|
84
|
+
*/
|
|
85
|
+
set sum(value) {
|
|
86
|
+
this._sum = value;
|
|
87
|
+
}
|
|
88
|
+
_left = undefined;
|
|
89
|
+
/**
|
|
90
|
+
* The function returns the left child of a segment tree node.
|
|
91
|
+
* @returns The `left` property of the `SegmentTreeNode` object is being returned. It is of type
|
|
92
|
+
* `SegmentTreeNode` or `undefined`.
|
|
93
|
+
*/
|
|
94
|
+
get left() {
|
|
95
|
+
return this._left;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The function sets the value of the left property of a SegmentTreeNode object.
|
|
99
|
+
* @param {SegmentTreeNode | undefined} value - The value parameter is of type SegmentTreeNode or
|
|
100
|
+
* undefined.
|
|
101
|
+
*/
|
|
102
|
+
set left(value) {
|
|
103
|
+
this._left = value;
|
|
104
|
+
}
|
|
105
|
+
_right = undefined;
|
|
106
|
+
/**
|
|
107
|
+
* The function returns the right child of a segment tree node.
|
|
108
|
+
* @returns The `getRight()` method is returning a value of type `SegmentTreeNode` or `undefined`.
|
|
109
|
+
*/
|
|
110
|
+
get right() {
|
|
111
|
+
return this._right;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The function sets the right child of a segment tree node.
|
|
115
|
+
* @param {SegmentTreeNode | undefined} value - The `value` parameter is of type `SegmentTreeNode |
|
|
116
|
+
* undefined`. This means that it can accept either a `SegmentTreeNode` object or `undefined` as its
|
|
117
|
+
* value.
|
|
118
|
+
*/
|
|
119
|
+
set right(value) {
|
|
120
|
+
this._right = value;
|
|
20
121
|
}
|
|
21
122
|
}
|
|
22
123
|
export class SegmentTree {
|
|
@@ -44,18 +145,34 @@ export class SegmentTree {
|
|
|
44
145
|
}
|
|
45
146
|
}
|
|
46
147
|
_values = [];
|
|
148
|
+
/**
|
|
149
|
+
* The function returns an array of numbers.
|
|
150
|
+
* @returns An array of numbers is being returned.
|
|
151
|
+
*/
|
|
47
152
|
get values() {
|
|
48
153
|
return this._values;
|
|
49
154
|
}
|
|
50
155
|
_start = 0;
|
|
156
|
+
/**
|
|
157
|
+
* The function returns the value of the protected variable _start.
|
|
158
|
+
* @returns The start value, which is of type number.
|
|
159
|
+
*/
|
|
51
160
|
get start() {
|
|
52
161
|
return this._start;
|
|
53
162
|
}
|
|
54
163
|
_end;
|
|
164
|
+
/**
|
|
165
|
+
* The function returns the value of the protected variable `_end`.
|
|
166
|
+
* @returns The value of the protected property `_end`.
|
|
167
|
+
*/
|
|
55
168
|
get end() {
|
|
56
169
|
return this._end;
|
|
57
170
|
}
|
|
58
171
|
_root;
|
|
172
|
+
/**
|
|
173
|
+
* The function returns the root node of a segment tree.
|
|
174
|
+
* @returns The `root` property of the class `SegmentTreeNode` or `undefined` if it is not defined.
|
|
175
|
+
*/
|
|
59
176
|
get root() {
|
|
60
177
|
return this._root;
|
|
61
178
|
}
|
|
@@ -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
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FamilyPosition, IterationType } from '../../types';
|
|
2
2
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
3
3
|
export class TreeMultimapNode extends AVLTreeNode {
|
|
4
|
-
count;
|
|
5
4
|
/**
|
|
6
5
|
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
7
6
|
* @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
|
|
@@ -16,6 +15,22 @@ export class TreeMultimapNode extends AVLTreeNode {
|
|
|
16
15
|
super(key, value);
|
|
17
16
|
this.count = count;
|
|
18
17
|
}
|
|
18
|
+
_count = 1;
|
|
19
|
+
/**
|
|
20
|
+
* The function returns the value of the protected variable _count.
|
|
21
|
+
* @returns The count property of the object, which is of type number.
|
|
22
|
+
*/
|
|
23
|
+
get count() {
|
|
24
|
+
return this._count;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The above function sets the value of the count property.
|
|
28
|
+
* @param {number} value - The value parameter is of type number, which means it can accept any
|
|
29
|
+
* numeric value.
|
|
30
|
+
*/
|
|
31
|
+
set count(value) {
|
|
32
|
+
this._count = value;
|
|
33
|
+
}
|
|
19
34
|
}
|
|
20
35
|
/**
|
|
21
36
|
* 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,6 +43,11 @@ export class TreeMultimap extends AVLTree {
|
|
|
28
43
|
}
|
|
29
44
|
_count = 0;
|
|
30
45
|
// TODO the _count is not accurate after nodes count modified
|
|
46
|
+
/**
|
|
47
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
48
|
+
* search.
|
|
49
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
50
|
+
*/
|
|
31
51
|
get count() {
|
|
32
52
|
let sum = 0;
|
|
33
53
|
this.dfs(node => (sum += node.count));
|
|
@@ -45,6 +65,15 @@ export class TreeMultimap extends AVLTree {
|
|
|
45
65
|
createNode(key, value, count) {
|
|
46
66
|
return new TreeMultimapNode(key, value, count);
|
|
47
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* The function creates a new TreeMultimap object with the specified options and returns it.
|
|
70
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
71
|
+
* configuration options for creating the `TreeMultimap` object. It can include properties such as
|
|
72
|
+
* `iterationType` and `variant`, which are used to specify the type of iteration and the variant of
|
|
73
|
+
* the tree, respectively. These properties can be
|
|
74
|
+
* @returns a new instance of the `TreeMultimap` class, with the provided options merged with the
|
|
75
|
+
* default options. The returned value is casted as `TREE`.
|
|
76
|
+
*/
|
|
48
77
|
createTree(options) {
|
|
49
78
|
return new TreeMultimap([], {
|
|
50
79
|
iterationType: this.iterationType,
|
|
@@ -319,6 +348,14 @@ export class TreeMultimap extends AVLTree {
|
|
|
319
348
|
}
|
|
320
349
|
return undefined;
|
|
321
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
353
|
+
* @param {NODE} oldNode - The `oldNode` parameter is of type `NODE` and represents the node that
|
|
354
|
+
* needs to be replaced in a data structure.
|
|
355
|
+
* @param {NODE} newNode - The `newNode` parameter is an object of type `NODE`.
|
|
356
|
+
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
357
|
+
* superclass, after updating the `count` property of the `newNode` object.
|
|
358
|
+
*/
|
|
322
359
|
_replaceNode(oldNode, newNode) {
|
|
323
360
|
newNode.count = oldNode.count + newNode.count;
|
|
324
361
|
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)
|
|
@@ -816,194 +816,6 @@ export class AbstractGraph extends IterableEntryBase {
|
|
|
816
816
|
}
|
|
817
817
|
return { costs, predecessor };
|
|
818
818
|
}
|
|
819
|
-
/**
|
|
820
|
-
* Time Complexity: O(V + E) - Linear time (Tarjan's algorithm).
|
|
821
|
-
* Space Complexity: O(V) - Linear space (Tarjan's algorithm).
|
|
822
|
-
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
823
|
-
* Tarjan can find cycles in directed or undirected graph
|
|
824
|
-
* Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time,
|
|
825
|
-
* Tarjan solve the bi-connected components of undirected graphs;
|
|
826
|
-
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
827
|
-
* /
|
|
828
|
-
|
|
829
|
-
/**
|
|
830
|
-
* Time Complexity: O(V + E) - Linear time (Tarjan's algorithm).
|
|
831
|
-
* Space Complexity: O(V) - Linear space (Tarjan's algorithm).
|
|
832
|
-
*
|
|
833
|
-
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
834
|
-
* Tarjan can find cycles in directed or undirected graph
|
|
835
|
-
* Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time,
|
|
836
|
-
* Tarjan solve the bi-connected components of undirected graphs;
|
|
837
|
-
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
838
|
-
* The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
|
|
839
|
-
* strongly connected components (SCCs), and cycles in a graph.
|
|
840
|
-
* @param {boolean} [needCutVertexes] - A boolean value indicating whether or not to calculate and return the
|
|
841
|
-
* articulation points in the graph. Articulation points are the vertexMap in a graph whose removal would increase the
|
|
842
|
-
* number of connected components in the graph.
|
|
843
|
-
* @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
|
|
844
|
-
* (edgeMap whose removal would increase the number of connected components in the graph).
|
|
845
|
-
* @param {boolean} [needSCCs] - A boolean value indicating whether the Strongly Connected Components (SCCs) of the
|
|
846
|
-
* graph are needed. If set to true, the function will calculate and return the SCCs of the graph. If set to false, the
|
|
847
|
-
* SCCs will not be calculated or returned.
|
|
848
|
-
* @param {boolean} [needCycles] - A boolean flag indicating whether the algorithm should find cycles in the graph. If
|
|
849
|
-
* set to true, the algorithm will return a map of cycles, where the keys are the low values of the SCCs and the values
|
|
850
|
-
* are arrays of vertexMap that form cycles within the SCCs.
|
|
851
|
-
* @returns The function `tarjan` returns an object with the following properties:
|
|
852
|
-
*/
|
|
853
|
-
tarjan(needCutVertexes = false, needBridges = false, needSCCs = true, needCycles = false) {
|
|
854
|
-
// !! in undirected graph we will not let child visit parent when dfs
|
|
855
|
-
// !! articulation point(in dfs search tree not in graph): (cur !== root && cur.has(child)) && (low(child) >= dfn(cur)) || (cur === root && cur.children() >= 2)
|
|
856
|
-
// !! bridge: low(child) > dfn(cur)
|
|
857
|
-
const defaultConfig = false;
|
|
858
|
-
if (needCutVertexes === undefined)
|
|
859
|
-
needCutVertexes = defaultConfig;
|
|
860
|
-
if (needBridges === undefined)
|
|
861
|
-
needBridges = defaultConfig;
|
|
862
|
-
if (needSCCs === undefined)
|
|
863
|
-
needSCCs = defaultConfig;
|
|
864
|
-
if (needCycles === undefined)
|
|
865
|
-
needCycles = defaultConfig;
|
|
866
|
-
const dfnMap = new Map();
|
|
867
|
-
const lowMap = new Map();
|
|
868
|
-
const vertexMap = this._vertexMap;
|
|
869
|
-
vertexMap.forEach(v => {
|
|
870
|
-
dfnMap.set(v, -1);
|
|
871
|
-
lowMap.set(v, Infinity);
|
|
872
|
-
});
|
|
873
|
-
const [root] = vertexMap.values();
|
|
874
|
-
const cutVertexes = [];
|
|
875
|
-
const bridges = [];
|
|
876
|
-
let dfn = 0;
|
|
877
|
-
const dfs = (cur, parent) => {
|
|
878
|
-
dfn++;
|
|
879
|
-
dfnMap.set(cur, dfn);
|
|
880
|
-
lowMap.set(cur, dfn);
|
|
881
|
-
const neighbors = this.getNeighbors(cur);
|
|
882
|
-
let childCount = 0; // child in dfs tree not child in graph
|
|
883
|
-
for (const neighbor of neighbors) {
|
|
884
|
-
if (neighbor !== parent) {
|
|
885
|
-
if (dfnMap.get(neighbor) === -1) {
|
|
886
|
-
childCount++;
|
|
887
|
-
dfs(neighbor, cur);
|
|
888
|
-
}
|
|
889
|
-
const childLow = lowMap.get(neighbor);
|
|
890
|
-
const curLow = lowMap.get(cur);
|
|
891
|
-
// TODO after no-non-undefined-assertion not ensure the logic
|
|
892
|
-
if (curLow !== undefined && childLow !== undefined) {
|
|
893
|
-
lowMap.set(cur, Math.min(curLow, childLow));
|
|
894
|
-
}
|
|
895
|
-
const curFromMap = dfnMap.get(cur);
|
|
896
|
-
if (childLow !== undefined && curFromMap !== undefined) {
|
|
897
|
-
if (needCutVertexes) {
|
|
898
|
-
if ((cur === root && childCount >= 2) || (cur !== root && childLow >= curFromMap)) {
|
|
899
|
-
// todo not ensure the logic if (cur === root && childCount >= 2 || ((cur !== root) && (childLow >= curFromMap))) {
|
|
900
|
-
cutVertexes.push(cur);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
if (needBridges) {
|
|
904
|
-
if (childLow > curFromMap) {
|
|
905
|
-
const edgeCurToNeighbor = this.getEdge(cur, neighbor);
|
|
906
|
-
if (edgeCurToNeighbor) {
|
|
907
|
-
bridges.push(edgeCurToNeighbor);
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
dfs(root, undefined);
|
|
916
|
-
let SCCs = new Map();
|
|
917
|
-
const getSCCs = () => {
|
|
918
|
-
const SCCs = new Map();
|
|
919
|
-
lowMap.forEach((low, vertex) => {
|
|
920
|
-
if (!SCCs.has(low)) {
|
|
921
|
-
SCCs.set(low, [vertex]);
|
|
922
|
-
}
|
|
923
|
-
else {
|
|
924
|
-
SCCs.get(low)?.push(vertex);
|
|
925
|
-
}
|
|
926
|
-
});
|
|
927
|
-
return SCCs;
|
|
928
|
-
};
|
|
929
|
-
if (needSCCs) {
|
|
930
|
-
SCCs = getSCCs();
|
|
931
|
-
}
|
|
932
|
-
const cycles = new Map();
|
|
933
|
-
if (needCycles) {
|
|
934
|
-
const visitedMap = new Map();
|
|
935
|
-
const stack = [];
|
|
936
|
-
const findCyclesDFS = (cur, parent) => {
|
|
937
|
-
visitedMap.set(cur, true);
|
|
938
|
-
stack.push(cur);
|
|
939
|
-
const neighbors = this.getNeighbors(cur);
|
|
940
|
-
for (const neighbor of neighbors) {
|
|
941
|
-
if (!visitedMap.get(neighbor)) {
|
|
942
|
-
findCyclesDFS(neighbor, cur);
|
|
943
|
-
}
|
|
944
|
-
else if (stack.includes(neighbor) && neighbor !== parent) {
|
|
945
|
-
const cycleStartIndex = stack.indexOf(neighbor);
|
|
946
|
-
const cycle = stack.slice(cycleStartIndex);
|
|
947
|
-
const cycleLow = Math.min(...cycle.map(v => dfnMap.get(v) || Infinity));
|
|
948
|
-
cycles.set(cycleLow, cycle);
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
stack.pop();
|
|
952
|
-
};
|
|
953
|
-
vertexMap.forEach(v => {
|
|
954
|
-
if (!visitedMap.get(v)) {
|
|
955
|
-
findCyclesDFS(v, undefined);
|
|
956
|
-
}
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
return { dfnMap, lowMap, bridges, cutVertexes, SCCs, cycles };
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
|
|
963
|
-
* Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
|
|
964
|
-
*/
|
|
965
|
-
/**
|
|
966
|
-
* Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
|
|
967
|
-
* Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
|
|
968
|
-
*
|
|
969
|
-
* The function returns a map that associates each vertex object with its corresponding depth-first
|
|
970
|
-
* number.
|
|
971
|
-
* @returns A Map object with keys of type VO and values of type number.
|
|
972
|
-
*/
|
|
973
|
-
getDFNMap() {
|
|
974
|
-
return this.tarjan(false, false, false, false).dfnMap;
|
|
975
|
-
}
|
|
976
|
-
/**
|
|
977
|
-
* The function returns a Map object that contains the low values of each vertex in a Tarjan
|
|
978
|
-
* algorithm.
|
|
979
|
-
* @returns The method `getLowMap()` is returning a `Map` object with keys of type `VO` and values of
|
|
980
|
-
* type `number`.
|
|
981
|
-
*/
|
|
982
|
-
getLowMap() {
|
|
983
|
-
return this.tarjan(false, false, false, false).lowMap;
|
|
984
|
-
}
|
|
985
|
-
/**
|
|
986
|
-
* The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
|
|
987
|
-
* @returns an array of VO objects, specifically the cut vertexes.
|
|
988
|
-
*/
|
|
989
|
-
getCutVertexes() {
|
|
990
|
-
return this.tarjan(true, false, false, false).cutVertexes;
|
|
991
|
-
}
|
|
992
|
-
/**
|
|
993
|
-
* The function "getSCCs" returns a map of strongly connected components (SCCs) using the Tarjan
|
|
994
|
-
* algorithm.
|
|
995
|
-
* @returns a map where the keys are numbers and the values are arrays of VO objects.
|
|
996
|
-
*/
|
|
997
|
-
getSCCs() {
|
|
998
|
-
return this.tarjan(false, false, true, false).SCCs;
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
* The function "getBridges" returns an array of bridges using the Tarjan algorithm.
|
|
1002
|
-
* @returns the bridges found using the Tarjan algorithm.
|
|
1003
|
-
*/
|
|
1004
|
-
getBridges() {
|
|
1005
|
-
return this.tarjan(false, true, false, false).bridges;
|
|
1006
|
-
}
|
|
1007
819
|
/**
|
|
1008
820
|
* O(V+E+C)
|
|
1009
821
|
* O(V+C)
|
|
@@ -335,12 +335,71 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
335
335
|
* @return A boolean value
|
|
336
336
|
*/
|
|
337
337
|
isEmpty(): boolean;
|
|
338
|
+
/**
|
|
339
|
+
* Time Complexity: O(1)
|
|
340
|
+
* Space Complexity: O(1)
|
|
341
|
+
*/
|
|
342
|
+
/**
|
|
343
|
+
* Time Complexity: O(1)
|
|
344
|
+
* Space Complexity: O(1)
|
|
345
|
+
*
|
|
346
|
+
* The clear function resets the vertex map, in-edge map, and out-edge map.
|
|
347
|
+
*/
|
|
348
|
+
clear(): void;
|
|
338
349
|
/**
|
|
339
350
|
* The clone function creates a new DirectedGraph object with the same vertices and edges as the original.
|
|
340
351
|
*
|
|
341
352
|
* @return A new instance of the directedgraph class
|
|
342
353
|
*/
|
|
343
354
|
clone(): DirectedGraph<V, E, VO, EO>;
|
|
355
|
+
/**
|
|
356
|
+
* Time Complexity: O(V + E)
|
|
357
|
+
* Space Complexity: O(V)
|
|
358
|
+
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
359
|
+
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
360
|
+
*/
|
|
361
|
+
/**
|
|
362
|
+
* Time Complexity: O(V + E)
|
|
363
|
+
* Space Complexity: O(V)
|
|
364
|
+
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
365
|
+
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
366
|
+
*
|
|
367
|
+
* The function `tarjan` implements the Tarjan's algorithm to find strongly connected components in a
|
|
368
|
+
* graph.
|
|
369
|
+
* @returns The function `tarjan()` returns an object with three properties: `dfnMap`, `lowMap`, and
|
|
370
|
+
* `SCCs`.
|
|
371
|
+
*/
|
|
372
|
+
tarjan(): {
|
|
373
|
+
dfnMap: Map<VO, number>;
|
|
374
|
+
lowMap: Map<VO, number>;
|
|
375
|
+
SCCs: Map<number, VO[]>;
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
|
|
379
|
+
* Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
|
|
380
|
+
*/
|
|
381
|
+
/**
|
|
382
|
+
* Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
|
|
383
|
+
* Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
|
|
384
|
+
*
|
|
385
|
+
* The function returns a map that associates each vertex object with its corresponding depth-first
|
|
386
|
+
* number.
|
|
387
|
+
* @returns A Map object with keys of type VO and values of type number.
|
|
388
|
+
*/
|
|
389
|
+
getDFNMap(): Map<VO, number>;
|
|
390
|
+
/**
|
|
391
|
+
* The function returns a Map object that contains the low values of each vertex in a Tarjan
|
|
392
|
+
* algorithm.
|
|
393
|
+
* @returns The method `getLowMap()` is returning a `Map` object with keys of type `VO` and values of
|
|
394
|
+
* type `number`.
|
|
395
|
+
*/
|
|
396
|
+
getLowMap(): Map<VO, number>;
|
|
397
|
+
/**
|
|
398
|
+
* The function "getSCCs" returns a map of strongly connected components (SCCs) using the Tarjan
|
|
399
|
+
* algorithm.
|
|
400
|
+
* @returns a map where the keys are numbers and the values are arrays of VO objects.
|
|
401
|
+
*/
|
|
402
|
+
getSCCs(): Map<number, VO[]>;
|
|
344
403
|
/**
|
|
345
404
|
* Time Complexity: O(1)
|
|
346
405
|
* Space Complexity: O(1)
|