data-structure-typed 1.18.0 → 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 +8 -16
- package/dist/data-structures/binary-tree/binary-tree.d.ts +99 -98
- package/dist/data-structures/binary-tree/binary-tree.js +70 -65
- package/dist/data-structures/binary-tree/bst.d.ts +21 -21
- package/dist/data-structures/binary-tree/bst.js +15 -17
- 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/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 -58
- package/dist/data-structures/graph/abstract-graph.js +84 -68
- package/dist/data-structures/graph/directed-graph.d.ts +127 -96
- package/dist/data-structures/graph/directed-graph.js +161 -109
- package/dist/data-structures/graph/undirected-graph.d.ts +82 -59
- package/dist/data-structures/graph/undirected-graph.js +99 -72
- package/dist/data-structures/hash/coordinate-set.d.ts +1 -1
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/interfaces/abstract-graph.d.ts +22 -0
- package/dist/data-structures/interfaces/abstract-graph.js +2 -0
- package/dist/data-structures/interfaces/avl-tree.d.ts +1 -0
- package/dist/data-structures/interfaces/avl-tree.js +2 -0
- package/dist/data-structures/interfaces/binary-tree.d.ts +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 -1
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -1
- package/dist/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +4 -4
- package/dist/data-structures/queue/deque.d.ts +5 -5
- package/dist/data-structures/queue/deque.js +6 -6
- package/dist/data-structures/queue/queue.d.ts +1 -1
- package/dist/data-structures/stack/stack.d.ts +1 -1
- package/dist/data-structures/types/abstract-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/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 +288 -287
- package/docs/classes/AVLTreeNode.html +106 -63
- package/docs/classes/AaTree.html +14 -12
- package/docs/classes/AbstractEdge.html +68 -34
- package/docs/classes/AbstractGraph.html +219 -114
- package/docs/classes/AbstractVertex.html +71 -30
- package/docs/classes/ArrayDeque.html +27 -25
- package/docs/classes/BST.html +279 -273
- package/docs/classes/BSTNode.html +106 -57
- package/docs/classes/BTree.html +14 -12
- package/docs/classes/BinaryIndexedTree.html +22 -20
- package/docs/classes/BinaryTree.html +283 -277
- package/docs/classes/BinaryTreeNode.html +111 -63
- package/docs/classes/Character.html +17 -15
- package/docs/classes/CoordinateMap.html +22 -20
- package/docs/classes/CoordinateSet.html +23 -21
- package/docs/classes/Deque.html +47 -45
- package/docs/classes/DirectedEdge.html +74 -41
- package/docs/classes/DirectedGraph.html +444 -208
- package/docs/classes/DirectedVertex.html +63 -36
- package/docs/classes/DoublyLinkedList.html +52 -50
- package/docs/classes/DoublyLinkedListNode.html +24 -22
- package/docs/classes/HashTable.html +14 -12
- package/docs/classes/Heap.html +29 -27
- package/docs/classes/HeapItem.html +21 -19
- package/docs/classes/Matrix2D.html +29 -27
- package/docs/classes/MatrixNTI2D.html +17 -15
- package/docs/classes/MaxHeap.html +29 -27
- package/docs/classes/MaxPriorityQueue.html +67 -60
- package/docs/classes/MinHeap.html +29 -27
- package/docs/classes/MinPriorityQueue.html +67 -60
- package/docs/classes/Navigator.html +24 -22
- package/docs/classes/ObjectDeque.html +62 -50
- package/docs/classes/Pair.html +14 -12
- package/docs/classes/PriorityQueue.html +62 -55
- package/docs/classes/Queue.html +29 -27
- package/docs/classes/SegmentTree.html +30 -28
- package/docs/classes/SegmentTreeNode.html +33 -31
- package/docs/classes/SinglyLinkedList.html +49 -47
- package/docs/classes/SinglyLinkedListNode.html +21 -19
- package/docs/classes/SkipLinkedList.html +14 -12
- package/docs/classes/SplayTree.html +14 -12
- package/docs/classes/Stack.html +27 -25
- package/docs/classes/TreeMap.html +14 -12
- package/docs/classes/TreeMultiSet.html +277 -270
- package/docs/classes/TreeNode.html +29 -27
- package/docs/classes/TreeSet.html +14 -12
- package/docs/classes/Trie.html +26 -24
- package/docs/classes/TrieNode.html +24 -22
- package/docs/classes/TwoThreeTree.html +14 -12
- package/docs/classes/UndirectedEdge.html +70 -51
- package/docs/classes/UndirectedGraph.html +344 -161
- package/docs/classes/UndirectedVertex.html +63 -36
- package/docs/classes/Vector2D.html +41 -39
- package/docs/enums/CP.html +17 -15
- package/docs/enums/FamilyPosition.html +17 -15
- package/docs/enums/LoopType.html +16 -14
- package/docs/{interfaces/AVLTreeDeleted.html → enums/TopologicalProperty.html} +43 -43
- package/docs/index.html +195 -68
- package/docs/interfaces/{HeapOptions.html → IBinaryTree.html} +39 -32
- package/docs/interfaces/IBinaryTreeNode.html +383 -0
- package/docs/interfaces/IDirectedGraph.html +20 -18
- package/docs/interfaces/IGraph.html +118 -88
- package/docs/interfaces/{PriorityQueueOptions.html → IUNDirectedGraph.html} +22 -53
- package/docs/modules.html +25 -21
- package/docs/types/{ToThunkFn.html → AVLTreeDeleted.html} +27 -21
- package/docs/types/BSTComparator.html +14 -12
- package/docs/types/BSTDeletedResult.html +19 -17
- package/docs/types/BinaryTreeDeleted.html +19 -17
- package/docs/types/BinaryTreeNodeId.html +14 -12
- package/docs/types/BinaryTreeNodePropertyName.html +14 -12
- package/docs/types/DFSOrderPattern.html +14 -12
- package/docs/types/DijkstraResult.html +14 -12
- package/docs/types/Direction.html +14 -12
- package/docs/types/{TrlFn.html → EdgeId.html} +18 -29
- package/docs/types/{TrlAsyncFn.html → HeapOptions.html} +29 -19
- package/docs/types/NavigatorParams.html +164 -0
- package/docs/types/NodeOrPropertyName.html +14 -12
- package/docs/types/PriorityQueueComparator.html +14 -12
- package/docs/types/PriorityQueueDFSOrderPattern.html +14 -12
- package/docs/types/{SpecifyOptional.html → PriorityQueueOptions.html} +28 -19
- package/docs/types/RecursiveAVLTreeNode.html +135 -0
- package/docs/types/{Thunk.html → RecursiveBSTNode.html} +23 -24
- package/docs/types/RecursiveBinaryTreeNode.html +135 -0
- package/docs/types/ResultByProperty.html +17 -15
- package/docs/types/ResultsByProperty.html +17 -15
- package/docs/types/SegmentTreeNodeVal.html +14 -12
- package/docs/types/TopologicalStatus.html +14 -12
- package/docs/types/TreeMultiSetDeletedResult.html +19 -17
- package/docs/types/Turning.html +14 -12
- package/docs/types/VertexId.html +14 -12
- package/notes/note.md +8 -1
- package/package.json +10 -2
- package/docs/classes/RBTree.html +0 -153
- package/docs/interfaces/NavigatorParams.html +0 -200
|
@@ -1,106 +1,129 @@
|
|
|
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
35
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @param
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
49
|
+
*/
|
|
50
|
+
_createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
|
|
51
|
+
/**
|
|
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`.
|
|
40
59
|
*/
|
|
41
60
|
getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
|
|
42
61
|
/**
|
|
43
|
-
* The function adds an edge to a graph by
|
|
44
|
-
* @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.
|
|
45
65
|
* @returns a boolean value.
|
|
46
66
|
*/
|
|
47
67
|
addEdge(edge: E): boolean;
|
|
48
68
|
/**
|
|
49
|
-
* The function removes an edge between two vertices in
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* @param {V | VertexId} v2 -
|
|
53
|
-
*
|
|
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`.
|
|
54
78
|
*/
|
|
55
79
|
removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
|
|
56
80
|
/**
|
|
57
|
-
* The removeEdge function removes an edge between two vertices in
|
|
58
|
-
* @param
|
|
59
|
-
*
|
|
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.
|
|
60
85
|
*/
|
|
61
86
|
removeEdge(edge: E): E | null;
|
|
62
87
|
/**
|
|
63
|
-
* The function
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @returns
|
|
67
|
-
* 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.
|
|
68
92
|
*/
|
|
69
93
|
degreeOf(vertexOrId: VertexId | V): number;
|
|
70
94
|
/**
|
|
71
|
-
* The function "edgesOf" returns an array of edges connected to a given vertex.
|
|
72
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or
|
|
73
|
-
*
|
|
74
|
-
* returns
|
|
75
|
-
* 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.
|
|
76
99
|
*/
|
|
77
100
|
edgesOf(vertexOrId: VertexId | V): E[];
|
|
78
101
|
/**
|
|
79
|
-
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
80
|
-
* @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.
|
|
81
104
|
*/
|
|
82
105
|
edgeSet(): E[];
|
|
83
106
|
/**
|
|
84
|
-
* The function "getEdgesOf" returns an array of edges connected to a given vertex or vertex ID.
|
|
85
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can
|
|
86
|
-
*
|
|
87
|
-
* @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.
|
|
88
111
|
*/
|
|
89
112
|
getEdgesOf(vertexOrId: V | VertexId): E[];
|
|
90
113
|
/**
|
|
91
|
-
* The function
|
|
92
|
-
* @param {V | VertexId} vertexOrId - The
|
|
93
|
-
*
|
|
94
|
-
* @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.
|
|
95
118
|
*/
|
|
96
119
|
getNeighbors(vertexOrId: V | VertexId): V[];
|
|
97
120
|
/**
|
|
98
|
-
* The function "getEndsOfEdge" returns the vertices
|
|
99
|
-
* the graph.
|
|
100
|
-
* @param
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* `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`.
|
|
104
127
|
*/
|
|
105
128
|
getEndsOfEdge(edge: E): [V, V] | null;
|
|
106
129
|
protected _setEdges(v: Map<V, E[]>): void;
|
|
@@ -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
|
}
|
|
@@ -123,19 +123,42 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
123
123
|
configurable: true
|
|
124
124
|
});
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* @param
|
|
130
|
-
|
|
131
|
-
|
|
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
|
+
*/
|
|
131
|
+
UndirectedGraph.prototype._createVertex = function (id, val) {
|
|
132
|
+
return new this._vertexConstructor(id, val);
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
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`.
|
|
132
155
|
*/
|
|
133
156
|
UndirectedGraph.prototype.getEdge = function (v1, v2) {
|
|
134
157
|
var _a;
|
|
135
158
|
var edges = [];
|
|
136
159
|
if (v1 !== null && v2 !== null) {
|
|
137
|
-
var vertex1 = this.
|
|
138
|
-
var vertex2_1 = this.
|
|
160
|
+
var vertex1 = this._getVertex(v1);
|
|
161
|
+
var vertex2_1 = this._getVertex(v2);
|
|
139
162
|
if (vertex1 && vertex2_1) {
|
|
140
163
|
edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(function (e) { return e.vertices.includes(vertex2_1.id); });
|
|
141
164
|
}
|
|
@@ -143,8 +166,9 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
143
166
|
return edges ? edges[0] || null : null;
|
|
144
167
|
};
|
|
145
168
|
/**
|
|
146
|
-
* The function adds an edge to a graph by
|
|
147
|
-
* @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.
|
|
148
172
|
* @returns a boolean value.
|
|
149
173
|
*/
|
|
150
174
|
UndirectedGraph.prototype.addEdge = function (edge) {
|
|
@@ -152,7 +176,7 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
152
176
|
try {
|
|
153
177
|
for (var _b = __values(edge.vertices), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
154
178
|
var end = _c.value;
|
|
155
|
-
var endVertex = this.
|
|
179
|
+
var endVertex = this._getVertex(end);
|
|
156
180
|
if (endVertex === null)
|
|
157
181
|
return false;
|
|
158
182
|
if (endVertex) {
|
|
@@ -176,15 +200,19 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
176
200
|
return true;
|
|
177
201
|
};
|
|
178
202
|
/**
|
|
179
|
-
* The function removes an edge between two vertices in
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* @param {V | VertexId} v2 -
|
|
183
|
-
*
|
|
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`.
|
|
184
212
|
*/
|
|
185
213
|
UndirectedGraph.prototype.removeEdgeBetween = function (v1, v2) {
|
|
186
|
-
var vertex1 = this.
|
|
187
|
-
var vertex2 = this.
|
|
214
|
+
var vertex1 = this._getVertex(v1);
|
|
215
|
+
var vertex2 = this._getVertex(v2);
|
|
188
216
|
if (!vertex1 || !vertex2) {
|
|
189
217
|
return null;
|
|
190
218
|
}
|
|
@@ -200,23 +228,23 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
200
228
|
return removed;
|
|
201
229
|
};
|
|
202
230
|
/**
|
|
203
|
-
* The removeEdge function removes an edge between two vertices in
|
|
204
|
-
* @param
|
|
205
|
-
*
|
|
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.
|
|
206
235
|
*/
|
|
207
236
|
UndirectedGraph.prototype.removeEdge = function (edge) {
|
|
208
237
|
return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]);
|
|
209
238
|
};
|
|
210
239
|
/**
|
|
211
|
-
* The function
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* @returns
|
|
215
|
-
* 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.
|
|
216
244
|
*/
|
|
217
245
|
UndirectedGraph.prototype.degreeOf = function (vertexOrId) {
|
|
218
246
|
var _a;
|
|
219
|
-
var vertex = this.
|
|
247
|
+
var vertex = this._getVertex(vertexOrId);
|
|
220
248
|
if (vertex) {
|
|
221
249
|
return ((_a = this._edges.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
222
250
|
}
|
|
@@ -225,14 +253,13 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
225
253
|
}
|
|
226
254
|
};
|
|
227
255
|
/**
|
|
228
|
-
* The function "edgesOf" returns an array of edges connected to a given vertex.
|
|
229
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or
|
|
230
|
-
*
|
|
231
|
-
* returns
|
|
232
|
-
* 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.
|
|
233
260
|
*/
|
|
234
261
|
UndirectedGraph.prototype.edgesOf = function (vertexOrId) {
|
|
235
|
-
var vertex = this.
|
|
262
|
+
var vertex = this._getVertex(vertexOrId);
|
|
236
263
|
if (vertex) {
|
|
237
264
|
return this._edges.get(vertex) || [];
|
|
238
265
|
}
|
|
@@ -241,8 +268,8 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
241
268
|
}
|
|
242
269
|
};
|
|
243
270
|
/**
|
|
244
|
-
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
245
|
-
* @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.
|
|
246
273
|
*/
|
|
247
274
|
UndirectedGraph.prototype.edgeSet = function () {
|
|
248
275
|
var edgeSet = new Set();
|
|
@@ -254,34 +281,34 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
254
281
|
return __spreadArray([], __read(edgeSet), false);
|
|
255
282
|
};
|
|
256
283
|
/**
|
|
257
|
-
* The function "getEdgesOf" returns an array of edges connected to a given vertex or vertex ID.
|
|
258
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can
|
|
259
|
-
*
|
|
260
|
-
* @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.
|
|
261
288
|
*/
|
|
262
289
|
UndirectedGraph.prototype.getEdgesOf = function (vertexOrId) {
|
|
263
|
-
var vertex = this.
|
|
290
|
+
var vertex = this._getVertex(vertexOrId);
|
|
264
291
|
if (!vertex) {
|
|
265
292
|
return [];
|
|
266
293
|
}
|
|
267
294
|
return this._edges.get(vertex) || [];
|
|
268
295
|
};
|
|
269
296
|
/**
|
|
270
|
-
* The function
|
|
271
|
-
* @param {V | VertexId} vertexOrId - The
|
|
272
|
-
*
|
|
273
|
-
* @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.
|
|
274
301
|
*/
|
|
275
302
|
UndirectedGraph.prototype.getNeighbors = function (vertexOrId) {
|
|
276
303
|
var e_2, _a;
|
|
277
304
|
var neighbors = [];
|
|
278
|
-
var vertex = this.
|
|
305
|
+
var vertex = this._getVertex(vertexOrId);
|
|
279
306
|
if (vertex) {
|
|
280
307
|
var neighborEdges = this.getEdgesOf(vertex);
|
|
281
308
|
try {
|
|
282
309
|
for (var neighborEdges_1 = __values(neighborEdges), neighborEdges_1_1 = neighborEdges_1.next(); !neighborEdges_1_1.done; neighborEdges_1_1 = neighborEdges_1.next()) {
|
|
283
310
|
var edge = neighborEdges_1_1.value;
|
|
284
|
-
var neighbor = this.
|
|
311
|
+
var neighbor = this._getVertex(edge.vertices.filter(function (e) { return e !== vertex.id; })[0]);
|
|
285
312
|
if (neighbor) {
|
|
286
313
|
neighbors.push(neighbor);
|
|
287
314
|
}
|
|
@@ -298,19 +325,19 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
298
325
|
return neighbors;
|
|
299
326
|
};
|
|
300
327
|
/**
|
|
301
|
-
* The function "getEndsOfEdge" returns the vertices
|
|
302
|
-
* the graph.
|
|
303
|
-
* @param
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* `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`.
|
|
307
334
|
*/
|
|
308
335
|
UndirectedGraph.prototype.getEndsOfEdge = function (edge) {
|
|
309
336
|
if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
|
|
310
337
|
return null;
|
|
311
338
|
}
|
|
312
|
-
var v1 = this.
|
|
313
|
-
var v2 = this.
|
|
339
|
+
var v1 = this._getVertex(edge.vertices[0]);
|
|
340
|
+
var v2 = this._getVertex(edge.vertices[1]);
|
|
314
341
|
if (v1 && v2) {
|
|
315
342
|
return [v1, v2];
|
|
316
343
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
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;
|
|
@@ -25,4 +25,5 @@ __exportStar(require("./heap"), exports);
|
|
|
25
25
|
__exportStar(require("./priority-queue"), exports);
|
|
26
26
|
__exportStar(require("./matrix"), exports);
|
|
27
27
|
__exportStar(require("./trie"), exports);
|
|
28
|
+
__exportStar(require("./interfaces"), exports);
|
|
28
29
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { VertexId } from '../types';
|
|
2
|
+
export interface IGraph<V, E> {
|
|
3
|
+
hasVertex(vertexOrId: V | VertexId): boolean;
|
|
4
|
+
_getVertex(vertexOrId: VertexId | V): V | null;
|
|
5
|
+
_getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
6
|
+
createAddVertex(id: VertexId, val?: V): boolean;
|
|
7
|
+
addVertex(newVertex: V): boolean;
|
|
8
|
+
removeVertex(vertexOrId: V | VertexId): boolean;
|
|
9
|
+
removeAllVertices(vertices: V[] | VertexId[]): boolean;
|
|
10
|
+
degreeOf(vertexOrId: V | VertexId): number;
|
|
11
|
+
edgesOf(vertexOrId: V | VertexId): E[];
|
|
12
|
+
hasEdge(src: V | VertexId, dest: V | VertexId): boolean;
|
|
13
|
+
getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
14
|
+
edgeSet(): E[];
|
|
15
|
+
createAddEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E): boolean;
|
|
16
|
+
addEdge(edge: E): boolean;
|
|
17
|
+
removeEdgeBetween(src: V | VertexId, dest: V | VertexId): E | null;
|
|
18
|
+
removeEdge(edge: E): E | null;
|
|
19
|
+
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
|
|
20
|
+
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
|
|
21
|
+
getNeighbors(vertexOrId: V | VertexId): V[];
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BinaryTreeNodeId } from '../types';
|
|
2
|
+
import { FamilyPosition } from '../binary-tree';
|
|
3
|
+
export interface IBinaryTreeNode<T, FAMILY extends IBinaryTreeNode<T, FAMILY>> {
|
|
4
|
+
_createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null;
|
|
5
|
+
get id(): BinaryTreeNodeId;
|
|
6
|
+
set id(v: BinaryTreeNodeId);
|
|
7
|
+
get val(): T;
|
|
8
|
+
set val(v: T);
|
|
9
|
+
get left(): FAMILY | null | undefined;
|
|
10
|
+
set left(v: FAMILY | null | undefined);
|
|
11
|
+
get right(): FAMILY | null | undefined;
|
|
12
|
+
set right(v: FAMILY | null | undefined);
|
|
13
|
+
get parent(): FAMILY | null | undefined;
|
|
14
|
+
set parent(v: FAMILY | null | undefined);
|
|
15
|
+
get familyPosition(): FamilyPosition;
|
|
16
|
+
set familyPosition(v: FamilyPosition);
|
|
17
|
+
get count(): number;
|
|
18
|
+
set count(v: number);
|
|
19
|
+
get height(): number;
|
|
20
|
+
set height(v: number);
|
|
21
|
+
_createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null;
|
|
22
|
+
swapLocation(swapNode: FAMILY): FAMILY;
|
|
23
|
+
clone(): FAMILY | null;
|
|
24
|
+
}
|
|
25
|
+
export interface IBinaryTree<N extends IBinaryTreeNode<N['val'], N>> {
|
|
26
|
+
_createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { VertexId } from '../types';
|
|
2
|
+
export interface IDirectedGraph<V, E> {
|
|
3
|
+
incomingEdgesOf(vertex: V): E[];
|
|
4
|
+
outgoingEdgesOf(vertex: V): E[];
|
|
5
|
+
inDegreeOf(vertexOrId: V | VertexId): number;
|
|
6
|
+
outDegreeOf(vertexOrId: V | VertexId): number;
|
|
7
|
+
getEdgeSrc(e: E): V | null;
|
|
8
|
+
getEdgeDest(e: E): V | null;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|