data-structure-typed 0.8.18 → 1.12.9
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/.dependency-cruiser.js +449 -0
- package/.idea/data-structure-typed.iml +2 -0
- package/.idea/modules.xml +1 -1
- package/README.md +298 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
- package/dist/data-structures/binary-tree/avl-tree.js +150 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
- package/dist/data-structures/binary-tree/binary-tree.js +747 -369
- package/dist/data-structures/binary-tree/bst.d.ts +20 -8
- package/dist/data-structures/binary-tree/bst.js +164 -107
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
- package/dist/data-structures/binary-tree/segment-tree.js +95 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
- package/dist/data-structures/graph/abstract-graph.js +712 -323
- package/dist/data-structures/graph/directed-graph.d.ts +114 -12
- package/dist/data-structures/graph/directed-graph.js +372 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
- package/dist/data-structures/graph/undirected-graph.js +233 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
- package/dist/data-structures/hash/coordinate-map.js +70 -20
- package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
- package/dist/data-structures/hash/coordinate-set.js +58 -15
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/heap/heap.d.ts +26 -37
- package/dist/data-structures/heap/heap.js +56 -60
- package/dist/data-structures/heap/max-heap.d.ts +8 -2
- package/dist/data-structures/heap/max-heap.js +32 -9
- package/dist/data-structures/heap/min-heap.d.ts +9 -2
- package/dist/data-structures/heap/min-heap.js +33 -9
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
- package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
- package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
- package/dist/data-structures/matrix/matrix.d.ts +9 -0
- package/dist/data-structures/matrix/matrix.js +19 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
- package/dist/data-structures/matrix/matrix2d.js +158 -61
- package/dist/data-structures/matrix/navigator.d.ts +34 -16
- package/dist/data-structures/matrix/navigator.js +65 -18
- package/dist/data-structures/matrix/vector2d.d.ts +153 -29
- package/dist/data-structures/matrix/vector2d.js +249 -102
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
- package/dist/data-structures/priority-queue/priority-queue.js +285 -116
- package/dist/data-structures/queue/deque.d.ts +69 -0
- package/dist/data-structures/queue/deque.js +151 -56
- package/dist/data-structures/queue/queue.d.ts +34 -37
- package/dist/data-structures/queue/queue.js +59 -61
- package/dist/data-structures/stack/stack.d.ts +29 -35
- package/dist/data-structures/stack/stack.js +51 -56
- package/dist/data-structures/trie/trie.d.ts +36 -6
- package/dist/data-structures/trie/trie.js +256 -83
- package/dist/data-structures/types/abstract-graph.d.ts +29 -0
- package/dist/data-structures/types/abstract-graph.js +2 -0
- package/dist/data-structures/types/avl-tree.d.ts +5 -0
- package/dist/data-structures/types/avl-tree.js +2 -0
- package/dist/data-structures/types/binary-tree.d.ts +16 -0
- package/dist/data-structures/types/binary-tree.js +2 -0
- package/dist/data-structures/types/bst.d.ts +7 -0
- package/dist/data-structures/types/bst.js +2 -0
- package/dist/data-structures/types/directed-graph.d.ts +10 -0
- package/dist/data-structures/types/directed-graph.js +2 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/types/doubly-linked-list.js +2 -0
- package/dist/data-structures/types/heap.d.ts +7 -0
- package/dist/data-structures/types/heap.js +2 -0
- package/dist/data-structures/types/index.d.ts +13 -0
- package/dist/data-structures/types/index.js +29 -0
- package/dist/data-structures/types/navigator.d.ts +14 -0
- package/dist/data-structures/types/navigator.js +2 -0
- package/dist/data-structures/types/priority-queue.d.ts +7 -0
- package/dist/data-structures/types/priority-queue.js +2 -0
- package/dist/data-structures/types/segment-tree.d.ts +1 -0
- package/dist/data-structures/types/segment-tree.js +2 -0
- package/dist/data-structures/types/singly-linked-list.js +2 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -0
- package/dist/data-structures/types/tree-multiset.js +2 -0
- package/dist/utils/trampoline.d.ts +14 -0
- package/dist/utils/trampoline.js +130 -0
- package/dist/utils/types/index.js +17 -0
- package/dist/{types → utils}/types/utils.d.ts +15 -1
- package/dist/{types → utils/types}/utils.js +21 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
- package/dist/utils/utils.js +651 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +85 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1367 -0
- package/docs/classes/AVLTree.html +2046 -0
- package/docs/classes/AVLTreeNode.html +423 -0
- package/docs/classes/AaTree.html +117 -0
- package/docs/classes/AbstractEdge.html +198 -0
- package/docs/classes/AbstractGraph.html +891 -0
- package/docs/classes/AbstractVertex.html +164 -0
- package/docs/classes/ArrayDeque.html +384 -0
- package/docs/classes/BST.html +1893 -0
- package/docs/classes/BSTNode.html +425 -0
- package/docs/classes/BTree.html +117 -0
- package/docs/classes/BinaryIndexedTree.html +244 -0
- package/docs/classes/BinaryTree.html +1754 -0
- package/docs/classes/BinaryTreeNode.html +396 -0
- package/docs/classes/Character.html +165 -0
- package/docs/classes/CoordinateMap.html +394 -0
- package/docs/classes/CoordinateSet.html +355 -0
- package/docs/classes/Deque.html +617 -0
- package/docs/classes/DirectedEdge.html +247 -0
- package/docs/classes/DirectedGraph.html +1207 -0
- package/docs/classes/DirectedVertex.html +154 -0
- package/docs/classes/DoublyLinkedList.html +619 -0
- package/docs/classes/DoublyLinkedListNode.html +160 -0
- package/docs/classes/Heap.html +315 -0
- package/docs/classes/Matrix2D.html +447 -0
- package/docs/classes/MatrixNTI2D.html +181 -0
- package/docs/classes/MaxHeap.html +325 -0
- package/docs/classes/MaxPriorityQueue.html +668 -0
- package/docs/classes/MinHeap.html +326 -0
- package/docs/classes/MinPriorityQueue.html +668 -0
- package/docs/classes/Navigator.html +285 -0
- package/docs/classes/ObjectDeque.html +289 -0
- package/docs/classes/PriorityQueue.html +643 -0
- package/docs/classes/Queue.html +337 -0
- package/docs/classes/RBTree.html +117 -0
- package/docs/classes/SegmentTree.html +234 -0
- package/docs/classes/SegmentTreeNode.html +302 -0
- package/docs/classes/SinglyLinkedList.html +1035 -0
- package/docs/classes/SinglyLinkedListNode.html +304 -0
- package/docs/classes/SplayTree.html +117 -0
- package/docs/classes/Stack.html +313 -0
- package/docs/classes/TreeMultiSet.html +1897 -0
- package/docs/classes/Trie.html +317 -0
- package/docs/classes/TrieNode.html +221 -0
- package/docs/classes/TwoThreeTree.html +117 -0
- package/docs/classes/UndirectedEdge.html +220 -0
- package/docs/classes/UndirectedGraph.html +1006 -0
- package/docs/classes/UndirectedVertex.html +154 -0
- package/docs/classes/Vector2D.html +746 -0
- package/docs/enums/CP.html +126 -0
- package/docs/enums/FamilyPosition.html +126 -0
- package/docs/enums/LoopType.html +119 -0
- package/docs/index.html +288 -0
- package/docs/modules.html +146 -0
- package/jest.config.js +5 -0
- package/package.json +33 -47
- package/rename_clear_files.sh +29 -0
- package/src/assets/complexities-diff.jpg +0 -0
- package/src/assets/data-structure-complexities.jpg +0 -0
- package/src/data-structures/binary-tree/avl-tree.ts +58 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
- package/src/data-structures/binary-tree/binary-tree.ts +460 -145
- package/src/data-structures/binary-tree/bst.ts +31 -25
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/segment-tree.ts +25 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
- package/src/data-structures/diagrams/README.md +5 -0
- package/src/data-structures/graph/abstract-graph.ts +224 -108
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/src/data-structures/graph/directed-graph.ts +132 -26
- package/src/data-structures/graph/undirected-graph.ts +78 -11
- package/src/data-structures/hash/coordinate-map.ts +33 -1
- package/src/data-structures/hash/coordinate-set.ts +25 -0
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +27 -41
- package/src/data-structures/heap/max-heap.ts +8 -2
- package/src/data-structures/heap/min-heap.ts +9 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
- package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
- package/src/data-structures/matrix/matrix.ts +11 -0
- package/src/data-structures/matrix/matrix2d.ts +90 -10
- package/src/data-structures/matrix/navigator.ts +34 -14
- package/src/data-structures/matrix/vector2d.ts +187 -63
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
- package/src/data-structures/priority-queue/priority-queue.ts +200 -78
- package/src/data-structures/queue/deque.ts +71 -2
- package/src/data-structures/queue/queue.ts +37 -40
- package/src/data-structures/stack/stack.ts +32 -38
- package/src/data-structures/trie/trie.ts +83 -14
- package/src/data-structures/types/abstract-graph.ts +51 -0
- package/src/data-structures/types/avl-tree.ts +6 -0
- package/src/data-structures/types/binary-tree.ts +15 -0
- package/src/data-structures/types/bst.ts +5 -0
- package/src/data-structures/types/directed-graph.ts +18 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +8 -0
- package/src/data-structures/types/index.ts +13 -0
- package/src/data-structures/types/navigator.ts +13 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +1 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/trampoline.ts +51 -0
- package/src/utils/types/index.ts +1 -0
- package/src/{types → utils/types}/utils.ts +27 -5
- package/src/{utils.ts → utils/utils.ts} +41 -131
- package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
- package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
- package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
- package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
- package/tsconfig.json +9 -6
- package/dist/data-structures/trampoline.d.ts +0 -25
- package/dist/data-structures/trampoline.js +0 -52
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/pair.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/index.d.ts +0 -9
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/data-structures/trampoline.ts +0 -91
- package/src/types/index.ts +0 -1
- /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /package/dist/{types → utils}/index.js +0 -0
- /package/dist/{types → utils}/types/index.d.ts +0 -0
- /package/{src/types/patches/index.d.ts → tests/unit/data-structures/graph/abstract-graph.ts} +0 -0
|
@@ -1,44 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
2
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
7
|
exports.SegmentTree = exports.SegmentTreeNode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return this._start;
|
|
7
|
-
}
|
|
8
|
-
set start(v) {
|
|
9
|
-
this._start = v;
|
|
10
|
-
}
|
|
11
|
-
get end() {
|
|
12
|
-
return this._end;
|
|
13
|
-
}
|
|
14
|
-
set end(v) {
|
|
15
|
-
this._end = v;
|
|
16
|
-
}
|
|
17
|
-
get val() {
|
|
18
|
-
return this._val;
|
|
19
|
-
}
|
|
20
|
-
set val(v) {
|
|
21
|
-
this._val = v;
|
|
22
|
-
}
|
|
23
|
-
get sum() {
|
|
24
|
-
return this._sum;
|
|
25
|
-
}
|
|
26
|
-
set sum(v) {
|
|
27
|
-
this._sum = v;
|
|
28
|
-
}
|
|
29
|
-
get left() {
|
|
30
|
-
return this._left;
|
|
31
|
-
}
|
|
32
|
-
set left(v) {
|
|
33
|
-
this._left = v;
|
|
34
|
-
}
|
|
35
|
-
get right() {
|
|
36
|
-
return this._right;
|
|
37
|
-
}
|
|
38
|
-
set right(v) {
|
|
39
|
-
this._right = v;
|
|
40
|
-
}
|
|
41
|
-
constructor(start, end, sum, val) {
|
|
8
|
+
var SegmentTreeNode = /** @class */ (function () {
|
|
9
|
+
function SegmentTreeNode(start, end, sum, val) {
|
|
42
10
|
this._start = 0;
|
|
43
11
|
this._end = 0;
|
|
44
12
|
this._val = null;
|
|
@@ -50,13 +18,71 @@ class SegmentTreeNode {
|
|
|
50
18
|
this._sum = sum;
|
|
51
19
|
this._val = val || null;
|
|
52
20
|
}
|
|
53
|
-
|
|
21
|
+
Object.defineProperty(SegmentTreeNode.prototype, "start", {
|
|
22
|
+
get: function () {
|
|
23
|
+
return this._start;
|
|
24
|
+
},
|
|
25
|
+
set: function (v) {
|
|
26
|
+
this._start = v;
|
|
27
|
+
},
|
|
28
|
+
enumerable: false,
|
|
29
|
+
configurable: true
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(SegmentTreeNode.prototype, "end", {
|
|
32
|
+
get: function () {
|
|
33
|
+
return this._end;
|
|
34
|
+
},
|
|
35
|
+
set: function (v) {
|
|
36
|
+
this._end = v;
|
|
37
|
+
},
|
|
38
|
+
enumerable: false,
|
|
39
|
+
configurable: true
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(SegmentTreeNode.prototype, "val", {
|
|
42
|
+
get: function () {
|
|
43
|
+
return this._val;
|
|
44
|
+
},
|
|
45
|
+
set: function (v) {
|
|
46
|
+
this._val = v;
|
|
47
|
+
},
|
|
48
|
+
enumerable: false,
|
|
49
|
+
configurable: true
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(SegmentTreeNode.prototype, "sum", {
|
|
52
|
+
get: function () {
|
|
53
|
+
return this._sum;
|
|
54
|
+
},
|
|
55
|
+
set: function (v) {
|
|
56
|
+
this._sum = v;
|
|
57
|
+
},
|
|
58
|
+
enumerable: false,
|
|
59
|
+
configurable: true
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(SegmentTreeNode.prototype, "left", {
|
|
62
|
+
get: function () {
|
|
63
|
+
return this._left;
|
|
64
|
+
},
|
|
65
|
+
set: function (v) {
|
|
66
|
+
this._left = v;
|
|
67
|
+
},
|
|
68
|
+
enumerable: false,
|
|
69
|
+
configurable: true
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(SegmentTreeNode.prototype, "right", {
|
|
72
|
+
get: function () {
|
|
73
|
+
return this._right;
|
|
74
|
+
},
|
|
75
|
+
set: function (v) {
|
|
76
|
+
this._right = v;
|
|
77
|
+
},
|
|
78
|
+
enumerable: false,
|
|
79
|
+
configurable: true
|
|
80
|
+
});
|
|
81
|
+
return SegmentTreeNode;
|
|
82
|
+
}());
|
|
54
83
|
exports.SegmentTreeNode = SegmentTreeNode;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return this._root;
|
|
58
|
-
}
|
|
59
|
-
constructor(values, start, end) {
|
|
84
|
+
var SegmentTree = /** @class */ (function () {
|
|
85
|
+
function SegmentTree(values, start, end) {
|
|
60
86
|
this._values = [];
|
|
61
87
|
this._start = 0;
|
|
62
88
|
start = start || 0;
|
|
@@ -66,30 +92,37 @@ class SegmentTree {
|
|
|
66
92
|
this._end = end;
|
|
67
93
|
this._root = this.build(start, end);
|
|
68
94
|
}
|
|
69
|
-
|
|
95
|
+
Object.defineProperty(SegmentTree.prototype, "root", {
|
|
96
|
+
get: function () {
|
|
97
|
+
return this._root;
|
|
98
|
+
},
|
|
99
|
+
enumerable: false,
|
|
100
|
+
configurable: true
|
|
101
|
+
});
|
|
102
|
+
SegmentTree.prototype.build = function (start, end) {
|
|
70
103
|
if (start === end) {
|
|
71
104
|
return new SegmentTreeNode(start, end, this._values[start]);
|
|
72
105
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
106
|
+
var mid = start + Math.floor((end - start) / 2);
|
|
107
|
+
var left = this.build(start, mid);
|
|
108
|
+
var right = this.build(mid + 1, end);
|
|
109
|
+
var cur = new SegmentTreeNode(start, end, left.sum + right.sum);
|
|
77
110
|
cur.left = left;
|
|
78
111
|
cur.right = right;
|
|
79
112
|
return cur;
|
|
80
|
-
}
|
|
81
|
-
updateNode(index, sum, val) {
|
|
82
|
-
|
|
113
|
+
};
|
|
114
|
+
SegmentTree.prototype.updateNode = function (index, sum, val) {
|
|
115
|
+
var root = this.root || null;
|
|
83
116
|
if (!root) {
|
|
84
117
|
return;
|
|
85
118
|
}
|
|
86
|
-
|
|
119
|
+
var dfs = function (cur, index, sum, val) {
|
|
87
120
|
if (cur.start === cur.end && cur.start === index) {
|
|
88
121
|
cur.sum = sum;
|
|
89
122
|
// cur.val = val;
|
|
90
123
|
return;
|
|
91
124
|
}
|
|
92
|
-
|
|
125
|
+
var mid = cur.start + Math.floor((cur.end - cur.start) / 2);
|
|
93
126
|
if (index <= mid) {
|
|
94
127
|
if (cur.left) {
|
|
95
128
|
dfs(cur.left, index, sum, val);
|
|
@@ -105,17 +138,17 @@ class SegmentTree {
|
|
|
105
138
|
}
|
|
106
139
|
};
|
|
107
140
|
dfs(root, index, sum);
|
|
108
|
-
}
|
|
109
|
-
querySumByRange(indexA, indexB) {
|
|
110
|
-
|
|
141
|
+
};
|
|
142
|
+
SegmentTree.prototype.querySumByRange = function (indexA, indexB) {
|
|
143
|
+
var root = this.root || null;
|
|
111
144
|
if (!root) {
|
|
112
145
|
return 0;
|
|
113
146
|
}
|
|
114
|
-
|
|
147
|
+
var dfs = function (cur, i, j) {
|
|
115
148
|
if (cur.start === i && cur.end === j) {
|
|
116
149
|
return cur.sum;
|
|
117
150
|
}
|
|
118
|
-
|
|
151
|
+
var mid = cur.start + Math.floor((cur.end - cur.start) / 2);
|
|
119
152
|
if (j <= mid) {
|
|
120
153
|
// TODO after no-non-null-assertion not ensure the logic
|
|
121
154
|
if (cur.left) {
|
|
@@ -146,6 +179,7 @@ class SegmentTree {
|
|
|
146
179
|
}
|
|
147
180
|
};
|
|
148
181
|
return dfs(root, indexA, indexB);
|
|
149
|
-
}
|
|
150
|
-
|
|
182
|
+
};
|
|
183
|
+
return SegmentTree;
|
|
184
|
+
}());
|
|
151
185
|
exports.SegmentTree = SegmentTree;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SplayTree = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
var SplayTree = /** @class */ (function () {
|
|
5
|
+
function SplayTree() {
|
|
6
|
+
}
|
|
7
|
+
return SplayTree;
|
|
8
|
+
}());
|
|
6
9
|
exports.SplayTree = SplayTree;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
1
5
|
import { BST, BSTNode } from './bst';
|
|
2
|
-
import { BinaryTreeNodeId } from '
|
|
3
|
-
export type TreeMultiSetDeletedResult<T> = {
|
|
4
|
-
deleted: BSTNode<T> | null;
|
|
5
|
-
needBalanced: BSTNode<T> | null;
|
|
6
|
-
};
|
|
6
|
+
import type { BinaryTreeNodeId, TreeMultiSetDeletedResult } from '../types';
|
|
7
7
|
export declare class TreeMultiSet<T> extends BST<T> {
|
|
8
8
|
createNode(id: BinaryTreeNodeId, val: T, count?: number): BSTNode<T>;
|
|
9
9
|
put(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
|
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
18
|
exports.TreeMultiSet = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
19
|
+
/**
|
|
20
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
21
|
+
* @license MIT
|
|
22
|
+
*/
|
|
23
|
+
var bst_1 = require("./bst");
|
|
24
|
+
var TreeMultiSet = /** @class */ (function (_super) {
|
|
25
|
+
__extends(TreeMultiSet, _super);
|
|
26
|
+
function TreeMultiSet() {
|
|
27
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
11
28
|
}
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
|
|
29
|
+
TreeMultiSet.prototype.createNode = function (id, val, count) {
|
|
30
|
+
return new bst_1.BSTNode(id, val, count);
|
|
31
|
+
};
|
|
32
|
+
TreeMultiSet.prototype.put = function (id, val, count) {
|
|
33
|
+
return _super.prototype.put.call(this, id, val, count);
|
|
34
|
+
};
|
|
35
|
+
TreeMultiSet.prototype.remove = function (id, isUpdateAllLeftSum) {
|
|
36
|
+
return _super.prototype.remove.call(this, id, isUpdateAllLeftSum);
|
|
37
|
+
};
|
|
38
|
+
return TreeMultiSet;
|
|
39
|
+
}(bst_1.BST));
|
|
16
40
|
exports.TreeMultiSet = TreeMultiSet;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TwoThreeTree = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
var TwoThreeTree = /** @class */ (function () {
|
|
5
|
+
function TwoThreeTree() {
|
|
6
|
+
}
|
|
7
|
+
return TwoThreeTree;
|
|
8
|
+
}());
|
|
6
9
|
exports.TwoThreeTree = TwoThreeTree;
|
|
@@ -1,95 +1,197 @@
|
|
|
1
|
-
|
|
2
|
-
export type DijkstraResult<V> = {
|
|
3
|
-
distMap: Map<V, number>;
|
|
4
|
-
preMap: Map<V, V | null>;
|
|
5
|
-
seen: Set<V>;
|
|
6
|
-
paths: V[][];
|
|
7
|
-
minDist: number;
|
|
8
|
-
minPath: V[];
|
|
9
|
-
} | null;
|
|
10
|
-
export interface I_Graph<V, E> {
|
|
11
|
-
containsVertex(vertexOrId: V | VertexId): boolean;
|
|
12
|
-
getVertex(vertexOrId: VertexId | V): V | null;
|
|
13
|
-
getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
14
|
-
vertexSet(): Map<VertexId, V>;
|
|
15
|
-
addVertex(v: V): boolean;
|
|
16
|
-
removeVertex(vertexOrId: V | VertexId): boolean;
|
|
17
|
-
removeAllVertices(vertices: V[] | VertexId[]): boolean;
|
|
18
|
-
degreeOf(vertexOrId: V | VertexId): number;
|
|
19
|
-
edgesOf(vertexOrId: V | VertexId): E[];
|
|
20
|
-
containsEdge(src: V | VertexId, dest: V | VertexId): boolean;
|
|
21
|
-
getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
22
|
-
edgeSet(): E[];
|
|
23
|
-
addEdge(edge: E): boolean;
|
|
24
|
-
removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
25
|
-
removeEdge(edge: E): E | null;
|
|
26
|
-
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
|
|
27
|
-
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
|
|
28
|
-
getNeighbors(vertexOrId: V | VertexId): V[];
|
|
29
|
-
}
|
|
1
|
+
import type { DijkstraResult, IGraph, VertexId } from '../types';
|
|
30
2
|
export declare class AbstractVertex {
|
|
31
|
-
|
|
3
|
+
constructor(id: VertexId);
|
|
4
|
+
protected _id: VertexId;
|
|
32
5
|
get id(): VertexId;
|
|
33
6
|
set id(v: VertexId);
|
|
34
|
-
constructor(id: VertexId);
|
|
35
7
|
}
|
|
36
8
|
export declare abstract class AbstractEdge {
|
|
9
|
+
static DEFAULT_EDGE_WEIGHT: number;
|
|
10
|
+
protected constructor(weight?: number);
|
|
37
11
|
private _weight;
|
|
38
12
|
get weight(): number;
|
|
39
13
|
set weight(v: number);
|
|
40
14
|
private _hashCode;
|
|
41
15
|
get hashCode(): string;
|
|
42
16
|
set hashCode(v: string);
|
|
43
|
-
protected constructor(weight?: number);
|
|
44
|
-
static DEFAULT_EDGE_WEIGHT: number;
|
|
45
17
|
}
|
|
46
|
-
export declare abstract class AbstractGraph<V extends AbstractVertex, E extends AbstractEdge> implements
|
|
18
|
+
export declare abstract class AbstractGraph<V extends AbstractVertex, E extends AbstractEdge> implements IGraph<V, E> {
|
|
47
19
|
protected _vertices: Map<VertexId, V>;
|
|
48
20
|
abstract removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
49
21
|
abstract removeEdge(edge: E): E | null;
|
|
22
|
+
/**
|
|
23
|
+
* The function `getVertex` returns the vertex object associated with a given vertex ID or vertex object, or null if it
|
|
24
|
+
* does not exist.
|
|
25
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
26
|
+
* @returns The function `getVertex` returns the vertex object (`V`) corresponding to the given `vertexOrId` parameter.
|
|
27
|
+
* If the vertex is found in the `_vertices` map, it is returned. Otherwise, `null` is returned.
|
|
28
|
+
*/
|
|
50
29
|
getVertex(vertexOrId: VertexId | V): V | null;
|
|
30
|
+
/**
|
|
31
|
+
* The function `getVertexId` returns the id of a vertex, whether it is passed as an instance of `AbstractVertex` or as
|
|
32
|
+
* a `VertexId`.
|
|
33
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
34
|
+
* (`VertexId`).
|
|
35
|
+
* @returns the id of the vertex.
|
|
36
|
+
*/
|
|
51
37
|
getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
38
|
+
/**
|
|
39
|
+
* The function checks if a vertex exists in a graph.
|
|
40
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
|
|
41
|
+
* (`VertexId`).
|
|
42
|
+
* @returns The method `containsVertex` returns a boolean value.
|
|
43
|
+
*/
|
|
52
44
|
containsVertex(vertexOrId: V | VertexId): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The function `vertexSet()` returns a map of vertices.
|
|
47
|
+
* @returns The method `vertexSet()` returns a map of vertex IDs to vertex objects.
|
|
48
|
+
*/
|
|
53
49
|
vertexSet(): Map<VertexId, V>;
|
|
54
50
|
abstract getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
|
|
51
|
+
/**
|
|
52
|
+
* The addVertex function adds a new vertex to a graph if it does not already exist.
|
|
53
|
+
* @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
|
|
54
|
+
* @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
|
|
55
|
+
* false. Otherwise, it will add the newVertex to the graph and return true.
|
|
56
|
+
*/
|
|
55
57
|
addVertex(newVertex: V): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
60
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
61
|
+
* (`VertexId`).
|
|
62
|
+
* @returns The method `removeVertex` returns a boolean value.
|
|
63
|
+
*/
|
|
56
64
|
removeVertex(vertexOrId: V | VertexId): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
|
|
67
|
+
* @param {V[] | VertexId[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
|
|
68
|
+
* of vertex IDs (`VertexId[]`).
|
|
69
|
+
* @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
|
|
70
|
+
* were removed.
|
|
71
|
+
*/
|
|
57
72
|
removeAllVertices(vertices: V[] | VertexId[]): boolean;
|
|
58
73
|
abstract degreeOf(vertexOrId: V | VertexId): number;
|
|
59
74
|
abstract edgeSet(): E[];
|
|
60
75
|
abstract edgesOf(vertexOrId: V | VertexId): E[];
|
|
76
|
+
/**
|
|
77
|
+
* The function checks if there is an edge between two vertices in a graph.
|
|
78
|
+
* @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the identifier of
|
|
79
|
+
* a vertex in a graph, while V represents the type of the vertex itself.
|
|
80
|
+
* @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in an edge. It can be either a `VertexId`
|
|
81
|
+
* or a `V` type.
|
|
82
|
+
* @returns The function `containsEdge` returns a boolean value. It returns `true` if there is an edge between the
|
|
83
|
+
* vertices `v1` and `v2`, and `false` otherwise.
|
|
84
|
+
*/
|
|
61
85
|
containsEdge(v1: VertexId | V, v2: VertexId | V): boolean;
|
|
62
86
|
abstract addEdge(edge: E): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* The function sets the weight of an edge between two vertices in a graph.
|
|
89
|
+
* @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
|
|
90
|
+
* the source vertex of the edge.
|
|
91
|
+
* @param {VertexId | V} destOrId - The `destOrId` parameter represents the destination vertex of the edge. It can be
|
|
92
|
+
* either a `VertexId` or a vertex object `V`.
|
|
93
|
+
* @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrId)
|
|
94
|
+
* and the destination vertex (destOrId).
|
|
95
|
+
* @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
|
|
96
|
+
* the weight of the edge and return true. If the edge does not exist, the function will return false.
|
|
97
|
+
*/
|
|
63
98
|
setEdgeWeight(srcOrId: VertexId | V, destOrId: VertexId | V, weight: number): boolean;
|
|
64
99
|
abstract getNeighbors(vertexOrId: V | VertexId): V[];
|
|
100
|
+
/**
|
|
101
|
+
* The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
|
|
102
|
+
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
|
|
103
|
+
* It is the starting vertex for finding paths.
|
|
104
|
+
* @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex that we
|
|
105
|
+
* want to find paths to from the starting vertex `v1`.
|
|
106
|
+
* @returns an array of arrays of vertices (V[][]). Each inner array represents a path between the given vertices (v1
|
|
107
|
+
* and v2).
|
|
108
|
+
*/
|
|
65
109
|
getAllPathsBetween(v1: V | VertexId, v2: V | VertexId): V[][];
|
|
110
|
+
/**
|
|
111
|
+
* The function calculates the sum of weights along a given path.
|
|
112
|
+
* @param {V[]} path - An array of vertices (V) representing a path in a graph.
|
|
113
|
+
* @returns The function `getPathSumWeight` returns the sum of the weights of the edges in the given path.
|
|
114
|
+
*/
|
|
66
115
|
getPathSumWeight(path: V[]): number;
|
|
116
|
+
/**
|
|
117
|
+
* The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
|
|
118
|
+
* weights or using a breadth-first search algorithm.
|
|
119
|
+
* @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or vertex ID of the graph.
|
|
120
|
+
* @param {V | VertexId} v2 - The parameter `v2` represents the second vertex in the graph. It can be either a vertex
|
|
121
|
+
* object or a vertex ID.
|
|
122
|
+
* @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
|
|
123
|
+
* If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
|
|
124
|
+
* the edges. If isWeight is set to false or not provided, the function will calculate the
|
|
125
|
+
* @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertices (`v1`
|
|
126
|
+
* and `v2`) in a graph. If the `isWeight` parameter is `true`, it calculates the minimum weight between the vertices.
|
|
127
|
+
* If `isWeight` is `false` or not provided, it calculates the minimum number of edges between the vertices. If the
|
|
128
|
+
* vertices are not
|
|
129
|
+
*/
|
|
67
130
|
getMinCostBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): number | null;
|
|
131
|
+
/**
|
|
132
|
+
* The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
|
|
133
|
+
* using a breadth-first search algorithm.
|
|
134
|
+
* @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or its ID.
|
|
135
|
+
* @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex that we
|
|
136
|
+
* want to find the minimum path to from the source vertex `v1`.
|
|
137
|
+
* @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
|
|
138
|
+
* minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
|
|
139
|
+
* to false, the function will use breadth-first search (BFS) to find the minimum path. If
|
|
140
|
+
* @returns The function `getMinPathBetween` returns an array of vertices (`V[]`) representing the minimum path between
|
|
141
|
+
* two vertices (`v1` and `v2`). If no path is found, it returns `null`.
|
|
142
|
+
*/
|
|
68
143
|
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
|
|
69
144
|
/**
|
|
70
145
|
* Dijkstra algorithm time: O(VE) space: O(V + E)
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* @param
|
|
74
|
-
*
|
|
146
|
+
* The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
|
|
147
|
+
* a graph without using a heap data structure.
|
|
148
|
+
* @param {V | VertexId} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
|
|
149
|
+
* vertex object or a vertex ID.
|
|
150
|
+
* @param {V | VertexId | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
|
|
151
|
+
* parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
|
|
152
|
+
* identifier. If no destination is provided, the value is set to `null`.
|
|
153
|
+
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
154
|
+
* distance from the source vertex to the destination vertex should be calculated and returned in the result. If
|
|
155
|
+
* `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
|
|
156
|
+
* @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
|
|
157
|
+
* paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
|
|
158
|
+
* shortest paths from the source vertex to all other vertices in the graph. If `genPaths
|
|
159
|
+
* @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<V>`.
|
|
75
160
|
*/
|
|
76
161
|
dijkstraWithoutHeap(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
|
|
77
162
|
/**
|
|
78
163
|
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* @param
|
|
82
|
-
*
|
|
164
|
+
* The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
|
|
165
|
+
* optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
|
|
166
|
+
* @param {V | VertexId} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
|
|
167
|
+
* start. It can be either a vertex object or a vertex ID.
|
|
168
|
+
* @param {V | VertexId | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
|
|
169
|
+
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
|
|
170
|
+
* will calculate the shortest paths to all other vertices from the source vertex.
|
|
171
|
+
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
172
|
+
* distance from the source vertex to the destination vertex should be calculated and returned in the result. If
|
|
173
|
+
* `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
|
|
174
|
+
* @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
|
|
175
|
+
* paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
|
|
176
|
+
* shortest paths from the source vertex to all other vertices in the graph. If `genPaths
|
|
177
|
+
* @returns The function `dijkstra` returns an object of type `DijkstraResult<V>`.
|
|
83
178
|
*/
|
|
84
179
|
dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
|
|
85
180
|
abstract getEndsOfEdge(edge: E): [V, V] | null;
|
|
86
181
|
/**
|
|
87
182
|
* BellmanFord time:O(VE) space:O(V)
|
|
88
183
|
* one to rest pairs
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* @param
|
|
92
|
-
*
|
|
184
|
+
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
185
|
+
* all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
|
|
186
|
+
* @param {V | VertexId} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
|
|
187
|
+
* start calculating the shortest paths. It can be either a vertex object or a vertex ID.
|
|
188
|
+
* @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
|
|
189
|
+
* @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
|
|
190
|
+
* calculate the minimum distance from the source vertex to all other vertices in the graph. If `getMin` is set to
|
|
191
|
+
* `true`, the algorithm will find the minimum distance and update the `min` variable with the minimum
|
|
192
|
+
* @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertices from the source
|
|
193
|
+
* vertex.
|
|
194
|
+
* @returns The function `bellmanFord` returns an object with the following properties:
|
|
93
195
|
*/
|
|
94
196
|
bellmanFord(src: V | VertexId, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean): {
|
|
95
197
|
hasNegativeCycle: boolean | undefined;
|
|
@@ -102,6 +204,12 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
102
204
|
/**
|
|
103
205
|
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
104
206
|
* all pairs
|
|
207
|
+
* The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
|
|
208
|
+
* graph.
|
|
209
|
+
* @returns The function `floyd()` returns an object with two properties: `costs` and `predecessor`. The `costs`
|
|
210
|
+
* property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
|
|
211
|
+
* `predecessor` property is a 2D array of vertices (or `null`) representing the predecessor vertices in the shortest
|
|
212
|
+
* path between vertices in the
|
|
105
213
|
*/
|
|
106
214
|
floyd(): {
|
|
107
215
|
costs: number[][];
|
|
@@ -114,6 +222,20 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
114
222
|
* Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
|
|
115
223
|
* Tarjan solve the bi-connected components of undirected graphs;
|
|
116
224
|
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
225
|
+
* The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
|
|
226
|
+
* strongly connected components (SCCs), and cycles in a graph.
|
|
227
|
+
* @param {boolean} [needArticulationPoints] - A boolean value indicating whether or not to calculate and return the
|
|
228
|
+
* articulation points in the graph. Articulation points are the vertices in a graph whose removal would increase the
|
|
229
|
+
* number of connected components in the graph.
|
|
230
|
+
* @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
|
|
231
|
+
* (edges whose removal would increase the number of connected components in the graph).
|
|
232
|
+
* @param {boolean} [needSCCs] - A boolean value indicating whether the Strongly Connected Components (SCCs) of the
|
|
233
|
+
* graph are needed. If set to true, the function will calculate and return the SCCs of the graph. If set to false, the
|
|
234
|
+
* SCCs will not be calculated or returned.
|
|
235
|
+
* @param {boolean} [needCycles] - A boolean flag indicating whether the algorithm should find cycles in the graph. If
|
|
236
|
+
* set to true, the algorithm will return a map of cycles, where the keys are the low values of the SCCs and the values
|
|
237
|
+
* are arrays of vertices that form cycles within the SCCs.
|
|
238
|
+
* @returns The function `tarjan` returns an object with the following properties:
|
|
117
239
|
*/
|
|
118
240
|
tarjan(needArticulationPoints?: boolean, needBridges?: boolean, needSCCs?: boolean, needCycles?: boolean): {
|
|
119
241
|
dfnMap: Map<V, number>;
|