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,71 +1,156 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
})();
|
|
17
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
18
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
+
if (!m) return o;
|
|
20
|
+
var i = m.call(o), r, ar = [], e;
|
|
21
|
+
try {
|
|
22
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
9
23
|
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this._dest = dest;
|
|
17
|
-
}
|
|
18
|
-
get src() {
|
|
19
|
-
return this._src;
|
|
24
|
+
catch (error) { e = { error: error }; }
|
|
25
|
+
finally {
|
|
26
|
+
try {
|
|
27
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
+
}
|
|
29
|
+
finally { if (e) throw e.error; }
|
|
20
30
|
}
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
+
if (ar || !(i in from)) {
|
|
36
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
+
ar[i] = from[i];
|
|
38
|
+
}
|
|
23
39
|
}
|
|
24
|
-
|
|
25
|
-
|
|
40
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
+
};
|
|
42
|
+
var __values = (this && this.__values) || function(o) {
|
|
43
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
44
|
+
if (m) return m.call(o);
|
|
45
|
+
if (o && typeof o.length === "number") return {
|
|
46
|
+
next: function () {
|
|
47
|
+
if (o && i >= o.length) o = void 0;
|
|
48
|
+
return { value: o && o[i++], done: !o };
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.DirectedGraph = exports.DirectedEdge = exports.DirectedVertex = void 0;
|
|
55
|
+
/**
|
|
56
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
57
|
+
* @license MIT
|
|
58
|
+
*/
|
|
59
|
+
var utils_1 = require("../../utils");
|
|
60
|
+
var abstract_graph_1 = require("./abstract-graph");
|
|
61
|
+
var DirectedVertex = /** @class */ (function (_super) {
|
|
62
|
+
__extends(DirectedVertex, _super);
|
|
63
|
+
function DirectedVertex(id) {
|
|
64
|
+
return _super.call(this, id) || this;
|
|
26
65
|
}
|
|
27
|
-
|
|
28
|
-
|
|
66
|
+
return DirectedVertex;
|
|
67
|
+
}(abstract_graph_1.AbstractVertex));
|
|
68
|
+
exports.DirectedVertex = DirectedVertex;
|
|
69
|
+
var DirectedEdge = /** @class */ (function (_super) {
|
|
70
|
+
__extends(DirectedEdge, _super);
|
|
71
|
+
function DirectedEdge(src, dest, weight) {
|
|
72
|
+
var _this = _super.call(this, weight) || this;
|
|
73
|
+
_this._src = src;
|
|
74
|
+
_this._dest = dest;
|
|
75
|
+
return _this;
|
|
29
76
|
}
|
|
30
|
-
|
|
77
|
+
Object.defineProperty(DirectedEdge.prototype, "src", {
|
|
78
|
+
get: function () {
|
|
79
|
+
return this._src;
|
|
80
|
+
},
|
|
81
|
+
set: function (v) {
|
|
82
|
+
this._src = v;
|
|
83
|
+
},
|
|
84
|
+
enumerable: false,
|
|
85
|
+
configurable: true
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(DirectedEdge.prototype, "dest", {
|
|
88
|
+
get: function () {
|
|
89
|
+
return this._dest;
|
|
90
|
+
},
|
|
91
|
+
set: function (v) {
|
|
92
|
+
this._dest = v;
|
|
93
|
+
},
|
|
94
|
+
enumerable: false,
|
|
95
|
+
configurable: true
|
|
96
|
+
});
|
|
97
|
+
return DirectedEdge;
|
|
98
|
+
}(abstract_graph_1.AbstractEdge));
|
|
31
99
|
exports.DirectedEdge = DirectedEdge;
|
|
32
100
|
// Strongly connected, One direction connected, Weakly connected
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
101
|
+
var DirectedGraph = /** @class */ (function (_super) {
|
|
102
|
+
__extends(DirectedGraph, _super);
|
|
103
|
+
function DirectedGraph() {
|
|
104
|
+
var _this = _super.call(this) || this;
|
|
105
|
+
_this._outEdgeMap = new Map();
|
|
106
|
+
_this._inEdgeMap = new Map();
|
|
107
|
+
return _this;
|
|
38
108
|
}
|
|
39
|
-
|
|
40
|
-
|
|
109
|
+
/**
|
|
110
|
+
* The function `getEdge` returns the first edge between two vertices, given their source and destination.
|
|
111
|
+
* @param {V | null | VertexId} srcOrId - The `srcOrId` parameter can be either a vertex object (`V`), a vertex ID
|
|
112
|
+
* (`VertexId`), or `null`. It represents the source vertex of the edge.
|
|
113
|
+
* @param {V | null | VertexId} destOrId - The `destOrId` parameter is either a vertex object (`V`), a vertex ID
|
|
114
|
+
* (`VertexId`), or `null`. It represents the destination vertex of the edge.
|
|
115
|
+
* @returns an edge (E) or null.
|
|
116
|
+
*/
|
|
117
|
+
DirectedGraph.prototype.getEdge = function (srcOrId, destOrId) {
|
|
118
|
+
var edges = [];
|
|
41
119
|
if (srcOrId !== null && destOrId !== null) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (src &&
|
|
45
|
-
|
|
120
|
+
var src = this.getVertex(srcOrId);
|
|
121
|
+
var dest_1 = this.getVertex(destOrId);
|
|
122
|
+
if (src && dest_1) {
|
|
123
|
+
var srcOutEdges = this._outEdgeMap.get(src);
|
|
46
124
|
if (srcOutEdges) {
|
|
47
|
-
edges = srcOutEdges.filter(edge
|
|
125
|
+
edges = srcOutEdges.filter(function (edge) { return edge.dest === dest_1.id; });
|
|
48
126
|
}
|
|
49
127
|
}
|
|
50
128
|
}
|
|
51
129
|
return edges[0] || null;
|
|
52
|
-
}
|
|
53
|
-
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* The `addEdge` function adds an edge to a graph if the source and destination vertices exist.
|
|
133
|
+
* @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in the graph. It contains
|
|
134
|
+
* information about the source vertex (`src`) and the destination vertex (`dest`) of the edge.
|
|
135
|
+
* @returns The `addEdge` function returns a boolean value. It returns `true` if the edge was successfully added to the
|
|
136
|
+
* graph, and `false` if either the source or destination vertices of the edge are not present in the graph.
|
|
137
|
+
*/
|
|
138
|
+
DirectedGraph.prototype.addEdge = function (edge) {
|
|
54
139
|
if (!(this.containsVertex(edge.src) && this.containsVertex(edge.dest))) {
|
|
55
140
|
return false;
|
|
56
141
|
}
|
|
57
|
-
|
|
58
|
-
|
|
142
|
+
var srcVertex = this.getVertex(edge.src);
|
|
143
|
+
var destVertex = this.getVertex(edge.dest);
|
|
59
144
|
// TODO after no-non-null-assertion not ensure the logic
|
|
60
145
|
if (srcVertex && destVertex) {
|
|
61
|
-
|
|
146
|
+
var srcOutEdges = this._outEdgeMap.get(srcVertex);
|
|
62
147
|
if (srcOutEdges) {
|
|
63
148
|
srcOutEdges.push(edge);
|
|
64
149
|
}
|
|
65
150
|
else {
|
|
66
151
|
this._outEdgeMap.set(srcVertex, [edge]);
|
|
67
152
|
}
|
|
68
|
-
|
|
153
|
+
var destInEdges = this._inEdgeMap.get(destVertex);
|
|
69
154
|
if (destInEdges) {
|
|
70
155
|
destInEdges.push(edge);
|
|
71
156
|
}
|
|
@@ -77,95 +162,194 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
77
162
|
else {
|
|
78
163
|
return false;
|
|
79
164
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* The function removes an edge between two vertices in a directed graph and returns the removed edge.
|
|
168
|
+
* @param {V | VertexId} srcOrId - The source vertex or its ID.
|
|
169
|
+
* @param {V | VertexId} destOrId - The `destOrId` parameter in the `removeEdgeBetween` function represents the
|
|
170
|
+
* destination vertex of the edge that needs to be removed. It can be either a vertex object (`V`) or a vertex ID
|
|
171
|
+
* (`VertexId`).
|
|
172
|
+
* @returns The function `removeEdgeBetween` returns the removed edge (`E`) if the edge between the source and
|
|
173
|
+
* destination vertices is successfully removed. If either the source or destination vertex is not found, or if the
|
|
174
|
+
* edge does not exist, it returns `null`.
|
|
175
|
+
*/
|
|
176
|
+
DirectedGraph.prototype.removeEdgeBetween = function (srcOrId, destOrId) {
|
|
177
|
+
var src = this.getVertex(srcOrId);
|
|
178
|
+
var dest = this.getVertex(destOrId);
|
|
179
|
+
var removed = null;
|
|
85
180
|
if (!src || !dest) {
|
|
86
181
|
return null;
|
|
87
182
|
}
|
|
88
|
-
|
|
183
|
+
var srcOutEdges = this._outEdgeMap.get(src);
|
|
89
184
|
if (srcOutEdges) {
|
|
90
|
-
|
|
185
|
+
/**
|
|
186
|
+
* The removeEdge function removes an edge from a graph and returns the removed edge, or null if the edge was not
|
|
187
|
+
* found.
|
|
188
|
+
* @param {E} edge - The `edge` parameter represents the edge that you want to remove from the graph. It should be an
|
|
189
|
+
* object that has `src` and `dest` properties, which represent the source and destination vertices of the edge,
|
|
190
|
+
* respectively.
|
|
191
|
+
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
|
|
192
|
+
*/
|
|
193
|
+
(0, utils_1.arrayRemove)(srcOutEdges, function (edge) { return edge.dest === dest.id; });
|
|
91
194
|
}
|
|
92
|
-
|
|
195
|
+
var destInEdges = this._inEdgeMap.get(dest);
|
|
93
196
|
if (destInEdges) {
|
|
94
|
-
removed = (0, utils_1.arrayRemove)(destInEdges, edge
|
|
197
|
+
removed = (0, utils_1.arrayRemove)(destInEdges, function (edge) { return edge.src === src.id; })[0] || null;
|
|
95
198
|
}
|
|
96
199
|
return removed;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* The removeEdge function removes an edge from a graph and returns the removed edge, or null if the edge was not
|
|
203
|
+
* found.
|
|
204
|
+
* @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
205
|
+
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
206
|
+
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
|
|
207
|
+
*/
|
|
208
|
+
DirectedGraph.prototype.removeEdge = function (edge) {
|
|
209
|
+
var removed = null;
|
|
210
|
+
var src = this.getVertex(edge.src);
|
|
211
|
+
var dest = this.getVertex(edge.dest);
|
|
102
212
|
if (src && dest) {
|
|
103
|
-
|
|
213
|
+
var srcOutEdges = this._outEdgeMap.get(src);
|
|
104
214
|
if (srcOutEdges && srcOutEdges.length > 0) {
|
|
105
|
-
(0, utils_1.arrayRemove)(srcOutEdges, edge
|
|
215
|
+
(0, utils_1.arrayRemove)(srcOutEdges, function (edge) { return edge.src === src.id; });
|
|
106
216
|
}
|
|
107
|
-
|
|
217
|
+
var destInEdges = this._inEdgeMap.get(dest);
|
|
108
218
|
if (destInEdges && destInEdges.length > 0) {
|
|
109
|
-
removed = (0, utils_1.arrayRemove)(destInEdges, edge
|
|
219
|
+
removed = (0, utils_1.arrayRemove)(destInEdges, function (edge) { return edge.dest === dest.id; })[0];
|
|
110
220
|
}
|
|
111
221
|
}
|
|
112
222
|
return removed;
|
|
113
|
-
}
|
|
114
|
-
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* The function removeAllEdges removes all edges between two vertices.
|
|
226
|
+
* @param {VertexId | V} src - The `src` parameter represents the source vertex from which the edges will be removed.
|
|
227
|
+
* It can be either a `VertexId` or a `V` type, which represents the identifier or object of the vertex.
|
|
228
|
+
* @param {VertexId | V} dest - The `dest` parameter represents the destination vertex of an edge. It can be either a
|
|
229
|
+
* `VertexId` or a vertex object `V`.
|
|
230
|
+
* @returns An empty array is being returned.
|
|
231
|
+
*/
|
|
232
|
+
DirectedGraph.prototype.removeAllEdges = function (src, dest) {
|
|
115
233
|
return [];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
|
|
237
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
238
|
+
* (`VertexId`).
|
|
239
|
+
* @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
|
|
240
|
+
*/
|
|
241
|
+
DirectedGraph.prototype.incomingEdgesOf = function (vertexOrId) {
|
|
242
|
+
var target = this.getVertex(vertexOrId);
|
|
119
243
|
if (target) {
|
|
120
244
|
return this._inEdgeMap.get(target) || [];
|
|
121
245
|
}
|
|
122
246
|
return [];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
|
|
250
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
|
|
251
|
+
* (`VertexId`).
|
|
252
|
+
* @returns The method `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
|
|
253
|
+
*/
|
|
254
|
+
DirectedGraph.prototype.outgoingEdgesOf = function (vertexOrId) {
|
|
255
|
+
var target = this.getVertex(vertexOrId);
|
|
126
256
|
if (target) {
|
|
127
257
|
return this._outEdgeMap.get(target) || [];
|
|
128
258
|
}
|
|
129
259
|
return [];
|
|
130
|
-
}
|
|
131
|
-
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
|
|
263
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
264
|
+
* @returns the sum of the out-degree and in-degree of the specified vertex or vertex ID.
|
|
265
|
+
*/
|
|
266
|
+
DirectedGraph.prototype.degreeOf = function (vertexOrId) {
|
|
132
267
|
return this.outDegreeOf(vertexOrId) + this.inDegreeOf(vertexOrId);
|
|
133
|
-
}
|
|
134
|
-
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
|
|
271
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
272
|
+
* @returns The number of incoming edges of the specified vertex or vertex ID.
|
|
273
|
+
*/
|
|
274
|
+
DirectedGraph.prototype.inDegreeOf = function (vertexOrId) {
|
|
135
275
|
return this.incomingEdgesOf(vertexOrId).length;
|
|
136
|
-
}
|
|
137
|
-
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
|
|
279
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
280
|
+
* @returns The number of outgoing edges from the specified vertex or vertex ID.
|
|
281
|
+
*/
|
|
282
|
+
DirectedGraph.prototype.outDegreeOf = function (vertexOrId) {
|
|
138
283
|
return this.outgoingEdgesOf(vertexOrId).length;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
|
|
287
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
288
|
+
* @returns The function `edgesOf` returns an array of edges.
|
|
289
|
+
*/
|
|
290
|
+
DirectedGraph.prototype.edgesOf = function (vertexOrId) {
|
|
291
|
+
return __spreadArray(__spreadArray([], __read(this.outgoingEdgesOf(vertexOrId)), false), __read(this.incomingEdgesOf(vertexOrId)), false);
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
|
|
295
|
+
* @param {E} e - E - an edge object
|
|
296
|
+
* @returns the source vertex of the given edge, or null if the edge does not exist.
|
|
297
|
+
*/
|
|
298
|
+
DirectedGraph.prototype.getEdgeSrc = function (e) {
|
|
144
299
|
return this.getVertex(e.src);
|
|
145
|
-
}
|
|
146
|
-
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* The function "getEdgeDest" returns the vertex associated with the destination of an edge.
|
|
303
|
+
* @param {E} e - The parameter `e` is of type `E`, which represents an edge in a graph.
|
|
304
|
+
* @returns either a vertex object (of type V) or null.
|
|
305
|
+
*/
|
|
306
|
+
DirectedGraph.prototype.getEdgeDest = function (e) {
|
|
147
307
|
return this.getVertex(e.dest);
|
|
148
|
-
}
|
|
149
|
-
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
|
|
311
|
+
* @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
312
|
+
* find the destinations. It can be either a `V` object, a `VertexId` (which is a unique identifier for a vertex), or
|
|
313
|
+
* `null` if we want to find destinations from all vertices.
|
|
314
|
+
* @returns an array of vertices (V[]).
|
|
315
|
+
*/
|
|
316
|
+
DirectedGraph.prototype.getDestinations = function (vertex) {
|
|
317
|
+
var e_1, _a;
|
|
150
318
|
if (vertex === null) {
|
|
151
319
|
return [];
|
|
152
320
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
321
|
+
var destinations = [];
|
|
322
|
+
var outgoingEdges = this.outgoingEdgesOf(vertex);
|
|
323
|
+
try {
|
|
324
|
+
for (var outgoingEdges_1 = __values(outgoingEdges), outgoingEdges_1_1 = outgoingEdges_1.next(); !outgoingEdges_1_1.done; outgoingEdges_1_1 = outgoingEdges_1.next()) {
|
|
325
|
+
var outEdge = outgoingEdges_1_1.value;
|
|
326
|
+
var child = this.getEdgeDest(outEdge);
|
|
327
|
+
if (child) {
|
|
328
|
+
destinations.push(child);
|
|
329
|
+
}
|
|
159
330
|
}
|
|
160
331
|
}
|
|
332
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
333
|
+
finally {
|
|
334
|
+
try {
|
|
335
|
+
if (outgoingEdges_1_1 && !outgoingEdges_1_1.done && (_a = outgoingEdges_1.return)) _a.call(outgoingEdges_1);
|
|
336
|
+
}
|
|
337
|
+
finally { if (e_1) throw e_1.error; }
|
|
338
|
+
}
|
|
161
339
|
return destinations;
|
|
162
|
-
}
|
|
340
|
+
};
|
|
163
341
|
/**--- start find cycles --- */
|
|
164
342
|
/**
|
|
165
343
|
* when stored with adjacency list time: O(V+E)
|
|
166
344
|
* when stored with adjacency matrix time: O(V^2)
|
|
345
|
+
* The `topologicalSort` function performs a topological sort on a directed graph and returns the sorted vertices in
|
|
346
|
+
* reverse order, or null if the graph contains a cycle.
|
|
347
|
+
* @returns The function `topologicalSort()` returns an array of vertices in topological order if there is no cycle in
|
|
348
|
+
* the graph. If there is a cycle in the graph, it returns `null`.
|
|
167
349
|
*/
|
|
168
|
-
topologicalSort() {
|
|
350
|
+
DirectedGraph.prototype.topologicalSort = function () {
|
|
351
|
+
var e_2, _a, e_3, _b;
|
|
352
|
+
var _this = this;
|
|
169
353
|
// vector<vector<int>> g;
|
|
170
354
|
// vector<int> color;
|
|
171
355
|
// int last;
|
|
@@ -197,72 +381,132 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
197
381
|
// }
|
|
198
382
|
// When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
|
|
199
383
|
// When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
384
|
+
var statusMap = new Map();
|
|
385
|
+
try {
|
|
386
|
+
for (var _c = __values(this._vertices), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
387
|
+
var entry = _d.value;
|
|
388
|
+
statusMap.set(entry[1], 0);
|
|
389
|
+
}
|
|
203
390
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
391
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
392
|
+
finally {
|
|
393
|
+
try {
|
|
394
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
395
|
+
}
|
|
396
|
+
finally { if (e_2) throw e_2.error; }
|
|
397
|
+
}
|
|
398
|
+
var sorted = [];
|
|
399
|
+
var hasCycle = false;
|
|
400
|
+
var dfs = function (cur) {
|
|
401
|
+
var e_4, _a;
|
|
207
402
|
statusMap.set(cur, 1);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
403
|
+
var children = _this.getDestinations(cur);
|
|
404
|
+
try {
|
|
405
|
+
for (var children_1 = __values(children), children_1_1 = children_1.next(); !children_1_1.done; children_1_1 = children_1.next()) {
|
|
406
|
+
var child = children_1_1.value;
|
|
407
|
+
var childStatus = statusMap.get(child);
|
|
408
|
+
if (childStatus === 0) {
|
|
409
|
+
dfs(child);
|
|
410
|
+
}
|
|
411
|
+
else if (childStatus === 1) {
|
|
412
|
+
hasCycle = true;
|
|
413
|
+
}
|
|
213
414
|
}
|
|
214
|
-
|
|
215
|
-
|
|
415
|
+
}
|
|
416
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
417
|
+
finally {
|
|
418
|
+
try {
|
|
419
|
+
if (children_1_1 && !children_1_1.done && (_a = children_1.return)) _a.call(children_1);
|
|
216
420
|
}
|
|
421
|
+
finally { if (e_4) throw e_4.error; }
|
|
217
422
|
}
|
|
218
423
|
statusMap.set(cur, 2);
|
|
219
424
|
sorted.push(cur);
|
|
220
425
|
};
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
426
|
+
try {
|
|
427
|
+
for (var _e = __values(this._vertices), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
428
|
+
var entry = _f.value;
|
|
429
|
+
if (statusMap.get(entry[1]) === 0) {
|
|
430
|
+
dfs(entry[1]);
|
|
431
|
+
}
|
|
224
432
|
}
|
|
225
433
|
}
|
|
434
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
435
|
+
finally {
|
|
436
|
+
try {
|
|
437
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
438
|
+
}
|
|
439
|
+
finally { if (e_3) throw e_3.error; }
|
|
440
|
+
}
|
|
226
441
|
if (hasCycle) {
|
|
227
442
|
return null;
|
|
228
443
|
}
|
|
229
444
|
return sorted.reverse();
|
|
230
|
-
}
|
|
445
|
+
};
|
|
231
446
|
/**--- end find cycles --- */
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
447
|
+
/**
|
|
448
|
+
* The `edgeSet` function returns an array of all the edges in the graph.
|
|
449
|
+
* @returns The `edgeSet()` method returns an array of edges (`E[]`).
|
|
450
|
+
*/
|
|
451
|
+
DirectedGraph.prototype.edgeSet = function () {
|
|
452
|
+
var edges = [];
|
|
453
|
+
this._outEdgeMap.forEach(function (outEdges) {
|
|
454
|
+
edges = __spreadArray(__spreadArray([], __read(edges), false), __read(outEdges), false);
|
|
236
455
|
});
|
|
237
456
|
return edges;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
457
|
+
};
|
|
458
|
+
/**
|
|
459
|
+
* The function `getNeighbors` returns an array of neighboring vertices for a given vertex or vertex ID.
|
|
460
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
461
|
+
* (`VertexId`).
|
|
462
|
+
* @returns an array of vertices (V[]).
|
|
463
|
+
*/
|
|
464
|
+
DirectedGraph.prototype.getNeighbors = function (vertexOrId) {
|
|
465
|
+
var e_5, _a;
|
|
466
|
+
var neighbors = [];
|
|
467
|
+
var vertex = this.getVertex(vertexOrId);
|
|
242
468
|
if (vertex) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
469
|
+
var outEdges = this.outgoingEdgesOf(vertex);
|
|
470
|
+
try {
|
|
471
|
+
for (var outEdges_1 = __values(outEdges), outEdges_1_1 = outEdges_1.next(); !outEdges_1_1.done; outEdges_1_1 = outEdges_1.next()) {
|
|
472
|
+
var outEdge = outEdges_1_1.value;
|
|
473
|
+
var neighbor = this.getVertex(outEdge.dest);
|
|
474
|
+
// TODO after no-non-null-assertion not ensure the logic
|
|
475
|
+
if (neighbor) {
|
|
476
|
+
neighbors.push(neighbor);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
481
|
+
finally {
|
|
482
|
+
try {
|
|
483
|
+
if (outEdges_1_1 && !outEdges_1_1.done && (_a = outEdges_1.return)) _a.call(outEdges_1);
|
|
249
484
|
}
|
|
485
|
+
finally { if (e_5) throw e_5.error; }
|
|
250
486
|
}
|
|
251
487
|
}
|
|
252
488
|
return neighbors;
|
|
253
|
-
}
|
|
254
|
-
|
|
489
|
+
};
|
|
490
|
+
/**
|
|
491
|
+
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
|
|
492
|
+
* otherwise it returns null.
|
|
493
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
494
|
+
* @returns an array containing two vertices [V, V] if the edge is found in the graph. If the edge is not found, it
|
|
495
|
+
* returns null.
|
|
496
|
+
*/
|
|
497
|
+
DirectedGraph.prototype.getEndsOfEdge = function (edge) {
|
|
255
498
|
if (!this.containsEdge(edge.src, edge.dest)) {
|
|
256
499
|
return null;
|
|
257
500
|
}
|
|
258
|
-
|
|
259
|
-
|
|
501
|
+
var v1 = this.getVertex(edge.src);
|
|
502
|
+
var v2 = this.getVertex(edge.dest);
|
|
260
503
|
if (v1 && v2) {
|
|
261
504
|
return [v1, v2];
|
|
262
505
|
}
|
|
263
506
|
else {
|
|
264
507
|
return null;
|
|
265
508
|
}
|
|
266
|
-
}
|
|
267
|
-
|
|
509
|
+
};
|
|
510
|
+
return DirectedGraph;
|
|
511
|
+
}(abstract_graph_1.AbstractGraph));
|
|
268
512
|
exports.DirectedGraph = DirectedGraph;
|