data-structure-typed 1.18.0 → 1.18.6
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/abstract-binary-tree.d.ts +333 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +1455 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +20 -25
- package/dist/data-structures/binary-tree/avl-tree.js +10 -18
- package/dist/data-structures/binary-tree/binary-tree.d.ts +18 -345
- package/dist/data-structures/binary-tree/binary-tree.js +39 -1444
- package/dist/data-structures/binary-tree/bst.d.ts +24 -31
- package/dist/data-structures/binary-tree/bst.js +46 -53
- package/dist/data-structures/binary-tree/index.d.ts +1 -0
- package/dist/data-structures/binary-tree/index.js +1 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -2
- package/dist/data-structures/binary-tree/rb-tree.js +64 -5
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +11 -25
- package/dist/data-structures/binary-tree/tree-multiset.js +29 -31
- package/dist/data-structures/graph/abstract-graph.d.ts +56 -58
- package/dist/data-structures/graph/abstract-graph.js +84 -68
- package/dist/data-structures/graph/directed-graph.d.ts +124 -95
- package/dist/data-structures/graph/directed-graph.js +156 -108
- package/dist/data-structures/graph/undirected-graph.d.ts +83 -58
- package/dist/data-structures/graph/undirected-graph.js +98 -71
- package/dist/data-structures/hash/coordinate-set.d.ts +1 -1
- 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 +26 -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 -1
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -1
- 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/types/abstract-binary-tree.d.ts +32 -0
- package/dist/data-structures/types/abstract-binary-tree.js +21 -0
- package/dist/data-structures/types/abstract-graph.d.ts +1 -20
- package/dist/data-structures/types/avl-tree.d.ts +3 -4
- package/dist/data-structures/types/binary-tree.d.ts +3 -10
- package/dist/data-structures/types/bst.d.ts +10 -4
- package/dist/data-structures/types/bst.js +7 -0
- 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/heap.d.ts +2 -2
- package/dist/data-structures/types/helpers.d.ts +8 -0
- package/dist/data-structures/types/helpers.js +2 -0
- package/dist/data-structures/types/index.d.ts +3 -1
- package/dist/data-structures/types/index.js +3 -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/rb-tree.d.ts +6 -0
- package/dist/data-structures/types/rb-tree.js +8 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -4
- package/docs/assets/search.js +1 -1
- package/docs/classes/AVLTree.html +310 -309
- package/docs/classes/AVLTreeNode.html +122 -68
- package/docs/classes/AaTree.html +30 -17
- package/docs/classes/AbstractBinaryTree.html +2023 -0
- package/docs/classes/AbstractBinaryTreeNode.html +491 -0
- package/docs/classes/AbstractEdge.html +84 -39
- package/docs/classes/AbstractGraph.html +235 -119
- package/docs/classes/AbstractVertex.html +87 -35
- package/docs/classes/ArrayDeque.html +43 -30
- package/docs/classes/BST.html +297 -285
- package/docs/classes/BSTNode.html +123 -62
- package/docs/classes/BTree.html +30 -17
- package/docs/classes/BinaryIndexedTree.html +38 -25
- package/docs/classes/BinaryTree.html +596 -589
- package/docs/classes/BinaryTreeNode.html +181 -161
- package/docs/classes/Character.html +33 -20
- package/docs/classes/CoordinateMap.html +38 -25
- package/docs/classes/CoordinateSet.html +39 -26
- package/docs/classes/Deque.html +63 -50
- package/docs/classes/DirectedEdge.html +90 -46
- package/docs/classes/DirectedGraph.html +374 -212
- package/docs/classes/DirectedVertex.html +79 -41
- package/docs/classes/DoublyLinkedList.html +68 -55
- package/docs/classes/DoublyLinkedListNode.html +40 -27
- package/docs/classes/HashTable.html +30 -17
- package/docs/classes/Heap.html +45 -32
- package/docs/classes/HeapItem.html +37 -24
- package/docs/classes/Matrix2D.html +45 -32
- package/docs/classes/MatrixNTI2D.html +33 -20
- package/docs/classes/MaxHeap.html +45 -32
- package/docs/classes/MaxPriorityQueue.html +83 -65
- package/docs/classes/MinHeap.html +45 -32
- package/docs/classes/MinPriorityQueue.html +83 -65
- package/docs/classes/Navigator.html +40 -27
- package/docs/classes/ObjectDeque.html +78 -55
- package/docs/classes/Pair.html +30 -17
- package/docs/classes/PriorityQueue.html +78 -60
- package/docs/classes/Queue.html +45 -32
- package/docs/classes/SegmentTree.html +46 -33
- package/docs/classes/SegmentTreeNode.html +49 -36
- package/docs/classes/SinglyLinkedList.html +65 -52
- package/docs/classes/SinglyLinkedListNode.html +37 -24
- package/docs/classes/SkipLinkedList.html +30 -17
- package/docs/classes/SplayTree.html +30 -17
- package/docs/classes/Stack.html +43 -30
- package/docs/classes/TreeMap.html +30 -17
- package/docs/classes/TreeMultiSet.html +330 -316
- package/docs/classes/TreeMultiSetNode.html +450 -0
- package/docs/classes/TreeNode.html +45 -32
- package/docs/classes/TreeSet.html +30 -17
- package/docs/classes/Trie.html +42 -29
- package/docs/classes/TrieNode.html +40 -27
- package/docs/classes/TwoThreeTree.html +30 -17
- package/docs/classes/UndirectedEdge.html +86 -56
- package/docs/classes/UndirectedGraph.html +286 -165
- package/docs/classes/UndirectedVertex.html +79 -41
- package/docs/classes/Vector2D.html +57 -44
- package/docs/enums/CP.html +36 -23
- package/docs/enums/FamilyPosition.html +48 -35
- package/docs/enums/LoopType.html +42 -29
- package/docs/{interfaces/PriorityQueueOptions.html → enums/RBColor.html} +52 -55
- package/docs/{interfaces/AVLTreeDeleted.html → enums/TopologicalProperty.html} +59 -48
- package/docs/index.html +211 -73
- package/docs/interfaces/{NavigatorParams.html → IBinaryTree.html} +56 -67
- package/docs/interfaces/IBinaryTreeNode.html +396 -0
- package/docs/interfaces/IDirectedGraph.html +36 -23
- package/docs/interfaces/IGraph.html +134 -93
- package/docs/interfaces/{HeapOptions.html → IUNDirectedGraph.html} +38 -57
- package/docs/modules.html +57 -31
- package/docs/types/{ToThunkFn.html → AVLTreeOptions.html} +35 -27
- package/docs/types/AbstractBinaryTreeOptions.html +150 -0
- package/docs/types/AbstractRecursiveBinaryTreeNode.html +146 -0
- package/docs/types/{ResultsByProperty.html → AbstractResultByProperty.html} +35 -22
- package/docs/types/{TreeMultiSetDeletedResult.html → AbstractResultsByProperty.html} +35 -29
- package/docs/types/BSTComparator.html +30 -17
- package/docs/types/{TrlAsyncFn.html → BSTOptions.html} +36 -31
- package/docs/types/BinaryTreeDeletedResult.html +153 -0
- package/docs/types/BinaryTreeNodeId.html +30 -17
- package/docs/types/BinaryTreeNodePropertyName.html +30 -17
- package/docs/types/{BinaryTreeDeleted.html → BinaryTreeOptions.html} +35 -31
- package/docs/types/DFSOrderPattern.html +30 -17
- package/docs/types/DijkstraResult.html +30 -17
- package/docs/types/Direction.html +30 -17
- package/docs/types/{SpecifyOptional.html → EdgeId.html} +34 -28
- package/docs/types/{TrlFn.html → HeapOptions.html} +45 -24
- package/docs/types/IdObject.html +151 -0
- package/docs/types/{BSTDeletedResult.html → KeyValObject.html} +36 -30
- package/docs/types/NavigatorParams.html +175 -0
- package/docs/types/NodeOrPropertyName.html +30 -17
- package/docs/types/PriorityQueueComparator.html +30 -17
- package/docs/types/PriorityQueueDFSOrderPattern.html +30 -17
- package/docs/types/PriorityQueueOptions.html +155 -0
- package/docs/types/{Thunk.html → RBTreeOptions.html} +35 -27
- package/docs/types/RecursiveAVLTreeNode.html +146 -0
- package/docs/types/RecursiveBSTNode.html +146 -0
- package/docs/types/RecursiveBinaryTreeNode.html +146 -0
- package/docs/types/RecursiveTreeMultiSetNode.html +146 -0
- package/docs/types/SegmentTreeNodeVal.html +30 -17
- package/docs/types/TopologicalStatus.html +30 -17
- package/docs/types/TreeMultiSetOptions.html +146 -0
- package/docs/types/Turning.html +30 -17
- package/docs/types/VertexId.html +30 -17
- package/notes/note.md +8 -1
- package/package.json +10 -2
- package/docs/classes/RBTree.html +0 -153
- package/docs/types/ResultByProperty.html +0 -133
|
@@ -1,44 +1,50 @@
|
|
|
1
|
-
import type { DijkstraResult,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
protected
|
|
1
|
+
import type { DijkstraResult, VertexId } from '../types';
|
|
2
|
+
import { IGraph } from '../interfaces';
|
|
3
|
+
export declare abstract class AbstractVertex<T = number> {
|
|
4
|
+
protected constructor(id: VertexId, val?: T);
|
|
5
|
+
private _id;
|
|
5
6
|
get id(): VertexId;
|
|
6
7
|
set id(v: VertexId);
|
|
8
|
+
private _val;
|
|
9
|
+
get val(): T | undefined;
|
|
10
|
+
set val(value: T | undefined);
|
|
7
11
|
}
|
|
8
|
-
export declare abstract class AbstractEdge {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
protected constructor(weight?: number);
|
|
15
|
-
protected _weight: number;
|
|
12
|
+
export declare abstract class AbstractEdge<T = number> {
|
|
13
|
+
protected constructor(weight?: number, val?: T);
|
|
14
|
+
private _val;
|
|
15
|
+
get val(): T | undefined;
|
|
16
|
+
set val(value: T | undefined);
|
|
17
|
+
private _weight;
|
|
16
18
|
get weight(): number;
|
|
17
19
|
set weight(v: number);
|
|
18
20
|
protected _hashCode: string;
|
|
19
21
|
get hashCode(): string;
|
|
20
22
|
protected _setHashCode(v: string): void;
|
|
21
23
|
}
|
|
22
|
-
export declare abstract class AbstractGraph<V extends AbstractVertex
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
abstract removeEdge(edge: E): E | null;
|
|
24
|
+
export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E extends AbstractEdge<any>> implements IGraph<V, E> {
|
|
25
|
+
private _vertices;
|
|
26
|
+
get vertices(): Map<VertexId, V>;
|
|
26
27
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
30
|
-
* @
|
|
31
|
-
* If the vertex is found in the `_vertices` map, it is returned. Otherwise, `null` is returned.
|
|
28
|
+
* 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.
|
|
29
|
+
* 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.
|
|
30
|
+
* @param id
|
|
31
|
+
* @param val
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
abstract _createVertex(id: VertexId, val?: V): V;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @param
|
|
38
|
-
*
|
|
39
|
-
* @
|
|
35
|
+
* 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.
|
|
36
|
+
* 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.
|
|
37
|
+
* @param srcOrV1
|
|
38
|
+
* @param destOrV2
|
|
39
|
+
* @param weight
|
|
40
|
+
* @param val
|
|
40
41
|
*/
|
|
41
|
-
|
|
42
|
+
abstract _createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
|
|
43
|
+
abstract removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
44
|
+
abstract removeEdge(edge: E): E | null;
|
|
45
|
+
_getVertex(vertexOrId: VertexId | V): V | null;
|
|
46
|
+
getVertex(vertexId: VertexId): V | null;
|
|
47
|
+
_getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
42
48
|
/**
|
|
43
49
|
* The function checks if a vertex exists in a graph.
|
|
44
50
|
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
|
|
@@ -46,18 +52,8 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
46
52
|
* @returns The method `hasVertex` returns a boolean value.
|
|
47
53
|
*/
|
|
48
54
|
hasVertex(vertexOrId: V | VertexId): boolean;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* @returns The method `vertexSet()` returns a map of vertex IDs to vertex objects.
|
|
52
|
-
*/
|
|
53
|
-
vertexSet(): Map<VertexId, V>;
|
|
54
|
-
abstract getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
|
|
55
|
-
/**
|
|
56
|
-
* The addVertex function adds a new vertex to a graph if it does not already exist.
|
|
57
|
-
* @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
|
|
58
|
-
* @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
|
|
59
|
-
* false. Otherwise, it will add the newVertex to the graph and return true.
|
|
60
|
-
*/
|
|
55
|
+
abstract getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
56
|
+
createAddVertex(id: VertexId, val?: V['val']): boolean;
|
|
61
57
|
addVertex(newVertex: V): boolean;
|
|
62
58
|
/**
|
|
63
59
|
* The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
@@ -87,6 +83,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
87
83
|
* vertices `v1` and `v2`, and `false` otherwise.
|
|
88
84
|
*/
|
|
89
85
|
hasEdge(v1: VertexId | V, v2: VertexId | V): boolean;
|
|
86
|
+
createAddEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E['val']): boolean;
|
|
90
87
|
abstract addEdge(edge: E): boolean;
|
|
91
88
|
/**
|
|
92
89
|
* The function sets the weight of an edge between two vertices in a graph.
|
|
@@ -163,15 +160,6 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
163
160
|
* @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<V>`.
|
|
164
161
|
*/
|
|
165
162
|
dijkstraWithoutHeap(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
|
|
166
|
-
/**
|
|
167
|
-
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
|
|
168
|
-
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
|
|
169
|
-
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
|
|
170
|
-
*/
|
|
171
|
-
/**
|
|
172
|
-
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
173
|
-
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
174
|
-
*/
|
|
175
163
|
/**
|
|
176
164
|
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
177
165
|
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
@@ -191,13 +179,16 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
191
179
|
* @returns The function `dijkstra` returns an object of type `DijkstraResult<V>`.
|
|
192
180
|
*/
|
|
193
181
|
dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
|
|
194
|
-
abstract getEndsOfEdge(edge: E): [V, V] | null;
|
|
195
182
|
/**
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* The
|
|
199
|
-
|
|
183
|
+
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
|
|
184
|
+
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
|
|
185
|
+
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
|
|
186
|
+
*/
|
|
187
|
+
/**
|
|
188
|
+
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
189
|
+
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
200
190
|
*/
|
|
191
|
+
abstract getEndsOfEdge(edge: E): [V, V] | null;
|
|
201
192
|
/**
|
|
202
193
|
* BellmanFord time:O(VE) space:O(V)
|
|
203
194
|
* one to rest pairs
|
|
@@ -223,9 +214,10 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
223
214
|
minPath: V[];
|
|
224
215
|
};
|
|
225
216
|
/**
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
* The
|
|
217
|
+
* BellmanFord time:O(VE) space:O(V)
|
|
218
|
+
* one to rest pairs
|
|
219
|
+
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
220
|
+
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
229
221
|
*/
|
|
230
222
|
/**
|
|
231
223
|
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
@@ -242,7 +234,11 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
242
234
|
costs: number[][];
|
|
243
235
|
predecessor: (V | null)[][];
|
|
244
236
|
};
|
|
245
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
239
|
+
* all pairs
|
|
240
|
+
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
241
|
+
*/
|
|
246
242
|
/**
|
|
247
243
|
* Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
|
|
248
244
|
* Tarjan can find cycles in directed or undirected graph
|
|
@@ -272,4 +268,6 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
272
268
|
SCCs: Map<number, V[]>;
|
|
273
269
|
cycles: Map<number, V[]>;
|
|
274
270
|
};
|
|
271
|
+
/**--- start find cycles --- */
|
|
272
|
+
protected _setVertices(value: Map<VertexId, V>): void;
|
|
275
273
|
}
|
|
@@ -47,8 +47,9 @@ exports.AbstractGraph = exports.AbstractEdge = exports.AbstractVertex = void 0;
|
|
|
47
47
|
var utils_1 = require("../../utils");
|
|
48
48
|
var priority_queue_1 = require("../priority-queue");
|
|
49
49
|
var AbstractVertex = /** @class */ (function () {
|
|
50
|
-
function AbstractVertex(id) {
|
|
50
|
+
function AbstractVertex(id, val) {
|
|
51
51
|
this._id = id;
|
|
52
|
+
this._val = val;
|
|
52
53
|
}
|
|
53
54
|
Object.defineProperty(AbstractVertex.prototype, "id", {
|
|
54
55
|
get: function () {
|
|
@@ -60,19 +61,35 @@ var AbstractVertex = /** @class */ (function () {
|
|
|
60
61
|
enumerable: false,
|
|
61
62
|
configurable: true
|
|
62
63
|
});
|
|
64
|
+
Object.defineProperty(AbstractVertex.prototype, "val", {
|
|
65
|
+
get: function () {
|
|
66
|
+
return this._val;
|
|
67
|
+
},
|
|
68
|
+
set: function (value) {
|
|
69
|
+
this._val = value;
|
|
70
|
+
},
|
|
71
|
+
enumerable: false,
|
|
72
|
+
configurable: true
|
|
73
|
+
});
|
|
63
74
|
return AbstractVertex;
|
|
64
75
|
}());
|
|
65
76
|
exports.AbstractVertex = AbstractVertex;
|
|
66
77
|
var AbstractEdge = /** @class */ (function () {
|
|
67
|
-
|
|
68
|
-
* The function is a protected constructor that initializes the weight and generates a unique hash code for an edge.
|
|
69
|
-
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
70
|
-
* no weight is provided, it will default to the value of `AbstractEdge.DEFAULT_EDGE_WEIGHT`.
|
|
71
|
-
*/
|
|
72
|
-
function AbstractEdge(weight) {
|
|
78
|
+
function AbstractEdge(weight, val) {
|
|
73
79
|
this._weight = weight !== undefined ? weight : 1;
|
|
80
|
+
this._val = val;
|
|
74
81
|
this._hashCode = (0, utils_1.uuidV4)();
|
|
75
82
|
}
|
|
83
|
+
Object.defineProperty(AbstractEdge.prototype, "val", {
|
|
84
|
+
get: function () {
|
|
85
|
+
return this._val;
|
|
86
|
+
},
|
|
87
|
+
set: function (value) {
|
|
88
|
+
this._val = value;
|
|
89
|
+
},
|
|
90
|
+
enumerable: false,
|
|
91
|
+
configurable: true
|
|
92
|
+
});
|
|
76
93
|
Object.defineProperty(AbstractEdge.prototype, "weight", {
|
|
77
94
|
get: function () {
|
|
78
95
|
return this._weight;
|
|
@@ -90,6 +107,15 @@ var AbstractEdge = /** @class */ (function () {
|
|
|
90
107
|
enumerable: false,
|
|
91
108
|
configurable: true
|
|
92
109
|
});
|
|
110
|
+
// /**
|
|
111
|
+
// * 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.
|
|
112
|
+
// * 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.
|
|
113
|
+
// * @param srcOrV1
|
|
114
|
+
// * @param destOrV2
|
|
115
|
+
// * @param weight
|
|
116
|
+
// * @param val
|
|
117
|
+
// */
|
|
118
|
+
// abstract _createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
|
|
93
119
|
AbstractEdge.prototype._setHashCode = function (v) {
|
|
94
120
|
this._hashCode = v;
|
|
95
121
|
};
|
|
@@ -104,25 +130,21 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
104
130
|
/**--- end find cycles --- */
|
|
105
131
|
// Minimum Spanning Tree
|
|
106
132
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
AbstractGraph.prototype.
|
|
115
|
-
var vertexId = this.
|
|
133
|
+
Object.defineProperty(AbstractGraph.prototype, "vertices", {
|
|
134
|
+
get: function () {
|
|
135
|
+
return this._vertices;
|
|
136
|
+
},
|
|
137
|
+
enumerable: false,
|
|
138
|
+
configurable: true
|
|
139
|
+
});
|
|
140
|
+
AbstractGraph.prototype._getVertex = function (vertexOrId) {
|
|
141
|
+
var vertexId = this._getVertexId(vertexOrId);
|
|
116
142
|
return this._vertices.get(vertexId) || null;
|
|
117
143
|
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
* (`VertexId`).
|
|
123
|
-
* @returns the id of the vertex.
|
|
124
|
-
*/
|
|
125
|
-
AbstractGraph.prototype.getVertexId = function (vertexOrId) {
|
|
144
|
+
AbstractGraph.prototype.getVertex = function (vertexId) {
|
|
145
|
+
return this._vertices.get(vertexId) || null;
|
|
146
|
+
};
|
|
147
|
+
AbstractGraph.prototype._getVertexId = function (vertexOrId) {
|
|
126
148
|
return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
|
|
127
149
|
};
|
|
128
150
|
/**
|
|
@@ -132,24 +154,16 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
132
154
|
* @returns The method `hasVertex` returns a boolean value.
|
|
133
155
|
*/
|
|
134
156
|
AbstractGraph.prototype.hasVertex = function (vertexOrId) {
|
|
135
|
-
return this._vertices.has(this.
|
|
157
|
+
return this._vertices.has(this._getVertexId(vertexOrId));
|
|
136
158
|
};
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
*/
|
|
141
|
-
AbstractGraph.prototype.vertexSet = function () {
|
|
142
|
-
return this._vertices;
|
|
159
|
+
AbstractGraph.prototype.createAddVertex = function (id, val) {
|
|
160
|
+
var newVertex = this._createVertex(id, val);
|
|
161
|
+
return this.addVertex(newVertex);
|
|
143
162
|
};
|
|
144
|
-
/**
|
|
145
|
-
* The addVertex function adds a new vertex to a graph if it does not already exist.
|
|
146
|
-
* @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
|
|
147
|
-
* @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
|
|
148
|
-
* false. Otherwise, it will add the newVertex to the graph and return true.
|
|
149
|
-
*/
|
|
150
163
|
AbstractGraph.prototype.addVertex = function (newVertex) {
|
|
151
164
|
if (this.hasVertex(newVertex)) {
|
|
152
165
|
return false;
|
|
166
|
+
// throw (new Error('Duplicated vertex id is not allowed'));
|
|
153
167
|
}
|
|
154
168
|
this._vertices.set(newVertex.id, newVertex);
|
|
155
169
|
return true;
|
|
@@ -161,7 +175,7 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
161
175
|
* @returns The method `removeVertex` returns a boolean value.
|
|
162
176
|
*/
|
|
163
177
|
AbstractGraph.prototype.removeVertex = function (vertexOrId) {
|
|
164
|
-
var vertexId = this.
|
|
178
|
+
var vertexId = this._getVertexId(vertexOrId);
|
|
165
179
|
return this._vertices.delete(vertexId);
|
|
166
180
|
};
|
|
167
181
|
/**
|
|
@@ -202,6 +216,14 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
202
216
|
var edge = this.getEdge(v1, v2);
|
|
203
217
|
return !!edge;
|
|
204
218
|
};
|
|
219
|
+
AbstractGraph.prototype.createAddEdge = function (src, dest, weight, val) {
|
|
220
|
+
if (src instanceof AbstractVertex)
|
|
221
|
+
src = src.id;
|
|
222
|
+
if (dest instanceof AbstractVertex)
|
|
223
|
+
dest = dest.id;
|
|
224
|
+
var newEdge = this._createEdge(src, dest, weight, val);
|
|
225
|
+
return this.addEdge(newEdge);
|
|
226
|
+
};
|
|
205
227
|
/**
|
|
206
228
|
* The function sets the weight of an edge between two vertices in a graph.
|
|
207
229
|
* @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
|
|
@@ -235,8 +257,8 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
235
257
|
AbstractGraph.prototype.getAllPathsBetween = function (v1, v2) {
|
|
236
258
|
var _this = this;
|
|
237
259
|
var paths = [];
|
|
238
|
-
var vertex1 = this.
|
|
239
|
-
var vertex2 = this.
|
|
260
|
+
var vertex1 = this._getVertex(v1);
|
|
261
|
+
var vertex2 = this._getVertex(v2);
|
|
240
262
|
if (!(vertex1 && vertex2)) {
|
|
241
263
|
return [];
|
|
242
264
|
}
|
|
@@ -323,8 +345,8 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
323
345
|
}
|
|
324
346
|
else {
|
|
325
347
|
// BFS
|
|
326
|
-
var vertex2 = this.
|
|
327
|
-
var vertex1 = this.
|
|
348
|
+
var vertex2 = this._getVertex(v2);
|
|
349
|
+
var vertex1 = this._getVertex(v1);
|
|
328
350
|
if (!(vertex1 && vertex2)) {
|
|
329
351
|
return null;
|
|
330
352
|
}
|
|
@@ -409,8 +431,8 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
409
431
|
else {
|
|
410
432
|
// BFS
|
|
411
433
|
var minPath_1 = [];
|
|
412
|
-
var vertex1_1 = this.
|
|
413
|
-
var vertex2 = this.
|
|
434
|
+
var vertex1_1 = this._getVertex(v1);
|
|
435
|
+
var vertex2 = this._getVertex(v2);
|
|
414
436
|
if (!(vertex1_1 && vertex2)) {
|
|
415
437
|
return [];
|
|
416
438
|
}
|
|
@@ -481,8 +503,8 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
481
503
|
var distMap = new Map();
|
|
482
504
|
var seen = new Set();
|
|
483
505
|
var preMap = new Map(); // predecessor
|
|
484
|
-
var srcVertex = this.
|
|
485
|
-
var destVertex = dest ? this.
|
|
506
|
+
var srcVertex = this._getVertex(src);
|
|
507
|
+
var destVertex = dest ? this._getVertex(dest) : null;
|
|
486
508
|
if (!srcVertex) {
|
|
487
509
|
return null;
|
|
488
510
|
}
|
|
@@ -609,15 +631,6 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
609
631
|
genPaths && getPaths(minDest);
|
|
610
632
|
return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
|
|
611
633
|
};
|
|
612
|
-
/**
|
|
613
|
-
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
|
|
614
|
-
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
|
|
615
|
-
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
|
|
616
|
-
*/
|
|
617
|
-
/**
|
|
618
|
-
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
619
|
-
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
620
|
-
*/
|
|
621
634
|
/**
|
|
622
635
|
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
623
636
|
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
@@ -653,8 +666,8 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
653
666
|
var distMap = new Map();
|
|
654
667
|
var seen = new Set();
|
|
655
668
|
var preMap = new Map(); // predecessor
|
|
656
|
-
var srcVertex = this.
|
|
657
|
-
var destVertex = dest ? this.
|
|
669
|
+
var srcVertex = this._getVertex(src);
|
|
670
|
+
var destVertex = dest ? this._getVertex(dest) : null;
|
|
658
671
|
if (!srcVertex) {
|
|
659
672
|
return null;
|
|
660
673
|
}
|
|
@@ -766,12 +779,6 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
766
779
|
}
|
|
767
780
|
return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
|
|
768
781
|
};
|
|
769
|
-
/**
|
|
770
|
-
* BellmanFord time:O(VE) space:O(V)
|
|
771
|
-
* one to rest pairs
|
|
772
|
-
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
773
|
-
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
774
|
-
*/
|
|
775
782
|
/**
|
|
776
783
|
* BellmanFord time:O(VE) space:O(V)
|
|
777
784
|
* one to rest pairs
|
|
@@ -794,7 +801,7 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
794
801
|
getMin = false;
|
|
795
802
|
if (genPath === undefined)
|
|
796
803
|
genPath = false;
|
|
797
|
-
var srcVertex = this.
|
|
804
|
+
var srcVertex = this._getVertex(src);
|
|
798
805
|
var paths = [];
|
|
799
806
|
var distMap = new Map();
|
|
800
807
|
var preMap = new Map(); // predecessor
|
|
@@ -885,9 +892,10 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
885
892
|
return { hasNegativeCycle: hasNegativeCycle, distMap: distMap, preMap: preMap, paths: paths, min: min, minPath: minPath };
|
|
886
893
|
};
|
|
887
894
|
/**
|
|
888
|
-
*
|
|
889
|
-
*
|
|
890
|
-
* The
|
|
895
|
+
* BellmanFord time:O(VE) space:O(V)
|
|
896
|
+
* one to rest pairs
|
|
897
|
+
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
898
|
+
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
891
899
|
*/
|
|
892
900
|
/**
|
|
893
901
|
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
@@ -931,7 +939,11 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
931
939
|
}
|
|
932
940
|
return { costs: costs, predecessor: predecessor };
|
|
933
941
|
};
|
|
934
|
-
|
|
942
|
+
/**
|
|
943
|
+
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
944
|
+
* all pairs
|
|
945
|
+
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
946
|
+
*/
|
|
935
947
|
/**
|
|
936
948
|
* Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
|
|
937
949
|
* Tarjan can find cycles in directed or undirected graph
|
|
@@ -1059,6 +1071,10 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
1059
1071
|
}
|
|
1060
1072
|
return { dfnMap: dfnMap, lowMap: lowMap, bridges: bridges, articulationPoints: articulationPoints, SCCs: SCCs, cycles: cycles };
|
|
1061
1073
|
};
|
|
1074
|
+
/**--- start find cycles --- */
|
|
1075
|
+
AbstractGraph.prototype._setVertices = function (value) {
|
|
1076
|
+
this._vertices = value;
|
|
1077
|
+
};
|
|
1062
1078
|
return AbstractGraph;
|
|
1063
1079
|
}());
|
|
1064
1080
|
exports.AbstractGraph = AbstractGraph;
|