data-structure-typed 1.17.4 → 1.18.5
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/README.md +193 -66
- package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
- package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
- package/backup/recursive-type/src/assets/logo.png +0 -0
- package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +3 -0
- package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +288 -0
- package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +3 -0
- package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +78 -0
- package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +1502 -0
- package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +503 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/index.ts +11 -0
- package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +110 -0
- package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +243 -0
- package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +3 -0
- package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +55 -0
- package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +3 -0
- package/backup/recursive-type/src/data-structures/diagrams/README.md +5 -0
- package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +985 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +478 -0
- package/backup/recursive-type/src/data-structures/graph/index.ts +3 -0
- package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +293 -0
- package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +67 -0
- package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +56 -0
- package/backup/recursive-type/src/data-structures/hash/hash-table.ts +3 -0
- package/backup/recursive-type/src/data-structures/hash/index.ts +6 -0
- package/backup/recursive-type/src/data-structures/hash/pair.ts +3 -0
- package/backup/recursive-type/src/data-structures/hash/tree-map.ts +3 -0
- package/backup/recursive-type/src/data-structures/hash/tree-set.ts +3 -0
- package/backup/recursive-type/src/data-structures/heap/heap.ts +176 -0
- package/backup/recursive-type/src/data-structures/heap/index.ts +3 -0
- package/backup/recursive-type/src/data-structures/heap/max-heap.ts +31 -0
- package/backup/recursive-type/src/data-structures/heap/min-heap.ts +34 -0
- package/backup/recursive-type/src/data-structures/index.ts +15 -0
- package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +42 -0
- package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +56 -0
- package/backup/recursive-type/src/data-structures/interfaces/bst.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +15 -0
- package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/heap.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/index.ts +13 -0
- package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +3 -0
- package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +573 -0
- package/backup/recursive-type/src/data-structures/linked-list/index.ts +3 -0
- package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +490 -0
- package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/backup/recursive-type/src/data-structures/matrix/index.ts +4 -0
- package/backup/recursive-type/src/data-structures/matrix/matrix.ts +27 -0
- package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +208 -0
- package/backup/recursive-type/src/data-structures/matrix/navigator.ts +122 -0
- package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +316 -0
- package/backup/recursive-type/src/data-structures/priority-queue/index.ts +3 -0
- package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +49 -0
- package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +50 -0
- package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +354 -0
- package/backup/recursive-type/src/data-structures/queue/deque.ts +251 -0
- package/backup/recursive-type/src/data-structures/queue/index.ts +2 -0
- package/backup/recursive-type/src/data-structures/queue/queue.ts +120 -0
- package/backup/recursive-type/src/data-structures/stack/index.ts +1 -0
- package/backup/recursive-type/src/data-structures/stack/stack.ts +98 -0
- package/backup/recursive-type/src/data-structures/tree/index.ts +1 -0
- package/backup/recursive-type/src/data-structures/tree/tree.ts +80 -0
- package/backup/recursive-type/src/data-structures/trie/index.ts +1 -0
- package/backup/recursive-type/src/data-structures/trie/trie.ts +227 -0
- package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +5 -0
- package/backup/recursive-type/src/data-structures/types/avl-tree.ts +8 -0
- package/backup/recursive-type/src/data-structures/types/binary-tree.ts +10 -0
- package/backup/recursive-type/src/data-structures/types/bst.ts +6 -0
- package/backup/recursive-type/src/data-structures/types/directed-graph.ts +8 -0
- package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/backup/recursive-type/src/data-structures/types/heap.ts +5 -0
- package/backup/recursive-type/src/data-structures/types/index.ts +12 -0
- package/backup/recursive-type/src/data-structures/types/navigator.ts +13 -0
- package/backup/recursive-type/src/data-structures/types/priority-queue.ts +9 -0
- package/backup/recursive-type/src/data-structures/types/segment-tree.ts +1 -0
- package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +1 -0
- package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +1 -0
- package/backup/recursive-type/src/index.ts +1 -0
- package/backup/recursive-type/src/utils/index.ts +2 -0
- package/backup/recursive-type/src/utils/types/index.ts +1 -0
- package/backup/recursive-type/src/utils/types/utils.ts +6 -0
- package/backup/recursive-type/src/utils/utils.ts +78 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +19 -25
- package/dist/data-structures/binary-tree/avl-tree.js +12 -20
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +10 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +135 -161
- package/dist/data-structures/binary-tree/binary-tree.js +192 -164
- package/dist/data-structures/binary-tree/bst.d.ts +21 -21
- package/dist/data-structures/binary-tree/bst.js +33 -36
- package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -2
- package/dist/data-structures/binary-tree/rb-tree.js +68 -5
- package/dist/data-structures/binary-tree/segment-tree.d.ts +17 -39
- package/dist/data-structures/binary-tree/segment-tree.js +34 -47
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -8
- package/dist/data-structures/binary-tree/tree-multiset.js +7 -6
- package/dist/data-structures/graph/abstract-graph.d.ts +56 -71
- package/dist/data-structures/graph/abstract-graph.js +87 -92
- package/dist/data-structures/graph/directed-graph.d.ts +128 -105
- package/dist/data-structures/graph/directed-graph.js +161 -121
- package/dist/data-structures/graph/undirected-graph.d.ts +81 -62
- package/dist/data-structures/graph/undirected-graph.js +99 -78
- package/dist/data-structures/hash/coordinate-map.d.ts +1 -5
- package/dist/data-structures/hash/coordinate-map.js +3 -9
- package/dist/data-structures/hash/coordinate-set.d.ts +2 -6
- package/dist/data-structures/hash/coordinate-set.js +3 -9
- package/dist/data-structures/hash/hash-table.d.ts +2 -1
- package/dist/data-structures/hash/hash-table.js +7 -0
- package/dist/data-structures/hash/pair.d.ts +2 -1
- package/dist/data-structures/hash/pair.js +7 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -1
- package/dist/data-structures/hash/tree-map.js +7 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -1
- package/dist/data-structures/hash/tree-set.js +7 -0
- package/dist/data-structures/heap/heap.d.ts +0 -14
- package/dist/data-structures/heap/heap.js +3 -27
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/interfaces/abstract-graph.d.ts +22 -0
- package/dist/data-structures/interfaces/abstract-graph.js +2 -0
- package/dist/data-structures/interfaces/avl-tree.d.ts +1 -0
- package/dist/data-structures/interfaces/avl-tree.js +2 -0
- package/dist/data-structures/interfaces/binary-tree.d.ts +27 -0
- package/dist/data-structures/interfaces/binary-tree.js +2 -0
- package/dist/data-structures/interfaces/bst.d.ts +1 -0
- package/dist/data-structures/interfaces/bst.js +2 -0
- package/dist/data-structures/interfaces/directed-graph.d.ts +9 -0
- package/dist/data-structures/interfaces/directed-graph.js +2 -0
- package/dist/data-structures/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/interfaces/doubly-linked-list.js +2 -0
- package/dist/data-structures/interfaces/heap.d.ts +1 -0
- package/dist/data-structures/interfaces/heap.js +2 -0
- package/dist/data-structures/interfaces/index.d.ts +13 -0
- package/dist/data-structures/interfaces/index.js +29 -0
- package/dist/data-structures/interfaces/navigator.d.ts +1 -0
- package/dist/data-structures/interfaces/navigator.js +2 -0
- package/dist/data-structures/interfaces/priority-queue.d.ts +1 -0
- package/dist/data-structures/interfaces/priority-queue.js +2 -0
- package/dist/data-structures/interfaces/segment-tree.d.ts +1 -0
- package/dist/data-structures/interfaces/segment-tree.js +2 -0
- package/dist/data-structures/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/data-structures/interfaces/singly-linked-list.js +2 -0
- package/dist/data-structures/interfaces/tree-multiset.d.ts +1 -0
- package/dist/data-structures/interfaces/tree-multiset.js +2 -0
- package/dist/data-structures/interfaces/undirected-graph.d.ts +2 -0
- package/dist/data-structures/interfaces/undirected-graph.js +2 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -3
- package/dist/data-structures/linked-list/doubly-linked-list.js +12 -18
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -2
- package/dist/data-structures/linked-list/singly-linked-list.js +12 -15
- package/dist/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +4 -4
- package/dist/data-structures/queue/deque.d.ts +5 -5
- package/dist/data-structures/queue/deque.js +6 -6
- package/dist/data-structures/queue/queue.d.ts +1 -1
- package/dist/data-structures/stack/stack.d.ts +1 -1
- package/dist/data-structures/tree/tree.d.ts +12 -4
- package/dist/data-structures/tree/tree.js +44 -12
- package/dist/data-structures/trie/trie.d.ts +3 -3
- package/dist/data-structures/trie/trie.js +10 -10
- package/dist/data-structures/types/abstract-graph.d.ts +1 -20
- package/dist/data-structures/types/avl-tree.d.ts +5 -4
- package/dist/data-structures/types/binary-tree.d.ts +6 -5
- package/dist/data-structures/types/bst.d.ts +4 -3
- package/dist/data-structures/types/directed-graph.d.ts +5 -9
- package/dist/data-structures/types/directed-graph.js +7 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -1
- package/dist/data-structures/types/heap.d.ts +2 -2
- package/dist/data-structures/types/index.d.ts +0 -1
- package/dist/data-structures/types/index.js +0 -1
- package/dist/data-structures/types/navigator.d.ts +2 -2
- package/dist/data-structures/types/priority-queue.d.ts +2 -2
- package/dist/data-structures/types/tree-multiset.d.ts +3 -4
- package/docs/assets/search.js +1 -1
- package/docs/classes/AVLTree.html +552 -405
- package/docs/classes/AVLTreeNode.html +107 -242
- package/docs/classes/AaTree.html +18 -13
- package/docs/classes/AbstractEdge.html +77 -68
- package/docs/classes/AbstractGraph.html +223 -115
- package/docs/classes/AbstractVertex.html +71 -45
- package/docs/classes/ArrayDeque.html +31 -26
- package/docs/classes/BST.html +543 -391
- package/docs/classes/BSTNode.html +107 -236
- package/docs/classes/BTree.html +18 -13
- package/docs/classes/BinaryIndexedTree.html +56 -21
- package/docs/classes/BinaryTree.html +564 -355
- package/docs/classes/BinaryTreeNode.html +146 -199
- package/docs/classes/Character.html +21 -16
- package/docs/classes/CoordinateMap.html +49 -52
- package/docs/classes/CoordinateSet.html +50 -53
- package/docs/classes/Deque.html +51 -68
- package/docs/classes/DirectedEdge.html +98 -103
- package/docs/classes/DirectedGraph.html +449 -210
- package/docs/classes/DirectedVertex.html +63 -52
- package/docs/classes/DoublyLinkedList.html +56 -71
- package/docs/classes/DoublyLinkedListNode.html +28 -23
- package/docs/classes/HashTable.html +155 -0
- package/docs/classes/Heap.html +33 -109
- package/docs/classes/HeapItem.html +25 -20
- package/docs/classes/Matrix2D.html +33 -28
- package/docs/classes/MatrixNTI2D.html +21 -16
- package/docs/classes/MaxHeap.html +33 -114
- package/docs/classes/MaxPriorityQueue.html +71 -61
- package/docs/classes/MinHeap.html +33 -114
- package/docs/classes/MinPriorityQueue.html +71 -61
- package/docs/classes/Navigator.html +28 -23
- package/docs/classes/ObjectDeque.html +66 -51
- package/docs/classes/{RBTree.html → Pair.html} +25 -20
- package/docs/classes/PriorityQueue.html +66 -56
- package/docs/classes/Queue.html +33 -28
- package/docs/classes/SegmentTree.html +129 -57
- package/docs/classes/SegmentTreeNode.html +62 -140
- package/docs/classes/SinglyLinkedList.html +53 -58
- package/docs/classes/SinglyLinkedListNode.html +25 -20
- package/docs/classes/SkipLinkedList.html +18 -13
- package/docs/classes/SplayTree.html +18 -13
- package/docs/classes/Stack.html +31 -26
- package/docs/classes/TreeMap.html +155 -0
- package/docs/classes/TreeMultiSet.html +541 -388
- package/docs/classes/TreeNode.html +125 -35
- package/docs/classes/TreeSet.html +155 -0
- package/docs/classes/Trie.html +30 -25
- package/docs/classes/TrieNode.html +33 -28
- package/docs/classes/TwoThreeTree.html +18 -13
- package/docs/classes/UndirectedEdge.html +87 -80
- package/docs/classes/UndirectedGraph.html +356 -178
- package/docs/classes/UndirectedVertex.html +63 -52
- package/docs/classes/Vector2D.html +45 -40
- package/docs/enums/CP.html +21 -16
- package/docs/enums/FamilyPosition.html +21 -16
- package/docs/enums/LoopType.html +20 -15
- package/docs/{interfaces/AVLTreeDeleted.html → enums/TopologicalProperty.html} +47 -44
- package/docs/index.html +203 -69
- package/docs/interfaces/{PriorityQueueOptions.html → IBinaryTree.html} +49 -40
- package/docs/interfaces/IBinaryTreeNode.html +383 -0
- package/docs/interfaces/IDirectedGraph.html +24 -19
- package/docs/interfaces/IGraph.html +122 -89
- package/docs/interfaces/{HeapOptions.html → IUNDirectedGraph.html} +26 -53
- package/docs/modules.html +33 -23
- package/docs/types/{ToThunkFn.html → AVLTreeDeleted.html} +31 -22
- package/docs/types/BSTComparator.html +18 -13
- package/docs/types/BSTDeletedResult.html +23 -18
- package/docs/types/BinaryTreeDeleted.html +23 -18
- package/docs/types/BinaryTreeNodeId.html +18 -13
- package/docs/types/BinaryTreeNodePropertyName.html +18 -13
- package/docs/types/DFSOrderPattern.html +18 -13
- package/docs/types/DijkstraResult.html +18 -13
- package/docs/types/Direction.html +18 -13
- package/docs/types/{DoublyLinkedListGetBy.html → EdgeId.html} +22 -17
- package/docs/types/{TrlFn.html → HeapOptions.html} +33 -20
- package/docs/types/{TrlAsyncFn.html → NavigatorParams.html} +46 -20
- package/docs/types/NodeOrPropertyName.html +18 -13
- package/docs/types/PriorityQueueComparator.html +18 -13
- package/docs/types/PriorityQueueDFSOrderPattern.html +18 -13
- package/docs/types/{SpecifyOptional.html → PriorityQueueOptions.html} +32 -20
- package/docs/types/RecursiveAVLTreeNode.html +135 -0
- package/docs/types/RecursiveBSTNode.html +135 -0
- package/docs/types/RecursiveBinaryTreeNode.html +135 -0
- package/docs/types/ResultByProperty.html +21 -16
- package/docs/types/ResultsByProperty.html +21 -16
- package/docs/types/SegmentTreeNodeVal.html +18 -13
- package/docs/types/TopologicalStatus.html +18 -13
- package/docs/types/TreeMultiSetDeletedResult.html +23 -18
- package/docs/types/Turning.html +18 -13
- package/docs/types/VertexId.html +18 -13
- package/notes/note.md +12 -1
- package/package.json +11 -3
- package/tsconfig.json +2 -2
- package/docs/interfaces/NavigatorParams.html +0 -197
- package/docs/types/Thunk.html +0 -133
|
Binary file
|
|
Binary file
|
package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import {arrayRemove} from '../../utils';
|
|
9
|
+
import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
|
|
10
|
+
import type {TopologicalStatus, VertexId} from '../types';
|
|
11
|
+
import {IDirectedGraph} from '../interfaces';
|
|
12
|
+
|
|
13
|
+
export class DirectedVertex<T = number> extends AbstractVertex<T> {
|
|
14
|
+
/**
|
|
15
|
+
* The constructor function initializes a vertex with an optional value.
|
|
16
|
+
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is of type `VertexId`, which is
|
|
17
|
+
* typically a unique identifier for each vertex in a graph.
|
|
18
|
+
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to specify the value
|
|
19
|
+
* associated with the vertex.
|
|
20
|
+
*/
|
|
21
|
+
constructor(id: VertexId, val?: T) {
|
|
22
|
+
super(id, val);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// _createVertex(id: VertexId, val?: T): DirectedVertex<T> {
|
|
26
|
+
// return new DirectedVertex<T>(id, val);
|
|
27
|
+
// }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class DirectedEdge<T = number> extends AbstractEdge<T> {
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The constructor function initializes the source and destination vertices of an edge, along with an optional weight
|
|
34
|
+
* and value.
|
|
35
|
+
* @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
36
|
+
* a graph.
|
|
37
|
+
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
|
|
38
|
+
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
|
|
39
|
+
* is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
|
|
40
|
+
* If the weight is not provided, it will default to `undefined`.
|
|
41
|
+
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
|
|
42
|
+
* the edge.
|
|
43
|
+
*/
|
|
44
|
+
constructor(src: VertexId, dest: VertexId, weight?: number, val?: T) {
|
|
45
|
+
super(weight, val);
|
|
46
|
+
this._src = src;
|
|
47
|
+
this._dest = dest;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private _src: VertexId;
|
|
51
|
+
|
|
52
|
+
get src(): VertexId {
|
|
53
|
+
return this._src;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
set src(v: VertexId) {
|
|
57
|
+
this._src = v;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private _dest: VertexId;
|
|
61
|
+
|
|
62
|
+
get dest(): VertexId {
|
|
63
|
+
return this._dest;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
set dest(v: VertexId) {
|
|
67
|
+
this._dest = v;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// _createEdge(src: VertexId, dest: VertexId, weight?: number, val?: T): DirectedEdge<T> {
|
|
71
|
+
// if (weight === undefined || weight === null) weight = 1;
|
|
72
|
+
// return new DirectedEdge(src, dest, weight, val);
|
|
73
|
+
// }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Strongly connected, One direction connected, Weakly connected
|
|
77
|
+
export class DirectedGraph<V extends DirectedVertex<any>, E extends DirectedEdge<any>> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {
|
|
78
|
+
private readonly _vertexConstructor: new (id: VertexId, val?: V['val']) => V;
|
|
79
|
+
private readonly _edgeConstructor: new (src: VertexId, dest: VertexId, weight?: number, val?: E['val']) => E;
|
|
80
|
+
|
|
81
|
+
constructor(vertexConstructor: new (id: VertexId, val?: V['val']) => V, edgeConstructor: new (src: VertexId, dest: VertexId, weight?: number, val?: E['val']) => E) {
|
|
82
|
+
super();
|
|
83
|
+
this._vertexConstructor = vertexConstructor;
|
|
84
|
+
this._edgeConstructor = edgeConstructor;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private _outEdgeMap: Map<V, E[]> = new Map<V, E[]>();
|
|
88
|
+
|
|
89
|
+
get outEdgeMap(): Map<V, E[]> {
|
|
90
|
+
return this._outEdgeMap;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private _inEdgeMap: Map<V, E[]> = new Map<V, E[]>();
|
|
94
|
+
|
|
95
|
+
get inEdgeMap(): Map<V, E[]> {
|
|
96
|
+
return this._inEdgeMap;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
|
|
101
|
+
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
|
|
102
|
+
* @param id
|
|
103
|
+
* @param val
|
|
104
|
+
*/
|
|
105
|
+
_createVertex(id: VertexId, val?: V['val']): V {
|
|
106
|
+
return new this._vertexConstructor(id, val);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
|
|
111
|
+
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
|
|
112
|
+
* @param src
|
|
113
|
+
* @param dest
|
|
114
|
+
* @param weight
|
|
115
|
+
* @param val
|
|
116
|
+
*/
|
|
117
|
+
_createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E {
|
|
118
|
+
if (weight === undefined || weight === null) weight = 1;
|
|
119
|
+
return new this._edgeConstructor(src, dest, weight, val);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The function `getEdge` returns the directed edge between two vertices, given their source and destination.
|
|
124
|
+
* @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a
|
|
125
|
+
* DirectedVertex object or a VertexId.
|
|
126
|
+
* @param {V | null | VertexId} destOrId - The `destOrId` parameter is the destination vertex or its
|
|
127
|
+
* ID. It can be either a `DirectedVertex` object or a `VertexId` value.
|
|
128
|
+
* @returns a E object or null.
|
|
129
|
+
*/
|
|
130
|
+
getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null {
|
|
131
|
+
let edges: E[] = [];
|
|
132
|
+
|
|
133
|
+
if (srcOrId !== null && destOrId !== null) {
|
|
134
|
+
const src: V | null = this._getVertex(srcOrId);
|
|
135
|
+
const dest: V | null = this._getVertex(destOrId);
|
|
136
|
+
|
|
137
|
+
if (src && dest) {
|
|
138
|
+
const srcOutEdges = this._outEdgeMap.get(src);
|
|
139
|
+
if (srcOutEdges) {
|
|
140
|
+
edges = srcOutEdges.filter(edge => edge.dest === dest.id);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return edges[0] || null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The `addEdge` function adds a directed edge to a graph if the source and destination vertices exist.
|
|
150
|
+
* @param edge - The parameter `edge` is of type `E`, which represents a directed edge in a graph. It
|
|
151
|
+
* contains two properties:
|
|
152
|
+
* @returns The method `addEdge` returns a boolean value. It returns `true` if the edge was successfully added to the
|
|
153
|
+
* graph, and `false` if either the source or destination vertex of the edge is not present in the graph.
|
|
154
|
+
*/
|
|
155
|
+
addEdge(edge: E): boolean {
|
|
156
|
+
if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const srcVertex = this._getVertex(edge.src);
|
|
161
|
+
const destVertex = this._getVertex(edge.dest);
|
|
162
|
+
|
|
163
|
+
// TODO after no-non-null-assertion not ensure the logic
|
|
164
|
+
if (srcVertex && destVertex) {
|
|
165
|
+
const srcOutEdges = this._outEdgeMap.get(srcVertex);
|
|
166
|
+
if (srcOutEdges) {
|
|
167
|
+
srcOutEdges.push(edge);
|
|
168
|
+
} else {
|
|
169
|
+
this._outEdgeMap.set(srcVertex, [edge]);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const destInEdges = this._inEdgeMap.get(destVertex);
|
|
173
|
+
if (destInEdges) {
|
|
174
|
+
destInEdges.push(edge);
|
|
175
|
+
} else {
|
|
176
|
+
this._inEdgeMap.set(destVertex, [edge]);
|
|
177
|
+
}
|
|
178
|
+
return true;
|
|
179
|
+
} else {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The `removeEdgeBetween` function removes an edge between two vertices in a directed graph and returns the removed
|
|
186
|
+
* edge, or null if the edge was not found.
|
|
187
|
+
* @param {V | VertexId} srcOrId - The `srcOrId` parameter represents either a `V`
|
|
188
|
+
* object or a `VertexId` value. It is used to specify the source vertex of the edge that you want to remove.
|
|
189
|
+
* @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex of the
|
|
190
|
+
* edge that you want to remove. It can be either a `V` object or a `VertexId` value.
|
|
191
|
+
* @returns The function `removeEdgeBetween` returns the removed edge (`E`) if it exists, or `null` if
|
|
192
|
+
* the edge does not exist.
|
|
193
|
+
*/
|
|
194
|
+
removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null {
|
|
195
|
+
|
|
196
|
+
const src: V | null = this._getVertex(srcOrId);
|
|
197
|
+
const dest: V | null = this._getVertex(destOrId);
|
|
198
|
+
let removed: E | null = null;
|
|
199
|
+
if (!src || !dest) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const srcOutEdges = this._outEdgeMap.get(src);
|
|
204
|
+
if (srcOutEdges) {
|
|
205
|
+
/**
|
|
206
|
+
* The removeEdge function removes an edge from a graph and returns the removed edge, or null if the edge was not
|
|
207
|
+
* found.
|
|
208
|
+
* @param {E} edge - The `edge` parameter represents the edge that you want to remove from the graph. It should be an
|
|
209
|
+
* object that has `src` and `dest` properties, which represent the source and destination vertices of the edge,
|
|
210
|
+
* respectively.
|
|
211
|
+
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
|
|
212
|
+
*/
|
|
213
|
+
arrayRemove<E>(srcOutEdges, (edge: E) => edge.dest === dest.id);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const destInEdges = this._inEdgeMap.get(dest);
|
|
217
|
+
if (destInEdges) {
|
|
218
|
+
removed = arrayRemove<E>(destInEdges, (edge: E) => edge.src === src.id)[0] || null;
|
|
219
|
+
}
|
|
220
|
+
return removed;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* The `removeEdge` function removes a directed edge from a graph and returns the removed edge, or null if the edge was
|
|
225
|
+
* not found.
|
|
226
|
+
* @param edge - The `edge` parameter is an object of type `E`, which represents a directed edge in a
|
|
227
|
+
* graph. It has two properties:
|
|
228
|
+
* @returns The function `removeEdge` returns a `E` object if an edge is successfully removed, or `null`
|
|
229
|
+
* if no edge is removed.
|
|
230
|
+
*/
|
|
231
|
+
removeEdge(edge: E): E | null {
|
|
232
|
+
let removed: E | null = null;
|
|
233
|
+
const src = this._getVertex(edge.src);
|
|
234
|
+
const dest = this._getVertex(edge.dest);
|
|
235
|
+
if (src && dest) {
|
|
236
|
+
const srcOutEdges = this._outEdgeMap.get(src);
|
|
237
|
+
if (srcOutEdges && srcOutEdges.length > 0) {
|
|
238
|
+
arrayRemove(srcOutEdges, (edge: E) => edge.src === src.id);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const destInEdges = this._inEdgeMap.get(dest);
|
|
242
|
+
if (destInEdges && destInEdges.length > 0) {
|
|
243
|
+
removed = arrayRemove(destInEdges, (edge: E) => edge.dest === dest.id)[0];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return removed;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The function removeAllEdges removes all edges between two vertices.
|
|
253
|
+
* @param {VertexId | V} src - The `src` parameter can be either a `VertexId` or a `V`.
|
|
254
|
+
* @param {VertexId | V} dest - The `dest` parameter represents the destination vertex of an edge. It
|
|
255
|
+
* can be either a `VertexId` or a `V`.
|
|
256
|
+
* @returns An empty array of DirectedEdge objects is being returned.
|
|
257
|
+
*/
|
|
258
|
+
removeAllEdges(src: VertexId | V, dest: VertexId | V): E[] {
|
|
259
|
+
return [];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* The function returns an array of incoming edges of a given vertex or vertex ID.
|
|
264
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
|
|
265
|
+
* object or a `VertexId`.
|
|
266
|
+
* @returns The method `incomingEdgesOf` returns an array of `E` objects.
|
|
267
|
+
*/
|
|
268
|
+
incomingEdgesOf(vertexOrId: V | VertexId): E[] {
|
|
269
|
+
const target = this._getVertex(vertexOrId);
|
|
270
|
+
if (target) {
|
|
271
|
+
return this.inEdgeMap.get(target) || []
|
|
272
|
+
}
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* The function `outgoingEdgesOf` returns an array of outgoing directed edges from a given vertex or vertex ID.
|
|
278
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
|
|
279
|
+
* object or a `VertexId`.
|
|
280
|
+
* @returns The method `outgoingEdgesOf` returns an array of `E` objects.
|
|
281
|
+
*/
|
|
282
|
+
outgoingEdgesOf(vertexOrId: V | VertexId): E[] {
|
|
283
|
+
const target = this._getVertex(vertexOrId);
|
|
284
|
+
if (target) {
|
|
285
|
+
return this._outEdgeMap.get(target) || [];
|
|
286
|
+
}
|
|
287
|
+
return [];
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* The function "degreeOf" returns the total degree of a vertex in a directed graph, which is the sum of its out-degree
|
|
292
|
+
* and in-degree.
|
|
293
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
|
|
294
|
+
* `V`.
|
|
295
|
+
* @returns The sum of the out-degree and in-degree of the given vertex or vertex ID.
|
|
296
|
+
*/
|
|
297
|
+
degreeOf(vertexOrId: VertexId | V): number {
|
|
298
|
+
return this.outDegreeOf(vertexOrId) + this.inDegreeOf(vertexOrId);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* The function "inDegreeOf" returns the number of incoming edges for a given vertex or vertex ID in a directed graph.
|
|
303
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
|
|
304
|
+
* `V`.
|
|
305
|
+
* @returns The number of incoming edges of the specified vertex or vertex ID.
|
|
306
|
+
*/
|
|
307
|
+
inDegreeOf(vertexOrId: VertexId | V): number {
|
|
308
|
+
return this.incomingEdgesOf(vertexOrId).length;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* The function "outDegreeOf" returns the number of outgoing edges from a given vertex.
|
|
313
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
|
|
314
|
+
* `V`.
|
|
315
|
+
* @returns The number of outgoing edges from the specified vertex or vertex ID.
|
|
316
|
+
*/
|
|
317
|
+
outDegreeOf(vertexOrId: VertexId | V): number {
|
|
318
|
+
return this.outgoingEdgesOf(vertexOrId).length;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* The function "edgesOf" returns an array of both outgoing and incoming directed edges of a given vertex or vertex ID.
|
|
323
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
|
|
324
|
+
* `V`.
|
|
325
|
+
* @returns an array of directed edges.
|
|
326
|
+
*/
|
|
327
|
+
edgesOf(vertexOrId: VertexId | V): E[] {
|
|
328
|
+
return [...this.outgoingEdgesOf(vertexOrId), ...this.incomingEdgesOf(vertexOrId)];
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* The function "getEdgeSrc" returns the source vertex of a directed edge, or null if the edge does not exist.
|
|
333
|
+
* @param e - A directed edge object of type E.
|
|
334
|
+
* @returns either a DirectedVertex object or null.
|
|
335
|
+
*/
|
|
336
|
+
getEdgeSrc(e: E): V | null {
|
|
337
|
+
return this._getVertex(e.src);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* The function "getEdgeDest" returns the destination vertex of a directed edge.
|
|
342
|
+
* @param e - E - This is an object representing a directed edge in a graph. It contains information
|
|
343
|
+
* about the source vertex, destination vertex, and any associated data.
|
|
344
|
+
* @returns either a DirectedVertex object or null.
|
|
345
|
+
*/
|
|
346
|
+
getEdgeDest(e: E): V | null {
|
|
347
|
+
return this._getVertex(e.dest);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* The function `getDestinations` returns an array of directed vertices that are the destinations of outgoing edges
|
|
352
|
+
* from a given vertex.
|
|
353
|
+
* @param {V | VertexId | null} vertex - The `vertex` parameter can be one of the following:
|
|
354
|
+
* @returns an array of DirectedVertex objects.
|
|
355
|
+
*/
|
|
356
|
+
getDestinations(vertex: V | VertexId | null): V[] {
|
|
357
|
+
if (vertex === null) {
|
|
358
|
+
return [];
|
|
359
|
+
}
|
|
360
|
+
const destinations: V[] = [];
|
|
361
|
+
const outgoingEdges = this.outgoingEdgesOf(vertex);
|
|
362
|
+
for (const outEdge of outgoingEdges) {
|
|
363
|
+
const child = this.getEdgeDest(outEdge);
|
|
364
|
+
if (child) {
|
|
365
|
+
destinations.push(child);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return destinations;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* The `topologicalSort` function performs a topological sort on a directed graph and returns the sorted vertices in
|
|
373
|
+
* reverse order, or null if the graph contains a cycle.
|
|
374
|
+
* @returns The function `topologicalSort()` returns an array of `V` or `VertexId` objects in
|
|
375
|
+
* topological order, or `null` if there is a cycle in the graph.
|
|
376
|
+
*/
|
|
377
|
+
topologicalSort(): Array<V | VertexId> | null {
|
|
378
|
+
// When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
|
|
379
|
+
// When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
|
|
380
|
+
const statusMap: Map<V | VertexId, TopologicalStatus> = new Map<V | VertexId, TopologicalStatus>();
|
|
381
|
+
for (const entry of this.vertices) {
|
|
382
|
+
statusMap.set(entry[1], 0);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const sorted: (V | VertexId)[] = [];
|
|
386
|
+
let hasCycle = false;
|
|
387
|
+
const dfs = (cur: V | VertexId) => {
|
|
388
|
+
statusMap.set(cur, 1);
|
|
389
|
+
const children = this.getDestinations(cur);
|
|
390
|
+
for (const child of children) {
|
|
391
|
+
const childStatus = statusMap.get(child);
|
|
392
|
+
if (childStatus === 0) {
|
|
393
|
+
dfs(child);
|
|
394
|
+
} else if (childStatus === 1) {
|
|
395
|
+
hasCycle = true;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
statusMap.set(cur, 2);
|
|
399
|
+
sorted.push(cur);
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
for (const entry of this.vertices) {
|
|
403
|
+
if (statusMap.get(entry[1]) === 0) {
|
|
404
|
+
dfs(entry[1]);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (hasCycle) return null;
|
|
409
|
+
|
|
410
|
+
return sorted.reverse();
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* The `edgeSet` function returns an array of all directed edges in the graph.
|
|
415
|
+
* @returns The `edgeSet()` method returns an array of `E` objects.
|
|
416
|
+
*/
|
|
417
|
+
edgeSet(): E[] {
|
|
418
|
+
let edges: E[] = [];
|
|
419
|
+
this._outEdgeMap.forEach(outEdges => {
|
|
420
|
+
edges = [...edges, ...outEdges];
|
|
421
|
+
});
|
|
422
|
+
return edges;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**--- start find cycles --- */
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in a directed graph.
|
|
429
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
|
|
430
|
+
* object or a `VertexId`.
|
|
431
|
+
* @returns an array of DirectedVertex objects.
|
|
432
|
+
*/
|
|
433
|
+
getNeighbors(vertexOrId: V | VertexId): V[] {
|
|
434
|
+
const neighbors: V[] = [];
|
|
435
|
+
const vertex = this._getVertex(vertexOrId);
|
|
436
|
+
if (vertex) {
|
|
437
|
+
const outEdges = this.outgoingEdgesOf(vertex);
|
|
438
|
+
for (const outEdge of outEdges) {
|
|
439
|
+
const neighbor = this._getVertex(outEdge.dest);
|
|
440
|
+
// TODO after no-non-null-assertion not ensure the logic
|
|
441
|
+
if (neighbor) {
|
|
442
|
+
neighbors.push(neighbor);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return neighbors;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**--- end find cycles --- */
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* The function "getEndsOfEdge" returns the source and destination vertices of a directed edge if it exists in the
|
|
453
|
+
* graph, otherwise it returns null.
|
|
454
|
+
* @param edge - A directed edge object with a generic type E.
|
|
455
|
+
* @returns an array containing the starting and ending vertices of the given directed edge, or null if the edge does
|
|
456
|
+
* not exist in the graph.
|
|
457
|
+
*/
|
|
458
|
+
getEndsOfEdge(edge: E): [V, V] | null {
|
|
459
|
+
if (!this.hasEdge(edge.src, edge.dest)) {
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
const v1 = this._getVertex(edge.src);
|
|
463
|
+
const v2 = this._getVertex(edge.dest);
|
|
464
|
+
if (v1 && v2) {
|
|
465
|
+
return [v1, v2];
|
|
466
|
+
} else {
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
protected _setOutEdgeMap(value: Map<V, E[]>) {
|
|
472
|
+
this._outEdgeMap = value;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
protected _setInEdgeMap(value: Map<V, E[]>) {
|
|
476
|
+
this._inEdgeMap = value;
|
|
477
|
+
}
|
|
478
|
+
}
|