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
|
@@ -33,22 +33,23 @@ var TreeMultiSet = /** @class */ (function (_super) {
|
|
|
33
33
|
* The function creates a new BSTNode with the given id, value, and count.
|
|
34
34
|
* @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
|
|
35
35
|
* distinguish one node from another in the tree.
|
|
36
|
-
* @param {
|
|
36
|
+
* @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.
|
|
37
37
|
* @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
|
|
38
38
|
* occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
|
|
39
39
|
* @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
|
|
40
40
|
*/
|
|
41
|
-
TreeMultiSet.prototype.
|
|
42
|
-
|
|
41
|
+
TreeMultiSet.prototype._createNode = function (id, val, count) {
|
|
42
|
+
var node = new bst_1.BSTNode(id, val, count);
|
|
43
|
+
return node;
|
|
43
44
|
};
|
|
44
45
|
/**
|
|
45
46
|
* The function overrides the add method of the BinarySearchTree class in TypeScript.
|
|
46
47
|
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
|
|
47
|
-
* @param {
|
|
48
|
-
* can be of type `
|
|
48
|
+
* @param {N | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
|
|
49
|
+
* can be of type `N` (the generic type) or `null`.
|
|
49
50
|
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
|
|
50
51
|
* of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
|
|
51
|
-
* @returns The `add` method is returning a `BSTNode<
|
|
52
|
+
* @returns The `add` method is returning a `BSTNode<N>` object or `null`.
|
|
52
53
|
*/
|
|
53
54
|
TreeMultiSet.prototype.add = function (id, val, count) {
|
|
54
55
|
return _super.prototype.add.call(this, id, val, count);
|
|
@@ -1,57 +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);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
getId(): VertexId;
|
|
8
|
+
private _val;
|
|
9
|
+
get val(): T | undefined;
|
|
10
|
+
set val(value: T | undefined);
|
|
11
11
|
}
|
|
12
|
-
export declare abstract class AbstractEdge {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* no weight is provided, it will default to the value of `AbstractEdge.DEFAULT_EDGE_WEIGHT`.
|
|
18
|
-
*/
|
|
19
|
-
protected constructor(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);
|
|
20
17
|
private _weight;
|
|
21
18
|
get weight(): number;
|
|
22
19
|
set weight(v: number);
|
|
23
|
-
|
|
20
|
+
protected _hashCode: string;
|
|
24
21
|
get hashCode(): string;
|
|
25
|
-
|
|
22
|
+
protected _setHashCode(v: string): void;
|
|
23
|
+
}
|
|
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
|
+
* 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
|
|
28
32
|
*/
|
|
29
|
-
|
|
33
|
+
abstract _createVertex(id: VertexId, val?: V): V;
|
|
30
34
|
/**
|
|
31
|
-
*
|
|
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
|
|
32
41
|
*/
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
export declare abstract class AbstractGraph<V extends AbstractVertex, E extends AbstractEdge> implements IGraph<V, E> {
|
|
36
|
-
protected _vertices: Map<VertexId, V>;
|
|
42
|
+
abstract _createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
|
|
37
43
|
abstract removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
38
44
|
abstract removeEdge(edge: E): E | null;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
43
|
-
* @returns The function `getVertex` returns the vertex object (`V`) corresponding to the given `vertexOrId` parameter.
|
|
44
|
-
* If the vertex is found in the `_vertices` map, it is returned. Otherwise, `null` is returned.
|
|
45
|
-
*/
|
|
46
|
-
getVertex(vertexOrId: VertexId | V): V | null;
|
|
47
|
-
/**
|
|
48
|
-
* The function `getVertexId` returns the id of a vertex, whether it is passed as an instance of `AbstractVertex` or as
|
|
49
|
-
* a `VertexId`.
|
|
50
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
51
|
-
* (`VertexId`).
|
|
52
|
-
* @returns the id of the vertex.
|
|
53
|
-
*/
|
|
54
|
-
getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
45
|
+
_getVertex(vertexOrId: VertexId | V): V | null;
|
|
46
|
+
getVertex(vertexId: VertexId): V | null;
|
|
47
|
+
_getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
55
48
|
/**
|
|
56
49
|
* The function checks if a vertex exists in a graph.
|
|
57
50
|
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
|
|
@@ -59,18 +52,8 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
59
52
|
* @returns The method `hasVertex` returns a boolean value.
|
|
60
53
|
*/
|
|
61
54
|
hasVertex(vertexOrId: V | VertexId): boolean;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
* @returns The method `vertexSet()` returns a map of vertex IDs to vertex objects.
|
|
65
|
-
*/
|
|
66
|
-
vertexSet(): Map<VertexId, V>;
|
|
67
|
-
abstract getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
|
|
68
|
-
/**
|
|
69
|
-
* The addVertex function adds a new vertex to a graph if it does not already exist.
|
|
70
|
-
* @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
|
|
71
|
-
* @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
|
|
72
|
-
* false. Otherwise, it will add the newVertex to the graph and return true.
|
|
73
|
-
*/
|
|
55
|
+
abstract getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
56
|
+
createAddVertex(id: VertexId, val?: V['val']): boolean;
|
|
74
57
|
addVertex(newVertex: V): boolean;
|
|
75
58
|
/**
|
|
76
59
|
* The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
@@ -100,6 +83,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
100
83
|
* vertices `v1` and `v2`, and `false` otherwise.
|
|
101
84
|
*/
|
|
102
85
|
hasEdge(v1: VertexId | V, v2: VertexId | V): boolean;
|
|
86
|
+
createAddEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E['val']): boolean;
|
|
103
87
|
abstract addEdge(edge: E): boolean;
|
|
104
88
|
/**
|
|
105
89
|
* The function sets the weight of an edge between two vertices in a graph.
|
|
@@ -176,15 +160,6 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
176
160
|
* @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<V>`.
|
|
177
161
|
*/
|
|
178
162
|
dijkstraWithoutHeap(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
|
|
179
|
-
/**
|
|
180
|
-
* 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.
|
|
181
|
-
* 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.
|
|
182
|
-
* 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.
|
|
183
|
-
*/
|
|
184
|
-
/**
|
|
185
|
-
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
186
|
-
* 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.
|
|
187
|
-
*/
|
|
188
163
|
/**
|
|
189
164
|
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
190
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.
|
|
@@ -204,13 +179,16 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
204
179
|
* @returns The function `dijkstra` returns an object of type `DijkstraResult<V>`.
|
|
205
180
|
*/
|
|
206
181
|
dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
|
|
207
|
-
abstract getEndsOfEdge(edge: E): [V, V] | null;
|
|
208
182
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* The
|
|
212
|
-
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
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.
|
|
213
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.
|
|
190
|
+
*/
|
|
191
|
+
abstract getEndsOfEdge(edge: E): [V, V] | null;
|
|
214
192
|
/**
|
|
215
193
|
* BellmanFord time:O(VE) space:O(V)
|
|
216
194
|
* one to rest pairs
|
|
@@ -236,9 +214,10 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
236
214
|
minPath: V[];
|
|
237
215
|
};
|
|
238
216
|
/**
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
* 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
|
|
242
221
|
*/
|
|
243
222
|
/**
|
|
244
223
|
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
@@ -255,7 +234,11 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
255
234
|
costs: number[][];
|
|
256
235
|
predecessor: (V | null)[][];
|
|
257
236
|
};
|
|
258
|
-
|
|
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
|
+
*/
|
|
259
242
|
/**
|
|
260
243
|
* Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
|
|
261
244
|
* Tarjan can find cycles in directed or undirected graph
|
|
@@ -285,4 +268,6 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
|
|
|
285
268
|
SCCs: Map<number, V[]>;
|
|
286
269
|
cycles: Map<number, V[]>;
|
|
287
270
|
};
|
|
271
|
+
/**--- start find cycles --- */
|
|
272
|
+
protected _setVertices(value: Map<VertexId, V>): void;
|
|
288
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,27 +61,35 @@ var AbstractVertex = /** @class */ (function () {
|
|
|
60
61
|
enumerable: false,
|
|
61
62
|
configurable: true
|
|
62
63
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
+
});
|
|
69
74
|
return AbstractVertex;
|
|
70
75
|
}());
|
|
71
76
|
exports.AbstractVertex = AbstractVertex;
|
|
72
77
|
var AbstractEdge = /** @class */ (function () {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* no weight is provided, it will default to the value of `AbstractEdge.DEFAULT_EDGE_WEIGHT`.
|
|
77
|
-
*/
|
|
78
|
-
function AbstractEdge(weight) {
|
|
79
|
-
if (weight === undefined)
|
|
80
|
-
weight = AbstractEdge.DEFAULT_EDGE_WEIGHT;
|
|
81
|
-
this._weight = weight;
|
|
78
|
+
function AbstractEdge(weight, val) {
|
|
79
|
+
this._weight = weight !== undefined ? weight : 1;
|
|
80
|
+
this._val = val;
|
|
82
81
|
this._hashCode = (0, utils_1.uuidV4)();
|
|
83
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
|
+
});
|
|
84
93
|
Object.defineProperty(AbstractEdge.prototype, "weight", {
|
|
85
94
|
get: function () {
|
|
86
95
|
return this._weight;
|
|
@@ -95,25 +104,21 @@ var AbstractEdge = /** @class */ (function () {
|
|
|
95
104
|
get: function () {
|
|
96
105
|
return this._hashCode;
|
|
97
106
|
},
|
|
98
|
-
set: function (v) {
|
|
99
|
-
this._hashCode = v;
|
|
100
|
-
},
|
|
101
107
|
enumerable: false,
|
|
102
108
|
configurable: true
|
|
103
109
|
});
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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;
|
|
119
|
+
AbstractEdge.prototype._setHashCode = function (v) {
|
|
120
|
+
this._hashCode = v;
|
|
109
121
|
};
|
|
110
|
-
/**
|
|
111
|
-
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
112
|
-
*/
|
|
113
|
-
AbstractEdge.prototype.getHashCode = function () {
|
|
114
|
-
return this._hashCode;
|
|
115
|
-
};
|
|
116
|
-
AbstractEdge.DEFAULT_EDGE_WEIGHT = 1;
|
|
117
122
|
return AbstractEdge;
|
|
118
123
|
}());
|
|
119
124
|
exports.AbstractEdge = AbstractEdge;
|
|
@@ -125,25 +130,21 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
125
130
|
/**--- end find cycles --- */
|
|
126
131
|
// Minimum Spanning Tree
|
|
127
132
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
AbstractGraph.prototype.
|
|
136
|
-
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);
|
|
137
142
|
return this._vertices.get(vertexId) || null;
|
|
138
143
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
* (`VertexId`).
|
|
144
|
-
* @returns the id of the vertex.
|
|
145
|
-
*/
|
|
146
|
-
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) {
|
|
147
148
|
return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
|
|
148
149
|
};
|
|
149
150
|
/**
|
|
@@ -153,24 +154,16 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
153
154
|
* @returns The method `hasVertex` returns a boolean value.
|
|
154
155
|
*/
|
|
155
156
|
AbstractGraph.prototype.hasVertex = function (vertexOrId) {
|
|
156
|
-
return this._vertices.has(this.
|
|
157
|
+
return this._vertices.has(this._getVertexId(vertexOrId));
|
|
157
158
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
*/
|
|
162
|
-
AbstractGraph.prototype.vertexSet = function () {
|
|
163
|
-
return this._vertices;
|
|
159
|
+
AbstractGraph.prototype.createAddVertex = function (id, val) {
|
|
160
|
+
var newVertex = this._createVertex(id, val);
|
|
161
|
+
return this.addVertex(newVertex);
|
|
164
162
|
};
|
|
165
|
-
/**
|
|
166
|
-
* The addVertex function adds a new vertex to a graph if it does not already exist.
|
|
167
|
-
* @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
|
|
168
|
-
* @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
|
|
169
|
-
* false. Otherwise, it will add the newVertex to the graph and return true.
|
|
170
|
-
*/
|
|
171
163
|
AbstractGraph.prototype.addVertex = function (newVertex) {
|
|
172
164
|
if (this.hasVertex(newVertex)) {
|
|
173
165
|
return false;
|
|
166
|
+
// throw (new Error('Duplicated vertex id is not allowed'));
|
|
174
167
|
}
|
|
175
168
|
this._vertices.set(newVertex.id, newVertex);
|
|
176
169
|
return true;
|
|
@@ -182,7 +175,7 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
182
175
|
* @returns The method `removeVertex` returns a boolean value.
|
|
183
176
|
*/
|
|
184
177
|
AbstractGraph.prototype.removeVertex = function (vertexOrId) {
|
|
185
|
-
var vertexId = this.
|
|
178
|
+
var vertexId = this._getVertexId(vertexOrId);
|
|
186
179
|
return this._vertices.delete(vertexId);
|
|
187
180
|
};
|
|
188
181
|
/**
|
|
@@ -223,6 +216,14 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
223
216
|
var edge = this.getEdge(v1, v2);
|
|
224
217
|
return !!edge;
|
|
225
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
|
+
};
|
|
226
227
|
/**
|
|
227
228
|
* The function sets the weight of an edge between two vertices in a graph.
|
|
228
229
|
* @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
|
|
@@ -256,8 +257,8 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
256
257
|
AbstractGraph.prototype.getAllPathsBetween = function (v1, v2) {
|
|
257
258
|
var _this = this;
|
|
258
259
|
var paths = [];
|
|
259
|
-
var vertex1 = this.
|
|
260
|
-
var vertex2 = this.
|
|
260
|
+
var vertex1 = this._getVertex(v1);
|
|
261
|
+
var vertex2 = this._getVertex(v2);
|
|
261
262
|
if (!(vertex1 && vertex2)) {
|
|
262
263
|
return [];
|
|
263
264
|
}
|
|
@@ -344,8 +345,8 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
344
345
|
}
|
|
345
346
|
else {
|
|
346
347
|
// BFS
|
|
347
|
-
var vertex2 = this.
|
|
348
|
-
var vertex1 = this.
|
|
348
|
+
var vertex2 = this._getVertex(v2);
|
|
349
|
+
var vertex1 = this._getVertex(v1);
|
|
349
350
|
if (!(vertex1 && vertex2)) {
|
|
350
351
|
return null;
|
|
351
352
|
}
|
|
@@ -430,8 +431,8 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
430
431
|
else {
|
|
431
432
|
// BFS
|
|
432
433
|
var minPath_1 = [];
|
|
433
|
-
var vertex1_1 = this.
|
|
434
|
-
var vertex2 = this.
|
|
434
|
+
var vertex1_1 = this._getVertex(v1);
|
|
435
|
+
var vertex2 = this._getVertex(v2);
|
|
435
436
|
if (!(vertex1_1 && vertex2)) {
|
|
436
437
|
return [];
|
|
437
438
|
}
|
|
@@ -502,8 +503,8 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
502
503
|
var distMap = new Map();
|
|
503
504
|
var seen = new Set();
|
|
504
505
|
var preMap = new Map(); // predecessor
|
|
505
|
-
var srcVertex = this.
|
|
506
|
-
var destVertex = dest ? this.
|
|
506
|
+
var srcVertex = this._getVertex(src);
|
|
507
|
+
var destVertex = dest ? this._getVertex(dest) : null;
|
|
507
508
|
if (!srcVertex) {
|
|
508
509
|
return null;
|
|
509
510
|
}
|
|
@@ -630,15 +631,6 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
630
631
|
genPaths && getPaths(minDest);
|
|
631
632
|
return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
|
|
632
633
|
};
|
|
633
|
-
/**
|
|
634
|
-
* 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.
|
|
635
|
-
* 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.
|
|
636
|
-
* 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.
|
|
637
|
-
*/
|
|
638
|
-
/**
|
|
639
|
-
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
640
|
-
* 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.
|
|
641
|
-
*/
|
|
642
634
|
/**
|
|
643
635
|
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
644
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.
|
|
@@ -674,8 +666,8 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
674
666
|
var distMap = new Map();
|
|
675
667
|
var seen = new Set();
|
|
676
668
|
var preMap = new Map(); // predecessor
|
|
677
|
-
var srcVertex = this.
|
|
678
|
-
var destVertex = dest ? this.
|
|
669
|
+
var srcVertex = this._getVertex(src);
|
|
670
|
+
var destVertex = dest ? this._getVertex(dest) : null;
|
|
679
671
|
if (!srcVertex) {
|
|
680
672
|
return null;
|
|
681
673
|
}
|
|
@@ -787,12 +779,6 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
787
779
|
}
|
|
788
780
|
return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
|
|
789
781
|
};
|
|
790
|
-
/**
|
|
791
|
-
* BellmanFord time:O(VE) space:O(V)
|
|
792
|
-
* one to rest pairs
|
|
793
|
-
* 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.
|
|
794
|
-
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
795
|
-
*/
|
|
796
782
|
/**
|
|
797
783
|
* BellmanFord time:O(VE) space:O(V)
|
|
798
784
|
* one to rest pairs
|
|
@@ -815,7 +801,7 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
815
801
|
getMin = false;
|
|
816
802
|
if (genPath === undefined)
|
|
817
803
|
genPath = false;
|
|
818
|
-
var srcVertex = this.
|
|
804
|
+
var srcVertex = this._getVertex(src);
|
|
819
805
|
var paths = [];
|
|
820
806
|
var distMap = new Map();
|
|
821
807
|
var preMap = new Map(); // predecessor
|
|
@@ -906,9 +892,10 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
906
892
|
return { hasNegativeCycle: hasNegativeCycle, distMap: distMap, preMap: preMap, paths: paths, min: min, minPath: minPath };
|
|
907
893
|
};
|
|
908
894
|
/**
|
|
909
|
-
*
|
|
910
|
-
*
|
|
911
|
-
* 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
|
|
912
899
|
*/
|
|
913
900
|
/**
|
|
914
901
|
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
@@ -952,7 +939,11 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
952
939
|
}
|
|
953
940
|
return { costs: costs, predecessor: predecessor };
|
|
954
941
|
};
|
|
955
|
-
|
|
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
|
+
*/
|
|
956
947
|
/**
|
|
957
948
|
* Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
|
|
958
949
|
* Tarjan can find cycles in directed or undirected graph
|
|
@@ -1080,6 +1071,10 @@ var AbstractGraph = /** @class */ (function () {
|
|
|
1080
1071
|
}
|
|
1081
1072
|
return { dfnMap: dfnMap, lowMap: lowMap, bridges: bridges, articulationPoints: articulationPoints, SCCs: SCCs, cycles: cycles };
|
|
1082
1073
|
};
|
|
1074
|
+
/**--- start find cycles --- */
|
|
1075
|
+
AbstractGraph.prototype._setVertices = function (value) {
|
|
1076
|
+
this._vertices = value;
|
|
1077
|
+
};
|
|
1083
1078
|
return AbstractGraph;
|
|
1084
1079
|
}());
|
|
1085
1080
|
exports.AbstractGraph = AbstractGraph;
|