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
|
@@ -1,111 +1,130 @@
|
|
|
1
1
|
import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
|
|
2
2
|
import type { VertexId } from '../types';
|
|
3
|
-
export declare class UndirectedVertex extends AbstractVertex {
|
|
3
|
+
export declare class UndirectedVertex<T = number> extends AbstractVertex<T> {
|
|
4
4
|
/**
|
|
5
|
-
* The constructor function initializes
|
|
6
|
-
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is
|
|
7
|
-
* vertex
|
|
5
|
+
* The constructor function initializes a vertex with an optional value.
|
|
6
|
+
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is of type `VertexId`, which is
|
|
7
|
+
* typically a unique identifier for each vertex in a graph.
|
|
8
|
+
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
|
|
9
|
+
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
8
10
|
*/
|
|
9
|
-
constructor(id: VertexId);
|
|
11
|
+
constructor(id: VertexId, val?: T);
|
|
10
12
|
}
|
|
11
|
-
export declare class UndirectedEdge extends AbstractEdge {
|
|
13
|
+
export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
|
|
12
14
|
/**
|
|
13
|
-
* The constructor function initializes an instance of a class with two vertex IDs and an optional
|
|
15
|
+
* The constructor function initializes an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
16
|
+
* value.
|
|
14
17
|
* @param {VertexId} v1 - The parameter `v1` is of type `VertexId` and represents the first vertex in the edge.
|
|
15
18
|
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
|
|
16
|
-
* graph.
|
|
17
|
-
* @param {number} [weight] - The
|
|
18
|
-
*
|
|
19
|
+
* graph edge.
|
|
20
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
21
|
+
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
|
|
22
|
+
* the edge.
|
|
19
23
|
*/
|
|
20
|
-
constructor(v1: VertexId, v2: VertexId, weight?: number);
|
|
24
|
+
constructor(v1: VertexId, v2: VertexId, weight?: number, val?: T);
|
|
21
25
|
private _vertices;
|
|
22
26
|
get vertices(): [VertexId, VertexId];
|
|
23
27
|
set vertices(v: [VertexId, VertexId]);
|
|
24
|
-
/**
|
|
25
|
-
* 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.
|
|
26
|
-
*/
|
|
27
|
-
getVertices(): [VertexId, VertexId];
|
|
28
28
|
}
|
|
29
|
-
export declare class UndirectedGraph<V extends UndirectedVertex
|
|
30
|
-
|
|
29
|
+
export declare class UndirectedGraph<V extends UndirectedVertex<any>, E extends UndirectedEdge<any>> extends AbstractGraph<V, E> {
|
|
30
|
+
private readonly _vertexConstructor;
|
|
31
|
+
private readonly _edgeConstructor;
|
|
32
|
+
constructor(vertexConstructor: new (id: VertexId, val?: V['val']) => V, edgeConstructor: new (src: VertexId, dest: VertexId, weight?: number, val?: E['val']) => E);
|
|
31
33
|
protected _edges: Map<V, E[]>;
|
|
32
34
|
get edges(): Map<V, E[]>;
|
|
33
|
-
protected set edges(v: Map<V, E[]>);
|
|
34
35
|
/**
|
|
35
|
-
*
|
|
36
|
+
* 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.
|
|
37
|
+
* 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.
|
|
38
|
+
* @param id
|
|
39
|
+
* @param val
|
|
40
|
+
*/
|
|
41
|
+
_createVertex(id: VertexId, val?: V['val']): V;
|
|
42
|
+
/**
|
|
43
|
+
* 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.
|
|
44
|
+
* 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.
|
|
45
|
+
* @param src
|
|
46
|
+
* @param dest
|
|
47
|
+
* @param weight
|
|
48
|
+
* @param val
|
|
36
49
|
*/
|
|
37
|
-
|
|
50
|
+
_createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
|
|
38
51
|
/**
|
|
39
|
-
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
52
|
+
* The function `getEdge` returns the first undirected edge that connects two given vertices, or null if no such edge
|
|
53
|
+
* exists.
|
|
54
|
+
* @param {V | null | VertexId} v1 - The parameter `v1` represents either an `V`
|
|
55
|
+
* object, `null`, or a `VertexId`. It is used to specify one of the vertices of the edge.
|
|
56
|
+
* @param {V | null | VertexId} v2 - The parameter `v2` represents either an `UndirectedVertex`
|
|
57
|
+
* object or a `VertexId` (identifier) of an undirected vertex.
|
|
58
|
+
* @returns an instance of `E` or `null`.
|
|
45
59
|
*/
|
|
46
60
|
getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
|
|
47
61
|
/**
|
|
48
|
-
* The function adds an edge to a graph by
|
|
49
|
-
* @param
|
|
62
|
+
* The function adds an undirected edge to a graph by updating the adjacency list.
|
|
63
|
+
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
|
|
64
|
+
* array of two vertices connected by the edge.
|
|
50
65
|
* @returns a boolean value.
|
|
51
66
|
*/
|
|
52
67
|
addEdge(edge: E): boolean;
|
|
53
68
|
/**
|
|
54
|
-
* The function removes an edge between two vertices in
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* @param {V | VertexId} v2 -
|
|
58
|
-
*
|
|
69
|
+
* The function removes an edge between two vertices in an undirected graph.
|
|
70
|
+
* @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
|
|
71
|
+
* a `VertexId`. It is used to specify one of the vertices of the edge that needs to be removed.
|
|
72
|
+
* @param {V | VertexId} v2 - The parameter `v2` represents either an instance of the
|
|
73
|
+
* `UndirectedVertex` class or a `VertexId`. It is used to identify the second vertex of the edge that needs to be
|
|
74
|
+
* removed.
|
|
75
|
+
* @returns The function `removeEdgeBetween` returns an `E` object if an edge is successfully removed
|
|
76
|
+
* between the two vertices `v1` and `v2`. If either `v1` or `v2` is not found in the graph, or if there is no edge
|
|
77
|
+
* between them, the function returns `null`.
|
|
59
78
|
*/
|
|
60
79
|
removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
|
|
61
80
|
/**
|
|
62
|
-
* The removeEdge function removes an edge between two vertices in
|
|
63
|
-
* @param
|
|
64
|
-
*
|
|
81
|
+
* The removeEdge function removes an edge between two vertices in an undirected graph.
|
|
82
|
+
* @param edge - An object representing an undirected edge. It has a property called "vertices" which is an array
|
|
83
|
+
* containing the two vertices connected by the edge.
|
|
84
|
+
* @returns The method is returning an UndirectedEdge object or null.
|
|
65
85
|
*/
|
|
66
86
|
removeEdge(edge: E): E | null;
|
|
67
87
|
/**
|
|
68
|
-
* The function
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* @returns
|
|
72
|
-
* edges that are incident to that vertex.
|
|
88
|
+
* The function "degreeOf" returns the degree of a given vertex in an undirected graph.
|
|
89
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
|
|
90
|
+
* `V`.
|
|
91
|
+
* @returns the degree of the vertex.
|
|
73
92
|
*/
|
|
74
93
|
degreeOf(vertexOrId: VertexId | V): number;
|
|
75
94
|
/**
|
|
76
|
-
* The function "edgesOf" returns an array of edges connected to a given vertex.
|
|
77
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or
|
|
78
|
-
*
|
|
79
|
-
* returns
|
|
80
|
-
* an empty array.
|
|
95
|
+
* The function "edgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
|
|
96
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
|
|
97
|
+
* `V`.
|
|
98
|
+
* @returns an array of UndirectedEdge objects.
|
|
81
99
|
*/
|
|
82
100
|
edgesOf(vertexOrId: VertexId | V): E[];
|
|
83
101
|
/**
|
|
84
|
-
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
85
|
-
* @returns The method `edgeSet()` returns an array of
|
|
102
|
+
* The function "edgeSet" returns an array of unique undirected edges from a set of edges.
|
|
103
|
+
* @returns The method `edgeSet()` returns an array of `E` objects.
|
|
86
104
|
*/
|
|
87
105
|
edgeSet(): E[];
|
|
88
106
|
/**
|
|
89
|
-
* The function "getEdgesOf" returns an array of edges connected to a given vertex or vertex ID.
|
|
90
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can
|
|
91
|
-
*
|
|
92
|
-
* @returns an array of
|
|
107
|
+
* The function "getEdgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
|
|
108
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either an
|
|
109
|
+
* `V` object or a `VertexId`.
|
|
110
|
+
* @returns The function `getEdgesOf` returns an array of `E` objects.
|
|
93
111
|
*/
|
|
94
112
|
getEdgesOf(vertexOrId: V | VertexId): E[];
|
|
95
113
|
/**
|
|
96
|
-
* The function
|
|
97
|
-
* @param {V | VertexId} vertexOrId - The
|
|
98
|
-
*
|
|
99
|
-
* @returns an array of
|
|
114
|
+
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in an undirected graph.
|
|
115
|
+
* @param {V | VertexId} vertexOrId - The `vertexOrId` parameter can be either an
|
|
116
|
+
* `V` object or a `VertexId`. It represents the vertex for which we want to find the neighbors.
|
|
117
|
+
* @returns an array of UndirectedVertex objects.
|
|
100
118
|
*/
|
|
101
119
|
getNeighbors(vertexOrId: V | VertexId): V[];
|
|
102
120
|
/**
|
|
103
|
-
* The function "getEndsOfEdge" returns the vertices
|
|
104
|
-
* the graph.
|
|
105
|
-
* @param
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* `null`.
|
|
121
|
+
* The function "getEndsOfEdge" returns the two vertices that form the ends of a given undirected edge, or null if the
|
|
122
|
+
* edge does not exist in the graph.
|
|
123
|
+
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
|
|
124
|
+
* array containing two vertices that the edge connects.
|
|
125
|
+
* @returns The function `getEndsOfEdge` returns an array containing the two ends of the given `edge` if the edge
|
|
126
|
+
* exists in the graph. If the edge does not exist, it returns `null`.
|
|
109
127
|
*/
|
|
110
128
|
getEndsOfEdge(edge: E): [V, V] | null;
|
|
129
|
+
protected _setEdges(v: Map<V, E[]>): void;
|
|
111
130
|
}
|
|
@@ -64,12 +64,14 @@ var abstract_graph_1 = require("./abstract-graph");
|
|
|
64
64
|
var UndirectedVertex = /** @class */ (function (_super) {
|
|
65
65
|
__extends(UndirectedVertex, _super);
|
|
66
66
|
/**
|
|
67
|
-
* The constructor function initializes
|
|
68
|
-
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is
|
|
69
|
-
* vertex
|
|
67
|
+
* The constructor function initializes a vertex with an optional value.
|
|
68
|
+
* @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is of type `VertexId`, which is
|
|
69
|
+
* typically a unique identifier for each vertex in a graph.
|
|
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.
|
|
70
72
|
*/
|
|
71
|
-
function UndirectedVertex(id) {
|
|
72
|
-
return _super.call(this, id) || this;
|
|
73
|
+
function UndirectedVertex(id, val) {
|
|
74
|
+
return _super.call(this, id, val) || this;
|
|
73
75
|
}
|
|
74
76
|
return UndirectedVertex;
|
|
75
77
|
}(abstract_graph_1.AbstractVertex));
|
|
@@ -77,15 +79,17 @@ exports.UndirectedVertex = UndirectedVertex;
|
|
|
77
79
|
var UndirectedEdge = /** @class */ (function (_super) {
|
|
78
80
|
__extends(UndirectedEdge, _super);
|
|
79
81
|
/**
|
|
80
|
-
* The constructor function initializes an instance of a class with two vertex IDs and an optional
|
|
82
|
+
* The constructor function initializes an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
83
|
+
* value.
|
|
81
84
|
* @param {VertexId} v1 - The parameter `v1` is of type `VertexId` and represents the first vertex in the edge.
|
|
82
85
|
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
|
|
83
|
-
* graph.
|
|
84
|
-
* @param {number} [weight] - The
|
|
85
|
-
*
|
|
86
|
+
* graph edge.
|
|
87
|
+
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
88
|
+
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
|
|
89
|
+
* the edge.
|
|
86
90
|
*/
|
|
87
|
-
function UndirectedEdge(v1, v2, weight) {
|
|
88
|
-
var _this = _super.call(this, weight) || this;
|
|
91
|
+
function UndirectedEdge(v1, v2, weight, val) {
|
|
92
|
+
var _this = _super.call(this, weight, val) || this;
|
|
89
93
|
_this._vertices = [v1, v2];
|
|
90
94
|
return _this;
|
|
91
95
|
}
|
|
@@ -99,19 +103,15 @@ var UndirectedEdge = /** @class */ (function (_super) {
|
|
|
99
103
|
enumerable: false,
|
|
100
104
|
configurable: true
|
|
101
105
|
});
|
|
102
|
-
/**
|
|
103
|
-
* 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.
|
|
104
|
-
*/
|
|
105
|
-
UndirectedEdge.prototype.getVertices = function () {
|
|
106
|
-
return this._vertices;
|
|
107
|
-
};
|
|
108
106
|
return UndirectedEdge;
|
|
109
107
|
}(abstract_graph_1.AbstractEdge));
|
|
110
108
|
exports.UndirectedEdge = UndirectedEdge;
|
|
111
109
|
var UndirectedGraph = /** @class */ (function (_super) {
|
|
112
110
|
__extends(UndirectedGraph, _super);
|
|
113
|
-
function UndirectedGraph() {
|
|
111
|
+
function UndirectedGraph(vertexConstructor, edgeConstructor) {
|
|
114
112
|
var _this = _super.call(this) || this;
|
|
113
|
+
_this._vertexConstructor = vertexConstructor;
|
|
114
|
+
_this._edgeConstructor = edgeConstructor;
|
|
115
115
|
_this._edges = new Map();
|
|
116
116
|
return _this;
|
|
117
117
|
}
|
|
@@ -119,32 +119,46 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
119
119
|
get: function () {
|
|
120
120
|
return this._edges;
|
|
121
121
|
},
|
|
122
|
-
set: function (v) {
|
|
123
|
-
this._edges = v;
|
|
124
|
-
},
|
|
125
122
|
enumerable: false,
|
|
126
123
|
configurable: true
|
|
127
124
|
});
|
|
128
125
|
/**
|
|
129
|
-
*
|
|
126
|
+
* 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.
|
|
127
|
+
* 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.
|
|
128
|
+
* @param id
|
|
129
|
+
* @param val
|
|
130
130
|
*/
|
|
131
|
-
UndirectedGraph.prototype.
|
|
132
|
-
return this.
|
|
131
|
+
UndirectedGraph.prototype._createVertex = function (id, val) {
|
|
132
|
+
return new this._vertexConstructor(id, val);
|
|
133
133
|
};
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* @param
|
|
139
|
-
*
|
|
140
|
-
* @
|
|
135
|
+
* 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.
|
|
136
|
+
* 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.
|
|
137
|
+
* @param src
|
|
138
|
+
* @param dest
|
|
139
|
+
* @param weight
|
|
140
|
+
* @param val
|
|
141
|
+
*/
|
|
142
|
+
UndirectedGraph.prototype._createEdge = function (src, dest, weight, val) {
|
|
143
|
+
if (weight === undefined || weight === null)
|
|
144
|
+
weight = 1;
|
|
145
|
+
return new this._edgeConstructor(src, dest, weight, val);
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* The function `getEdge` returns the first undirected edge that connects two given vertices, or null if no such edge
|
|
149
|
+
* exists.
|
|
150
|
+
* @param {V | null | VertexId} v1 - The parameter `v1` represents either an `V`
|
|
151
|
+
* object, `null`, or a `VertexId`. It is used to specify one of the vertices of the edge.
|
|
152
|
+
* @param {V | null | VertexId} v2 - The parameter `v2` represents either an `UndirectedVertex`
|
|
153
|
+
* object or a `VertexId` (identifier) of an undirected vertex.
|
|
154
|
+
* @returns an instance of `E` or `null`.
|
|
141
155
|
*/
|
|
142
156
|
UndirectedGraph.prototype.getEdge = function (v1, v2) {
|
|
143
157
|
var _a;
|
|
144
158
|
var edges = [];
|
|
145
159
|
if (v1 !== null && v2 !== null) {
|
|
146
|
-
var vertex1 = this.
|
|
147
|
-
var vertex2_1 = this.
|
|
160
|
+
var vertex1 = this._getVertex(v1);
|
|
161
|
+
var vertex2_1 = this._getVertex(v2);
|
|
148
162
|
if (vertex1 && vertex2_1) {
|
|
149
163
|
edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(function (e) { return e.vertices.includes(vertex2_1.id); });
|
|
150
164
|
}
|
|
@@ -152,8 +166,9 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
152
166
|
return edges ? edges[0] || null : null;
|
|
153
167
|
};
|
|
154
168
|
/**
|
|
155
|
-
* The function adds an edge to a graph by
|
|
156
|
-
* @param
|
|
169
|
+
* The function adds an undirected edge to a graph by updating the adjacency list.
|
|
170
|
+
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
|
|
171
|
+
* array of two vertices connected by the edge.
|
|
157
172
|
* @returns a boolean value.
|
|
158
173
|
*/
|
|
159
174
|
UndirectedGraph.prototype.addEdge = function (edge) {
|
|
@@ -161,7 +176,7 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
161
176
|
try {
|
|
162
177
|
for (var _b = __values(edge.vertices), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
163
178
|
var end = _c.value;
|
|
164
|
-
var endVertex = this.
|
|
179
|
+
var endVertex = this._getVertex(end);
|
|
165
180
|
if (endVertex === null)
|
|
166
181
|
return false;
|
|
167
182
|
if (endVertex) {
|
|
@@ -185,15 +200,19 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
185
200
|
return true;
|
|
186
201
|
};
|
|
187
202
|
/**
|
|
188
|
-
* The function removes an edge between two vertices in
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* @param {V | VertexId} v2 -
|
|
192
|
-
*
|
|
203
|
+
* The function removes an edge between two vertices in an undirected graph.
|
|
204
|
+
* @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
|
|
205
|
+
* a `VertexId`. It is used to specify one of the vertices of the edge that needs to be removed.
|
|
206
|
+
* @param {V | VertexId} v2 - The parameter `v2` represents either an instance of the
|
|
207
|
+
* `UndirectedVertex` class or a `VertexId`. It is used to identify the second vertex of the edge that needs to be
|
|
208
|
+
* removed.
|
|
209
|
+
* @returns The function `removeEdgeBetween` returns an `E` object if an edge is successfully removed
|
|
210
|
+
* between the two vertices `v1` and `v2`. If either `v1` or `v2` is not found in the graph, or if there is no edge
|
|
211
|
+
* between them, the function returns `null`.
|
|
193
212
|
*/
|
|
194
213
|
UndirectedGraph.prototype.removeEdgeBetween = function (v1, v2) {
|
|
195
|
-
var vertex1 = this.
|
|
196
|
-
var vertex2 = this.
|
|
214
|
+
var vertex1 = this._getVertex(v1);
|
|
215
|
+
var vertex2 = this._getVertex(v2);
|
|
197
216
|
if (!vertex1 || !vertex2) {
|
|
198
217
|
return null;
|
|
199
218
|
}
|
|
@@ -209,23 +228,23 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
209
228
|
return removed;
|
|
210
229
|
};
|
|
211
230
|
/**
|
|
212
|
-
* The removeEdge function removes an edge between two vertices in
|
|
213
|
-
* @param
|
|
214
|
-
*
|
|
231
|
+
* The removeEdge function removes an edge between two vertices in an undirected graph.
|
|
232
|
+
* @param edge - An object representing an undirected edge. It has a property called "vertices" which is an array
|
|
233
|
+
* containing the two vertices connected by the edge.
|
|
234
|
+
* @returns The method is returning an UndirectedEdge object or null.
|
|
215
235
|
*/
|
|
216
236
|
UndirectedGraph.prototype.removeEdge = function (edge) {
|
|
217
237
|
return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]);
|
|
218
238
|
};
|
|
219
239
|
/**
|
|
220
|
-
* The function
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* @returns
|
|
224
|
-
* edges that are incident to that vertex.
|
|
240
|
+
* The function "degreeOf" returns the degree of a given vertex in an undirected graph.
|
|
241
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
|
|
242
|
+
* `V`.
|
|
243
|
+
* @returns the degree of the vertex.
|
|
225
244
|
*/
|
|
226
245
|
UndirectedGraph.prototype.degreeOf = function (vertexOrId) {
|
|
227
246
|
var _a;
|
|
228
|
-
var vertex = this.
|
|
247
|
+
var vertex = this._getVertex(vertexOrId);
|
|
229
248
|
if (vertex) {
|
|
230
249
|
return ((_a = this._edges.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
231
250
|
}
|
|
@@ -234,14 +253,13 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
234
253
|
}
|
|
235
254
|
};
|
|
236
255
|
/**
|
|
237
|
-
* The function "edgesOf" returns an array of edges connected to a given vertex.
|
|
238
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or
|
|
239
|
-
*
|
|
240
|
-
* returns
|
|
241
|
-
* an empty array.
|
|
256
|
+
* The function "edgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
|
|
257
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
|
|
258
|
+
* `V`.
|
|
259
|
+
* @returns an array of UndirectedEdge objects.
|
|
242
260
|
*/
|
|
243
261
|
UndirectedGraph.prototype.edgesOf = function (vertexOrId) {
|
|
244
|
-
var vertex = this.
|
|
262
|
+
var vertex = this._getVertex(vertexOrId);
|
|
245
263
|
if (vertex) {
|
|
246
264
|
return this._edges.get(vertex) || [];
|
|
247
265
|
}
|
|
@@ -250,8 +268,8 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
250
268
|
}
|
|
251
269
|
};
|
|
252
270
|
/**
|
|
253
|
-
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
254
|
-
* @returns The method `edgeSet()` returns an array of
|
|
271
|
+
* The function "edgeSet" returns an array of unique undirected edges from a set of edges.
|
|
272
|
+
* @returns The method `edgeSet()` returns an array of `E` objects.
|
|
255
273
|
*/
|
|
256
274
|
UndirectedGraph.prototype.edgeSet = function () {
|
|
257
275
|
var edgeSet = new Set();
|
|
@@ -263,34 +281,34 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
263
281
|
return __spreadArray([], __read(edgeSet), false);
|
|
264
282
|
};
|
|
265
283
|
/**
|
|
266
|
-
* The function "getEdgesOf" returns an array of edges connected to a given vertex or vertex ID.
|
|
267
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can
|
|
268
|
-
*
|
|
269
|
-
* @returns an array of
|
|
284
|
+
* The function "getEdgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
|
|
285
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either an
|
|
286
|
+
* `V` object or a `VertexId`.
|
|
287
|
+
* @returns The function `getEdgesOf` returns an array of `E` objects.
|
|
270
288
|
*/
|
|
271
289
|
UndirectedGraph.prototype.getEdgesOf = function (vertexOrId) {
|
|
272
|
-
var vertex = this.
|
|
290
|
+
var vertex = this._getVertex(vertexOrId);
|
|
273
291
|
if (!vertex) {
|
|
274
292
|
return [];
|
|
275
293
|
}
|
|
276
294
|
return this._edges.get(vertex) || [];
|
|
277
295
|
};
|
|
278
296
|
/**
|
|
279
|
-
* The function
|
|
280
|
-
* @param {V | VertexId} vertexOrId - The
|
|
281
|
-
*
|
|
282
|
-
* @returns an array of
|
|
297
|
+
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in an undirected graph.
|
|
298
|
+
* @param {V | VertexId} vertexOrId - The `vertexOrId` parameter can be either an
|
|
299
|
+
* `V` object or a `VertexId`. It represents the vertex for which we want to find the neighbors.
|
|
300
|
+
* @returns an array of UndirectedVertex objects.
|
|
283
301
|
*/
|
|
284
302
|
UndirectedGraph.prototype.getNeighbors = function (vertexOrId) {
|
|
285
303
|
var e_2, _a;
|
|
286
304
|
var neighbors = [];
|
|
287
|
-
var vertex = this.
|
|
305
|
+
var vertex = this._getVertex(vertexOrId);
|
|
288
306
|
if (vertex) {
|
|
289
307
|
var neighborEdges = this.getEdgesOf(vertex);
|
|
290
308
|
try {
|
|
291
309
|
for (var neighborEdges_1 = __values(neighborEdges), neighborEdges_1_1 = neighborEdges_1.next(); !neighborEdges_1_1.done; neighborEdges_1_1 = neighborEdges_1.next()) {
|
|
292
310
|
var edge = neighborEdges_1_1.value;
|
|
293
|
-
var neighbor = this.
|
|
311
|
+
var neighbor = this._getVertex(edge.vertices.filter(function (e) { return e !== vertex.id; })[0]);
|
|
294
312
|
if (neighbor) {
|
|
295
313
|
neighbors.push(neighbor);
|
|
296
314
|
}
|
|
@@ -307,19 +325,19 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
307
325
|
return neighbors;
|
|
308
326
|
};
|
|
309
327
|
/**
|
|
310
|
-
* The function "getEndsOfEdge" returns the vertices
|
|
311
|
-
* the graph.
|
|
312
|
-
* @param
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
* `null`.
|
|
328
|
+
* The function "getEndsOfEdge" returns the two vertices that form the ends of a given undirected edge, or null if the
|
|
329
|
+
* edge does not exist in the graph.
|
|
330
|
+
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
|
|
331
|
+
* array containing two vertices that the edge connects.
|
|
332
|
+
* @returns The function `getEndsOfEdge` returns an array containing the two ends of the given `edge` if the edge
|
|
333
|
+
* exists in the graph. If the edge does not exist, it returns `null`.
|
|
316
334
|
*/
|
|
317
335
|
UndirectedGraph.prototype.getEndsOfEdge = function (edge) {
|
|
318
336
|
if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
|
|
319
337
|
return null;
|
|
320
338
|
}
|
|
321
|
-
var v1 = this.
|
|
322
|
-
var v2 = this.
|
|
339
|
+
var v1 = this._getVertex(edge.vertices[0]);
|
|
340
|
+
var v2 = this._getVertex(edge.vertices[1]);
|
|
323
341
|
if (v1 && v2) {
|
|
324
342
|
return [v1, v2];
|
|
325
343
|
}
|
|
@@ -327,6 +345,9 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
327
345
|
return null;
|
|
328
346
|
}
|
|
329
347
|
};
|
|
348
|
+
UndirectedGraph.prototype._setEdges = function (v) {
|
|
349
|
+
this._edges = v;
|
|
350
|
+
};
|
|
330
351
|
return UndirectedGraph;
|
|
331
352
|
}(abstract_graph_1.AbstractGraph));
|
|
332
353
|
exports.UndirectedGraph = UndirectedGraph;
|
|
@@ -9,11 +9,6 @@ export declare class CoordinateMap<V> extends Map<any, V> {
|
|
|
9
9
|
constructor(joint?: string);
|
|
10
10
|
protected _joint: string;
|
|
11
11
|
get joint(): string;
|
|
12
|
-
protected set joint(v: string);
|
|
13
|
-
/**
|
|
14
|
-
* 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.
|
|
15
|
-
*/
|
|
16
|
-
getJoint(): string;
|
|
17
12
|
/**
|
|
18
13
|
* The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
|
|
19
14
|
* key array with a specified delimiter.
|
|
@@ -46,4 +41,5 @@ export declare class CoordinateMap<V> extends Map<any, V> {
|
|
|
46
41
|
* `key` array joined together using the `_joint` property.
|
|
47
42
|
*/
|
|
48
43
|
delete(key: number[]): boolean;
|
|
44
|
+
protected _setJoint(v: string): void;
|
|
49
45
|
}
|
|
@@ -36,18 +36,9 @@ var CoordinateMap = /** @class */ (function (_super) {
|
|
|
36
36
|
get: function () {
|
|
37
37
|
return this._joint;
|
|
38
38
|
},
|
|
39
|
-
set: function (v) {
|
|
40
|
-
this._joint = v;
|
|
41
|
-
},
|
|
42
39
|
enumerable: false,
|
|
43
40
|
configurable: true
|
|
44
41
|
});
|
|
45
|
-
/**
|
|
46
|
-
* 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.
|
|
47
|
-
*/
|
|
48
|
-
CoordinateMap.prototype.getJoint = function () {
|
|
49
|
-
return this._joint;
|
|
50
|
-
};
|
|
51
42
|
/**
|
|
52
43
|
* The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
|
|
53
44
|
* key array with a specified delimiter.
|
|
@@ -88,6 +79,9 @@ var CoordinateMap = /** @class */ (function (_super) {
|
|
|
88
79
|
CoordinateMap.prototype.delete = function (key) {
|
|
89
80
|
return _super.prototype.delete.call(this, key.join(this._joint));
|
|
90
81
|
};
|
|
82
|
+
CoordinateMap.prototype._setJoint = function (v) {
|
|
83
|
+
this._joint = v;
|
|
84
|
+
};
|
|
91
85
|
return CoordinateMap;
|
|
92
86
|
}(Map));
|
|
93
87
|
exports.CoordinateMap = CoordinateMap;
|
|
@@ -5,15 +5,10 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
export declare class CoordinateSet extends Set {
|
|
8
|
+
export declare class CoordinateSet extends Set<any> {
|
|
9
9
|
constructor(joint?: string);
|
|
10
10
|
protected _joint: string;
|
|
11
11
|
get joint(): string;
|
|
12
|
-
protected set joint(v: string);
|
|
13
|
-
/**
|
|
14
|
-
* 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.
|
|
15
|
-
*/
|
|
16
|
-
getJoint(): string;
|
|
17
12
|
/**
|
|
18
13
|
* The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
|
|
19
14
|
* joining its elements with a specified separator.
|
|
@@ -38,4 +33,5 @@ export declare class CoordinateSet extends Set {
|
|
|
38
33
|
* `value` array joined together using the `_joint` property.
|
|
39
34
|
*/
|
|
40
35
|
delete(value: number[]): boolean;
|
|
36
|
+
protected _setJoint(v: string): void;
|
|
41
37
|
}
|
|
@@ -36,18 +36,9 @@ var CoordinateSet = /** @class */ (function (_super) {
|
|
|
36
36
|
get: function () {
|
|
37
37
|
return this._joint;
|
|
38
38
|
},
|
|
39
|
-
set: function (v) {
|
|
40
|
-
this._joint = v;
|
|
41
|
-
},
|
|
42
39
|
enumerable: false,
|
|
43
40
|
configurable: true
|
|
44
41
|
});
|
|
45
|
-
/**
|
|
46
|
-
* 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.
|
|
47
|
-
*/
|
|
48
|
-
CoordinateSet.prototype.getJoint = function () {
|
|
49
|
-
return this._joint;
|
|
50
|
-
};
|
|
51
42
|
/**
|
|
52
43
|
* The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
|
|
53
44
|
* joining its elements with a specified separator.
|
|
@@ -78,6 +69,9 @@ var CoordinateSet = /** @class */ (function (_super) {
|
|
|
78
69
|
CoordinateSet.prototype.delete = function (value) {
|
|
79
70
|
return _super.prototype.delete.call(this, value.join(this._joint));
|
|
80
71
|
};
|
|
72
|
+
CoordinateSet.prototype._setJoint = function (v) {
|
|
73
|
+
this._joint = v;
|
|
74
|
+
};
|
|
81
75
|
return CoordinateSet;
|
|
82
76
|
}(Set));
|
|
83
77
|
exports.CoordinateSet = CoordinateSet;
|