data-structure-typed 1.18.7 → 1.19.0
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 +208 -419
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +198 -167
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +413 -398
- package/dist/data-structures/binary-tree/avl-tree.d.ts +24 -16
- package/dist/data-structures/binary-tree/avl-tree.js +23 -17
- package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
- package/dist/data-structures/binary-tree/binary-tree.js +12 -27
- package/dist/data-structures/binary-tree/bst.d.ts +66 -90
- package/dist/data-structures/binary-tree/bst.js +85 -163
- package/dist/data-structures/binary-tree/rb-tree.d.ts +6 -17
- package/dist/data-structures/binary-tree/rb-tree.js +5 -17
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +187 -18
- package/dist/data-structures/binary-tree/tree-multiset.js +716 -39
- package/dist/data-structures/graph/abstract-graph.d.ts +112 -52
- package/dist/data-structures/graph/abstract-graph.js +138 -72
- package/dist/data-structures/graph/directed-graph.d.ts +104 -101
- package/dist/data-structures/graph/directed-graph.js +134 -129
- package/dist/data-structures/graph/undirected-graph.d.ts +66 -65
- package/dist/data-structures/graph/undirected-graph.js +107 -106
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +12 -18
- package/dist/data-structures/interfaces/abstract-graph.d.ts +2 -4
- package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
- package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
- package/dist/data-structures/interfaces/bst.d.ts +4 -5
- package/dist/data-structures/interfaces/rb-tree.d.ts +2 -3
- package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
- package/dist/data-structures/tree/tree.d.ts +1 -4
- package/dist/data-structures/tree/tree.js +1 -12
- package/dist/data-structures/types/abstract-binary-tree.d.ts +10 -6
- package/dist/data-structures/types/abstract-binary-tree.js +9 -5
- package/dist/data-structures/types/avl-tree.d.ts +1 -1
- package/dist/data-structures/types/binary-tree.d.ts +1 -1
- package/dist/data-structures/types/bst.d.ts +1 -1
- package/dist/data-structures/types/bst.js +1 -1
- package/dist/data-structures/types/directed-graph.js +1 -1
- package/dist/data-structures/types/helpers.d.ts +1 -8
- package/dist/data-structures/types/rb-tree.d.ts +2 -0
- package/dist/data-structures/types/rb-tree.js +1 -1
- package/dist/data-structures/types/tree-multiset.d.ts +5 -5
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/index.d.ts +1 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/validate-type.d.ts +19 -0
- package/dist/utils/types/validate-type.js +2 -0
- package/dist/utils/utils.d.ts +2 -2
- package/dist/utils/utils.js +0 -62
- package/dist/utils/validate-type.d.ts +45 -0
- package/dist/utils/validate-type.js +58 -0
- package/package.json +5 -2
- 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 +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
- package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
- package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
- package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
- 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 +0 -11
- package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
- package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
- package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
- package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
- package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
- 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 +0 -478
- package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
- package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
- package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
- package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
- package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
- package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
- package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
- package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
- package/backup/recursive-type/src/data-structures/index.ts +0 -15
- package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
- package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
- package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
- package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
- package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
- package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
- package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
- package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
- package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
- package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
- package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
- package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
- package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
- package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
- package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
- package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
- package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
- package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
- package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
- package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
- package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
- package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
- package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
- package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
- package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
- package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
- package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
- package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
- package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
- package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
- package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
- package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
- package/backup/recursive-type/src/index.ts +0 -1
- package/backup/recursive-type/src/utils/index.ts +0 -2
- package/backup/recursive-type/src/utils/types/index.ts +0 -1
- package/backup/recursive-type/src/utils/types/utils.ts +0 -6
- package/backup/recursive-type/src/utils/utils.ts +0 -78
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -92
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1367
- package/docs/classes/AVLTree.html +0 -2451
- package/docs/classes/AVLTreeNode.html +0 -499
- package/docs/classes/AaTree.html +0 -172
- package/docs/classes/AbstractBinaryTree.html +0 -2118
- package/docs/classes/AbstractBinaryTreeNode.html +0 -524
- package/docs/classes/AbstractEdge.html +0 -295
- package/docs/classes/AbstractGraph.html +0 -1043
- package/docs/classes/AbstractVertex.html +0 -258
- package/docs/classes/ArrayDeque.html +0 -439
- package/docs/classes/BST.html +0 -2297
- package/docs/classes/BSTNode.html +0 -503
- package/docs/classes/BTree.html +0 -172
- package/docs/classes/BinaryIndexedTree.html +0 -341
- package/docs/classes/BinaryTree.html +0 -2133
- package/docs/classes/BinaryTreeNode.html +0 -501
- package/docs/classes/Character.html +0 -220
- package/docs/classes/CoordinateMap.html +0 -483
- package/docs/classes/CoordinateSet.html +0 -444
- package/docs/classes/Deque.html +0 -975
- package/docs/classes/DirectedEdge.html +0 -366
- package/docs/classes/DirectedGraph.html +0 -1443
- package/docs/classes/DirectedVertex.html +0 -254
- package/docs/classes/DoublyLinkedList.html +0 -968
- package/docs/classes/DoublyLinkedListNode.html +0 -297
- package/docs/classes/HashTable.html +0 -172
- package/docs/classes/Heap.html +0 -423
- package/docs/classes/HeapItem.html +0 -255
- package/docs/classes/Matrix2D.html +0 -502
- package/docs/classes/MatrixNTI2D.html +0 -240
- package/docs/classes/MaxHeap.html +0 -436
- package/docs/classes/MaxPriorityQueue.html +0 -836
- package/docs/classes/MinHeap.html +0 -437
- package/docs/classes/MinPriorityQueue.html +0 -838
- package/docs/classes/Navigator.html +0 -313
- package/docs/classes/ObjectDeque.html +0 -455
- package/docs/classes/Pair.html +0 -172
- package/docs/classes/PriorityQueue.html +0 -760
- package/docs/classes/Queue.html +0 -392
- package/docs/classes/RBTree.html +0 -2388
- package/docs/classes/RBTreeNode.html +0 -516
- package/docs/classes/SegmentTree.html +0 -434
- package/docs/classes/SegmentTreeNode.html +0 -357
- package/docs/classes/SinglyLinkedList.html +0 -788
- package/docs/classes/SinglyLinkedListNode.html +0 -270
- package/docs/classes/SkipLinkedList.html +0 -172
- package/docs/classes/SplayTree.html +0 -172
- package/docs/classes/Stack.html +0 -368
- package/docs/classes/TreeMap.html +0 -172
- package/docs/classes/TreeMultiSet.html +0 -2297
- package/docs/classes/TreeMultiSetNode.html +0 -499
- package/docs/classes/TreeNode.html +0 -343
- package/docs/classes/TreeSet.html +0 -172
- package/docs/classes/Trie.html +0 -372
- package/docs/classes/TrieNode.html +0 -280
- package/docs/classes/TwoThreeTree.html +0 -172
- package/docs/classes/UndirectedEdge.html +0 -337
- package/docs/classes/UndirectedGraph.html +0 -1210
- package/docs/classes/UndirectedVertex.html +0 -254
- package/docs/classes/Vector2D.html +0 -805
- package/docs/enums/CP.html +0 -181
- package/docs/enums/FamilyPosition.html +0 -181
- package/docs/enums/LoopType.html +0 -182
- package/docs/enums/RBColor.html +0 -174
- package/docs/enums/TopologicalProperty.html +0 -181
- package/docs/index.html +0 -645
- package/docs/interfaces/IAVLTree.html +0 -1378
- package/docs/interfaces/IAVLTreeNode.html +0 -405
- package/docs/interfaces/IAbstractBinaryTree.html +0 -1124
- package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -384
- package/docs/interfaces/IAbstractGraph.html +0 -433
- package/docs/interfaces/IBST.html +0 -1271
- package/docs/interfaces/IBSTNode.html +0 -408
- package/docs/interfaces/IDirectedGraph.html +0 -572
- package/docs/interfaces/IUNDirectedGraph.html +0 -465
- package/docs/modules.html +0 -262
- package/docs/types/AVLTreeOptions.html +0 -150
- package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -152
- package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -152
- package/docs/types/AbstractBinaryTreeOptions.html +0 -156
- package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -152
- package/docs/types/BSTComparator.html +0 -162
- package/docs/types/BSTOptions.html +0 -152
- package/docs/types/BinaryTreeDeletedResult.html +0 -159
- package/docs/types/BinaryTreeNodeId.html +0 -147
- package/docs/types/BinaryTreeNodePropertyName.html +0 -147
- package/docs/types/BinaryTreeOptions.html +0 -150
- package/docs/types/DFSOrderPattern.html +0 -147
- package/docs/types/DijkstraResult.html +0 -167
- package/docs/types/Direction.html +0 -147
- package/docs/types/EdgeId.html +0 -147
- package/docs/types/HeapOptions.html +0 -168
- package/docs/types/IdObject.html +0 -157
- package/docs/types/KeyValObject.html +0 -152
- package/docs/types/NavigatorParams.html +0 -181
- package/docs/types/NodeOrPropertyName.html +0 -147
- package/docs/types/PriorityQueueComparator.html +0 -167
- package/docs/types/PriorityQueueDFSOrderPattern.html +0 -147
- package/docs/types/PriorityQueueOptions.html +0 -161
- package/docs/types/RBTreeOptions.html +0 -150
- package/docs/types/RecursiveAVLTreeNode.html +0 -152
- package/docs/types/RecursiveBSTNode.html +0 -152
- package/docs/types/RecursiveBinaryTreeNode.html +0 -152
- package/docs/types/RecursiveTreeMultiSetNode.html +0 -152
- package/docs/types/SegmentTreeNodeVal.html +0 -147
- package/docs/types/TopologicalStatus.html +0 -147
- package/docs/types/TreeMultiSetOptions.html +0 -152
- package/docs/types/Turning.html +0 -147
- package/docs/types/VertexId.html +0 -147
- package/notes/bst.test.ts +0 -181
- package/notes/note.md +0 -34
|
@@ -65,10 +65,10 @@ var DirectedVertex = /** @class */ (function (_super) {
|
|
|
65
65
|
__extends(DirectedVertex, _super);
|
|
66
66
|
/**
|
|
67
67
|
* The constructor function initializes a vertex with an optional value.
|
|
68
|
-
* @param {VertexId} id - The `id` parameter is the identifier
|
|
69
|
-
*
|
|
70
|
-
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to
|
|
71
|
-
*
|
|
68
|
+
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
|
|
69
|
+
* used to uniquely identify the vertex within a graph or data structure.
|
|
70
|
+
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
|
|
71
|
+
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
72
72
|
*/
|
|
73
73
|
function DirectedVertex(id, val) {
|
|
74
74
|
return _super.call(this, id, val) || this;
|
|
@@ -83,11 +83,10 @@ var DirectedEdge = /** @class */ (function (_super) {
|
|
|
83
83
|
* and value.
|
|
84
84
|
* @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
85
85
|
* a graph.
|
|
86
|
-
* @param {VertexId} dest - The `dest` parameter
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
|
|
86
|
+
* @param {VertexId} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
|
|
87
|
+
* `VertexId`, which is likely a unique identifier for a vertex in a graph.
|
|
88
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
89
|
+
* @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value associated with
|
|
91
90
|
* the edge.
|
|
92
91
|
*/
|
|
93
92
|
function DirectedEdge(src, dest, weight, val) {
|
|
@@ -119,9 +118,11 @@ var DirectedEdge = /** @class */ (function (_super) {
|
|
|
119
118
|
return DirectedEdge;
|
|
120
119
|
}(abstract_graph_1.AbstractEdge));
|
|
121
120
|
exports.DirectedEdge = DirectedEdge;
|
|
122
|
-
// Strongly connected, One direction connected, Weakly connected
|
|
123
121
|
var DirectedGraph = /** @class */ (function (_super) {
|
|
124
122
|
__extends(DirectedGraph, _super);
|
|
123
|
+
/**
|
|
124
|
+
* The constructor function initializes an instance of a class.
|
|
125
|
+
*/
|
|
125
126
|
function DirectedGraph() {
|
|
126
127
|
var _this = _super.call(this) || this;
|
|
127
128
|
_this._outEdgeMap = new Map();
|
|
@@ -145,8 +146,15 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
145
146
|
/**
|
|
146
147
|
* 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.
|
|
147
148
|
* 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.
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* The function creates a new vertex with an optional value and returns it.
|
|
152
|
+
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is of type `VertexId`, which
|
|
153
|
+
* could be a number or a string depending on how you want to identify your vertices.
|
|
154
|
+
* @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
155
|
+
* it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
|
|
156
|
+
* assigned the same value as the 'id' parameter
|
|
157
|
+
* @returns a new instance of a DirectedVertex object, casted as type V.
|
|
150
158
|
*/
|
|
151
159
|
DirectedGraph.prototype.createVertex = function (id, val) {
|
|
152
160
|
return new DirectedVertex(id, val !== null && val !== void 0 ? val : id);
|
|
@@ -154,21 +162,27 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
154
162
|
/**
|
|
155
163
|
* 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.
|
|
156
164
|
* 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.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
*
|
|
160
|
-
* @param
|
|
165
|
+
*/
|
|
166
|
+
/**
|
|
167
|
+
* The function creates a directed edge between two vertices with an optional weight and value.
|
|
168
|
+
* @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
169
|
+
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
170
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
171
|
+
* weight is provided, it defaults to 1.
|
|
172
|
+
* @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
173
|
+
* is used to store additional information or data associated with the edge.
|
|
174
|
+
* @returns a new instance of a DirectedEdge object, casted as type E.
|
|
161
175
|
*/
|
|
162
176
|
DirectedGraph.prototype.createEdge = function (src, dest, weight, val) {
|
|
163
177
|
return new DirectedEdge(src, dest, weight !== null && weight !== void 0 ? weight : 1, val);
|
|
164
178
|
};
|
|
165
179
|
/**
|
|
166
|
-
* The
|
|
167
|
-
* @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* @returns
|
|
180
|
+
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
181
|
+
* @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
182
|
+
* @param {V | null | VertexId} destOrId - The `destOrId` parameter in the `getEdge` function represents the
|
|
183
|
+
* destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexId`), or `null` if the
|
|
184
|
+
* destination is not specified.
|
|
185
|
+
* @returns the first edge found between the source and destination vertices, or null if no such edge is found.
|
|
172
186
|
*/
|
|
173
187
|
DirectedGraph.prototype.getEdge = function (srcOrId, destOrId) {
|
|
174
188
|
var edges = [];
|
|
@@ -185,49 +199,10 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
185
199
|
return edges[0] || null;
|
|
186
200
|
};
|
|
187
201
|
/**
|
|
188
|
-
* The
|
|
189
|
-
* @param
|
|
190
|
-
*
|
|
191
|
-
* @returns
|
|
192
|
-
* graph, and `false` if either the source or destination vertex of the edge is not present in the graph.
|
|
193
|
-
*/
|
|
194
|
-
DirectedGraph.prototype.addEdge = function (edge) {
|
|
195
|
-
if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
var srcVertex = this._getVertex(edge.src);
|
|
199
|
-
var destVertex = this._getVertex(edge.dest);
|
|
200
|
-
// TODO after no-non-null-assertion not ensure the logic
|
|
201
|
-
if (srcVertex && destVertex) {
|
|
202
|
-
var srcOutEdges = this._outEdgeMap.get(srcVertex);
|
|
203
|
-
if (srcOutEdges) {
|
|
204
|
-
srcOutEdges.push(edge);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
this._outEdgeMap.set(srcVertex, [edge]);
|
|
208
|
-
}
|
|
209
|
-
var destInEdges = this._inEdgeMap.get(destVertex);
|
|
210
|
-
if (destInEdges) {
|
|
211
|
-
destInEdges.push(edge);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
this._inEdgeMap.set(destVertex, [edge]);
|
|
215
|
-
}
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
/**
|
|
223
|
-
* The `removeEdgeBetween` function removes an edge between two vertices in a directed graph and returns the removed
|
|
224
|
-
* edge, or null if the edge was not found.
|
|
225
|
-
* @param {V | VertexId} srcOrId - The `srcOrId` parameter represents either a `V`
|
|
226
|
-
* object or a `VertexId` value. It is used to specify the source vertex of the edge that you want to remove.
|
|
227
|
-
* @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex of the
|
|
228
|
-
* edge that you want to remove. It can be either a `V` object or a `VertexId` value.
|
|
229
|
-
* @returns The function `removeEdgeBetween` returns the removed edge (`E`) if it exists, or `null` if
|
|
230
|
-
* the edge does not exist.
|
|
202
|
+
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
203
|
+
* @param {V | VertexId} srcOrId - The source vertex or its ID.
|
|
204
|
+
* @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex or its ID.
|
|
205
|
+
* @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
|
|
231
206
|
*/
|
|
232
207
|
DirectedGraph.prototype.removeEdgeSrcToDest = function (srcOrId, destOrId) {
|
|
233
208
|
var src = this._getVertex(srcOrId);
|
|
@@ -247,12 +222,10 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
247
222
|
return removed;
|
|
248
223
|
};
|
|
249
224
|
/**
|
|
250
|
-
* The
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
* @returns The function `removeEdge` returns a `E` object if an edge is successfully removed, or `null`
|
|
255
|
-
* if no edge is removed.
|
|
225
|
+
* The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
|
|
226
|
+
* @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
227
|
+
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
228
|
+
* @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
|
|
256
229
|
*/
|
|
257
230
|
DirectedGraph.prototype.removeEdge = function (edge) {
|
|
258
231
|
var removed = null;
|
|
@@ -271,12 +244,12 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
271
244
|
return removed;
|
|
272
245
|
};
|
|
273
246
|
/**
|
|
274
|
-
* The function removes
|
|
275
|
-
* @param {VertexId | V} v1 - The parameter `v1`
|
|
276
|
-
*
|
|
277
|
-
* @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V
|
|
278
|
-
* second vertex
|
|
279
|
-
* @returns
|
|
247
|
+
* The function removes edges between two vertices and returns the removed edges.
|
|
248
|
+
* @param {VertexId | V} v1 - The parameter `v1` can be either a `VertexId` or a `V`. A `VertexId` represents the
|
|
249
|
+
* unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
|
|
250
|
+
* @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V` object. It is used to specify
|
|
251
|
+
* the second vertex in the edge that needs to be removed.
|
|
252
|
+
* @returns an array of removed edges (E[]).
|
|
280
253
|
*/
|
|
281
254
|
DirectedGraph.prototype.removeEdgesBetween = function (v1, v2) {
|
|
282
255
|
var removed = [];
|
|
@@ -289,10 +262,10 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
289
262
|
return removed;
|
|
290
263
|
};
|
|
291
264
|
/**
|
|
292
|
-
* The function returns an array of incoming edges
|
|
293
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
|
|
294
|
-
*
|
|
295
|
-
* @returns The method `incomingEdgesOf` returns an array of `E`
|
|
265
|
+
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
|
|
266
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
267
|
+
* (`VertexId`).
|
|
268
|
+
* @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
|
|
296
269
|
*/
|
|
297
270
|
DirectedGraph.prototype.incomingEdgesOf = function (vertexOrId) {
|
|
298
271
|
var target = this._getVertex(vertexOrId);
|
|
@@ -302,10 +275,10 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
302
275
|
return [];
|
|
303
276
|
};
|
|
304
277
|
/**
|
|
305
|
-
* The function `outgoingEdgesOf` returns an array of outgoing
|
|
306
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can
|
|
307
|
-
*
|
|
308
|
-
* @returns The method `outgoingEdgesOf` returns an array of `E`
|
|
278
|
+
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
|
|
279
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
|
|
280
|
+
* (`VertexId`).
|
|
281
|
+
* @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
|
|
309
282
|
*/
|
|
310
283
|
DirectedGraph.prototype.outgoingEdgesOf = function (vertexOrId) {
|
|
311
284
|
var target = this._getVertex(vertexOrId);
|
|
@@ -315,64 +288,58 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
315
288
|
return [];
|
|
316
289
|
};
|
|
317
290
|
/**
|
|
318
|
-
* The function "degreeOf" returns the total degree of a vertex
|
|
319
|
-
*
|
|
320
|
-
* @
|
|
321
|
-
* `V`.
|
|
322
|
-
* @returns The sum of the out-degree and in-degree of the given vertex or vertex ID.
|
|
291
|
+
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
|
|
292
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
293
|
+
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
|
|
323
294
|
*/
|
|
324
295
|
DirectedGraph.prototype.degreeOf = function (vertexOrId) {
|
|
325
296
|
return this.outDegreeOf(vertexOrId) + this.inDegreeOf(vertexOrId);
|
|
326
297
|
};
|
|
327
298
|
/**
|
|
328
|
-
* The function "inDegreeOf" returns the number of incoming edges for a given vertex
|
|
329
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
|
|
330
|
-
* `V`.
|
|
299
|
+
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
|
|
300
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
331
301
|
* @returns The number of incoming edges of the specified vertex or vertex ID.
|
|
332
302
|
*/
|
|
333
303
|
DirectedGraph.prototype.inDegreeOf = function (vertexOrId) {
|
|
334
304
|
return this.incomingEdgesOf(vertexOrId).length;
|
|
335
305
|
};
|
|
336
306
|
/**
|
|
337
|
-
* The function
|
|
338
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
|
|
339
|
-
* `V`.
|
|
307
|
+
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
|
|
308
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
340
309
|
* @returns The number of outgoing edges from the specified vertex or vertex ID.
|
|
341
310
|
*/
|
|
342
311
|
DirectedGraph.prototype.outDegreeOf = function (vertexOrId) {
|
|
343
312
|
return this.outgoingEdgesOf(vertexOrId).length;
|
|
344
313
|
};
|
|
345
314
|
/**
|
|
346
|
-
* The function "edgesOf" returns an array of both outgoing and incoming
|
|
347
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
|
|
348
|
-
* `
|
|
349
|
-
* @returns an array of directed edges.
|
|
315
|
+
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
|
|
316
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
317
|
+
* @returns The function `edgesOf` returns an array of edges.
|
|
350
318
|
*/
|
|
351
319
|
DirectedGraph.prototype.edgesOf = function (vertexOrId) {
|
|
352
320
|
return __spreadArray(__spreadArray([], __read(this.outgoingEdgesOf(vertexOrId)), false), __read(this.incomingEdgesOf(vertexOrId)), false);
|
|
353
321
|
};
|
|
354
322
|
/**
|
|
355
|
-
* The function "getEdgeSrc" returns the source vertex of
|
|
356
|
-
* @param e -
|
|
357
|
-
* @returns either a
|
|
323
|
+
* The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
|
|
324
|
+
* @param {E} e - The parameter "e" is of type E, which represents an edge in a graph.
|
|
325
|
+
* @returns either a vertex object (V) or null.
|
|
358
326
|
*/
|
|
359
327
|
DirectedGraph.prototype.getEdgeSrc = function (e) {
|
|
360
328
|
return this._getVertex(e.src);
|
|
361
329
|
};
|
|
362
330
|
/**
|
|
363
|
-
* The function "getEdgeDest" returns the destination vertex of
|
|
364
|
-
* @param e -
|
|
365
|
-
*
|
|
366
|
-
* @returns either a DirectedVertex object or null.
|
|
331
|
+
* The function "getEdgeDest" returns the destination vertex of an edge.
|
|
332
|
+
* @param {E} e - The parameter "e" is of type "E", which represents an edge in a graph.
|
|
333
|
+
* @returns either a vertex object of type V or null.
|
|
367
334
|
*/
|
|
368
335
|
DirectedGraph.prototype.getEdgeDest = function (e) {
|
|
369
336
|
return this._getVertex(e.dest);
|
|
370
337
|
};
|
|
371
338
|
/**
|
|
372
|
-
* The function `getDestinations` returns an array of
|
|
373
|
-
* from
|
|
374
|
-
*
|
|
375
|
-
* @returns an array of
|
|
339
|
+
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
|
|
340
|
+
* @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
341
|
+
* find the destinations. It can be either a `V` object, a `VertexId` value, or `null`.
|
|
342
|
+
* @returns an array of vertices (V[]).
|
|
376
343
|
*/
|
|
377
344
|
DirectedGraph.prototype.getDestinations = function (vertex) {
|
|
378
345
|
var e_1, _a;
|
|
@@ -400,14 +367,17 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
400
367
|
return destinations;
|
|
401
368
|
};
|
|
402
369
|
/**
|
|
403
|
-
* The `topologicalSort` function performs a topological sort on a
|
|
404
|
-
*
|
|
405
|
-
* @
|
|
406
|
-
*
|
|
370
|
+
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
|
|
371
|
+
* in the sorted order, or null if the graph contains a cycle.
|
|
372
|
+
* @param {'vertex' | 'id'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
373
|
+
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'id'. If 'vertex' is
|
|
374
|
+
* specified, the vertices themselves will be used for sorting. If 'id' is specified, the ids of
|
|
375
|
+
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
|
|
407
376
|
*/
|
|
408
|
-
DirectedGraph.prototype.topologicalSort = function () {
|
|
377
|
+
DirectedGraph.prototype.topologicalSort = function (propertyName) {
|
|
409
378
|
var e_2, _a, e_3, _b;
|
|
410
379
|
var _this = this;
|
|
380
|
+
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
411
381
|
// When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
|
|
412
382
|
// When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
|
|
413
383
|
var statusMap = new Map();
|
|
@@ -469,11 +439,13 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
469
439
|
}
|
|
470
440
|
if (hasCycle)
|
|
471
441
|
return null;
|
|
442
|
+
if (propertyName === 'id')
|
|
443
|
+
sorted = sorted.map(function (vertex) { return vertex instanceof DirectedVertex ? vertex.id : vertex; });
|
|
472
444
|
return sorted.reverse();
|
|
473
445
|
};
|
|
474
446
|
/**
|
|
475
|
-
* The `edgeSet` function returns an array of all
|
|
476
|
-
* @returns The `edgeSet()` method returns an array of `E`
|
|
447
|
+
* The `edgeSet` function returns an array of all the edges in the graph.
|
|
448
|
+
* @returns The `edgeSet()` method returns an array of edges (`E[]`).
|
|
477
449
|
*/
|
|
478
450
|
DirectedGraph.prototype.edgeSet = function () {
|
|
479
451
|
var edges = [];
|
|
@@ -482,12 +454,11 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
482
454
|
});
|
|
483
455
|
return edges;
|
|
484
456
|
};
|
|
485
|
-
/**--- start find cycles --- */
|
|
486
457
|
/**
|
|
487
|
-
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in a
|
|
488
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
|
|
489
|
-
*
|
|
490
|
-
* @returns an array of
|
|
458
|
+
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
|
|
459
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
460
|
+
* (`VertexId`).
|
|
461
|
+
* @returns an array of vertices (V[]).
|
|
491
462
|
*/
|
|
492
463
|
DirectedGraph.prototype.getNeighbors = function (vertexOrId) {
|
|
493
464
|
var e_5, _a;
|
|
@@ -515,13 +486,12 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
515
486
|
}
|
|
516
487
|
return neighbors;
|
|
517
488
|
};
|
|
518
|
-
/**--- end find cycles --- */
|
|
519
489
|
/**
|
|
520
|
-
* The function "getEndsOfEdge" returns the source and destination vertices of
|
|
521
|
-
*
|
|
522
|
-
* @param edge -
|
|
523
|
-
* @returns an array containing
|
|
524
|
-
* not exist
|
|
490
|
+
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
|
|
491
|
+
* otherwise it returns null.
|
|
492
|
+
* @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph.
|
|
493
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
|
|
494
|
+
* graph. If the edge does not exist, it returns `null`.
|
|
525
495
|
*/
|
|
526
496
|
DirectedGraph.prototype.getEndsOfEdge = function (edge) {
|
|
527
497
|
if (!this.hasEdge(edge.src, edge.dest)) {
|
|
@@ -536,6 +506,41 @@ var DirectedGraph = /** @class */ (function (_super) {
|
|
|
536
506
|
return null;
|
|
537
507
|
}
|
|
538
508
|
};
|
|
509
|
+
/**
|
|
510
|
+
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
|
|
511
|
+
* @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph. It is the edge that
|
|
512
|
+
* needs to be added to the graph.
|
|
513
|
+
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
514
|
+
* source or destination vertex does not exist in the graph.
|
|
515
|
+
*/
|
|
516
|
+
DirectedGraph.prototype._addEdgeOnly = function (edge) {
|
|
517
|
+
if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
var srcVertex = this._getVertex(edge.src);
|
|
521
|
+
var destVertex = this._getVertex(edge.dest);
|
|
522
|
+
// TODO after no-non-null-assertion not ensure the logic
|
|
523
|
+
if (srcVertex && destVertex) {
|
|
524
|
+
var srcOutEdges = this._outEdgeMap.get(srcVertex);
|
|
525
|
+
if (srcOutEdges) {
|
|
526
|
+
srcOutEdges.push(edge);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
this._outEdgeMap.set(srcVertex, [edge]);
|
|
530
|
+
}
|
|
531
|
+
var destInEdges = this._inEdgeMap.get(destVertex);
|
|
532
|
+
if (destInEdges) {
|
|
533
|
+
destInEdges.push(edge);
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
this._inEdgeMap.set(destVertex, [edge]);
|
|
537
|
+
}
|
|
538
|
+
return true;
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
};
|
|
539
544
|
DirectedGraph.prototype._setOutEdgeMap = function (value) {
|
|
540
545
|
this._outEdgeMap = value;
|
|
541
546
|
};
|
|
@@ -4,8 +4,8 @@ import { IUNDirectedGraph } from '../interfaces';
|
|
|
4
4
|
export declare class UndirectedVertex<T = number> extends AbstractVertex<T> {
|
|
5
5
|
/**
|
|
6
6
|
* The constructor function initializes a vertex with an optional value.
|
|
7
|
-
* @param {VertexId} id - The `id` parameter is the identifier
|
|
8
|
-
*
|
|
7
|
+
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
|
|
8
|
+
* used to uniquely identify the vertex within a graph or network.
|
|
9
9
|
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
|
|
10
10
|
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
11
11
|
*/
|
|
@@ -13,14 +13,14 @@ export declare class UndirectedVertex<T = number> extends AbstractVertex<T> {
|
|
|
13
13
|
}
|
|
14
14
|
export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
|
|
15
15
|
/**
|
|
16
|
-
* The constructor function
|
|
16
|
+
* The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
17
17
|
* value.
|
|
18
|
-
* @param {VertexId} v1 - The
|
|
18
|
+
* @param {VertexId} v1 - The first vertex ID of the edge.
|
|
19
19
|
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
|
|
20
20
|
* graph edge.
|
|
21
21
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
22
|
-
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It
|
|
23
|
-
* the edge.
|
|
22
|
+
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store a value associated
|
|
23
|
+
* with the edge.
|
|
24
24
|
*/
|
|
25
25
|
constructor(v1: VertexId, v2: VertexId, weight?: number, val?: T);
|
|
26
26
|
private _vertices;
|
|
@@ -28,99 +28,100 @@ export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
|
|
|
28
28
|
set vertices(v: [VertexId, VertexId]);
|
|
29
29
|
}
|
|
30
30
|
export declare class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> implements IUNDirectedGraph<V, E> {
|
|
31
|
+
/**
|
|
32
|
+
* The constructor initializes a new Map object to store edges.
|
|
33
|
+
*/
|
|
31
34
|
constructor();
|
|
32
35
|
protected _edges: Map<V, E[]>;
|
|
33
36
|
get edges(): Map<V, E[]>;
|
|
34
37
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @param val
|
|
38
|
+
* The function creates a new vertex with an optional value and returns it.
|
|
39
|
+
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is used to distinguish one
|
|
40
|
+
* vertex from another in the graph.
|
|
41
|
+
* @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
42
|
+
* it will be used as the value of the vertex. If no value is provided, the `id` parameter will be used as the value of
|
|
43
|
+
* the vertex.
|
|
44
|
+
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
|
|
39
45
|
*/
|
|
40
46
|
createVertex(id: VertexId, val?: V['val']): V;
|
|
41
47
|
/**
|
|
42
|
-
* The function
|
|
43
|
-
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
44
|
-
*
|
|
45
|
-
* @param {
|
|
46
|
-
*
|
|
47
|
-
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
48
|
-
* weight is provided, the default value is 1.
|
|
48
|
+
* The function creates an undirected edge between two vertices with an optional weight and value.
|
|
49
|
+
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
50
|
+
* @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge.
|
|
51
|
+
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
52
|
+
* no weight is provided, it defaults to 1.
|
|
49
53
|
* @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
50
54
|
* is used to store additional information or data associated with the edge.
|
|
51
|
-
* @returns
|
|
55
|
+
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `E`.
|
|
52
56
|
*/
|
|
53
57
|
createEdge(v1: VertexId, v2: VertexId, weight?: number, val?: E['val']): E;
|
|
54
58
|
/**
|
|
55
|
-
* The function `getEdge` returns the first
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @returns an instance of `E` or `null`.
|
|
59
|
+
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
60
|
+
* @param {V | null | VertexId} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
|
|
61
|
+
* object), `null`, or `VertexId` (a string or number representing the ID of a vertex).
|
|
62
|
+
* @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
|
|
63
|
+
* object), `null`, or `VertexId` (vertex ID).
|
|
64
|
+
* @returns an edge (E) or null.
|
|
62
65
|
*/
|
|
63
66
|
getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
|
|
64
67
|
/**
|
|
65
|
-
* The function
|
|
66
|
-
* @param
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
|
|
70
|
-
addEdge(edge: E): boolean;
|
|
71
|
-
/**
|
|
72
|
-
* The function removes an edge between two vertices in an undirected graph.
|
|
73
|
-
* @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
|
|
74
|
-
* a `VertexId`. It is used to specify one of the vertices of the edge that needs to be removed.
|
|
75
|
-
* @param {V | VertexId} v2 - The parameter `v2` represents either an instance of the
|
|
76
|
-
* `UndirectedVertex` class or a `VertexId`. It is used to identify the second vertex of the edge that needs to be
|
|
77
|
-
* removed.
|
|
78
|
-
* @returns The function `removeEdgeBetween` returns an `E` object if an edge is successfully removed
|
|
79
|
-
* between the two vertices `v1` and `v2`. If either `v1` or `v2` is not found in the graph, or if there is no edge
|
|
80
|
-
* between them, the function returns `null`.
|
|
68
|
+
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
69
|
+
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
|
|
70
|
+
* @param {V | VertexId} v2 - V | VertexId - This parameter can be either a vertex object (V) or a vertex ID
|
|
71
|
+
* (VertexId). It represents the second vertex of the edge that needs to be removed.
|
|
72
|
+
* @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
|
|
81
73
|
*/
|
|
82
74
|
removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
|
|
83
75
|
/**
|
|
84
|
-
* The removeEdge function removes an edge between two vertices in
|
|
85
|
-
* @param edge -
|
|
86
|
-
*
|
|
87
|
-
* @returns The method is returning an UndirectedEdge object or null.
|
|
76
|
+
* The removeEdge function removes an edge between two vertices in a graph.
|
|
77
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
78
|
+
* @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
|
|
88
79
|
*/
|
|
89
80
|
removeEdge(edge: E): E | null;
|
|
90
81
|
/**
|
|
91
|
-
* The function
|
|
92
|
-
*
|
|
93
|
-
* `V`.
|
|
94
|
-
* @returns the degree of
|
|
82
|
+
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|
|
83
|
+
* vertex.
|
|
84
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
85
|
+
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
86
|
+
* edges connected to that vertex.
|
|
95
87
|
*/
|
|
96
88
|
degreeOf(vertexOrId: VertexId | V): number;
|
|
97
89
|
/**
|
|
98
|
-
* The function
|
|
99
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or
|
|
100
|
-
* `V
|
|
101
|
-
* @returns an array of
|
|
90
|
+
* The function returns the edges of a given vertex or vertex ID.
|
|
91
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`. A `VertexId` is a
|
|
92
|
+
* unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
|
|
93
|
+
* @returns an array of edges.
|
|
102
94
|
*/
|
|
103
95
|
edgesOf(vertexOrId: VertexId | V): E[];
|
|
104
96
|
/**
|
|
105
|
-
* The function "edgeSet" returns an array of unique
|
|
106
|
-
* @returns The method `edgeSet()` returns an array of `E
|
|
97
|
+
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
98
|
+
* @returns The method `edgeSet()` returns an array of type `E[]`.
|
|
107
99
|
*/
|
|
108
100
|
edgeSet(): E[];
|
|
109
101
|
/**
|
|
110
|
-
* The function
|
|
111
|
-
* @param {V | VertexId} vertexOrId - The `vertexOrId`
|
|
112
|
-
* `
|
|
113
|
-
* @returns an array of
|
|
102
|
+
* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
|
|
103
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
104
|
+
* (`VertexId`).
|
|
105
|
+
* @returns an array of vertices (V[]).
|
|
114
106
|
*/
|
|
115
107
|
getNeighbors(vertexOrId: V | VertexId): V[];
|
|
116
108
|
/**
|
|
117
|
-
* The function "getEndsOfEdge" returns the
|
|
118
|
-
*
|
|
119
|
-
* @param edge -
|
|
120
|
-
* array containing two vertices
|
|
121
|
-
*
|
|
122
|
-
* exists in the graph. If the edge does not exist, it returns `null`.
|
|
109
|
+
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
110
|
+
* it returns null.
|
|
111
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
112
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
|
|
113
|
+
* graph. If the edge does not exist, it returns `null`.
|
|
123
114
|
*/
|
|
124
115
|
getEndsOfEdge(edge: E): [V, V] | null;
|
|
116
|
+
/**
|
|
117
|
+
* The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
|
|
118
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
119
|
+
* @returns a boolean value.
|
|
120
|
+
*/
|
|
121
|
+
protected _addEdgeOnly(edge: E): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* The function sets the edges of a graph.
|
|
124
|
+
* @param v - A map where the keys are of type V and the values are arrays of type E.
|
|
125
|
+
*/
|
|
125
126
|
protected _setEdges(v: Map<V, E[]>): void;
|
|
126
127
|
}
|