data-structure-typed 1.18.7 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -419
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +198 -167
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +413 -398
- package/dist/data-structures/binary-tree/avl-tree.d.ts +24 -16
- package/dist/data-structures/binary-tree/avl-tree.js +23 -17
- package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
- package/dist/data-structures/binary-tree/binary-tree.js +12 -27
- package/dist/data-structures/binary-tree/bst.d.ts +66 -90
- package/dist/data-structures/binary-tree/bst.js +85 -163
- package/dist/data-structures/binary-tree/rb-tree.d.ts +6 -17
- package/dist/data-structures/binary-tree/rb-tree.js +5 -17
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +187 -18
- package/dist/data-structures/binary-tree/tree-multiset.js +716 -39
- package/dist/data-structures/graph/abstract-graph.d.ts +112 -52
- package/dist/data-structures/graph/abstract-graph.js +138 -72
- package/dist/data-structures/graph/directed-graph.d.ts +104 -101
- package/dist/data-structures/graph/directed-graph.js +134 -129
- package/dist/data-structures/graph/undirected-graph.d.ts +66 -65
- package/dist/data-structures/graph/undirected-graph.js +107 -106
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +12 -18
- package/dist/data-structures/interfaces/abstract-graph.d.ts +2 -4
- package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
- package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
- package/dist/data-structures/interfaces/bst.d.ts +4 -5
- package/dist/data-structures/interfaces/rb-tree.d.ts +2 -3
- package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
- package/dist/data-structures/tree/tree.d.ts +1 -4
- package/dist/data-structures/tree/tree.js +1 -12
- package/dist/data-structures/types/abstract-binary-tree.d.ts +10 -6
- package/dist/data-structures/types/abstract-binary-tree.js +9 -5
- package/dist/data-structures/types/avl-tree.d.ts +1 -1
- package/dist/data-structures/types/binary-tree.d.ts +1 -1
- package/dist/data-structures/types/bst.d.ts +1 -1
- package/dist/data-structures/types/bst.js +1 -1
- package/dist/data-structures/types/directed-graph.js +1 -1
- package/dist/data-structures/types/helpers.d.ts +1 -8
- package/dist/data-structures/types/rb-tree.d.ts +2 -0
- package/dist/data-structures/types/rb-tree.js +1 -1
- package/dist/data-structures/types/tree-multiset.d.ts +5 -5
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/index.d.ts +1 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/validate-type.d.ts +19 -0
- package/dist/utils/types/validate-type.js +2 -0
- package/dist/utils/utils.d.ts +2 -2
- package/dist/utils/utils.js +0 -62
- package/dist/utils/validate-type.d.ts +45 -0
- package/dist/utils/validate-type.js +58 -0
- package/package.json +5 -2
- package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
- package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
- package/backup/recursive-type/src/assets/logo.png +0 -0
- package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
- package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
- package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
- package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
- package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
- package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
- package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
- package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
- package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
- package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
- package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
- package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
- package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
- package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
- package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
- package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
- package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
- package/backup/recursive-type/src/data-structures/index.ts +0 -15
- package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
- package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
- package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
- package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
- package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
- package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
- package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
- package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
- package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
- package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
- package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
- package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
- package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
- package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
- package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
- package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
- package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
- package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
- package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
- package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
- package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
- package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
- package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
- package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
- package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
- package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
- package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
- package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
- package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
- package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
- package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
- package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
- package/backup/recursive-type/src/index.ts +0 -1
- package/backup/recursive-type/src/utils/index.ts +0 -2
- package/backup/recursive-type/src/utils/types/index.ts +0 -1
- package/backup/recursive-type/src/utils/types/utils.ts +0 -6
- package/backup/recursive-type/src/utils/utils.ts +0 -78
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -92
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1367
- package/docs/classes/AVLTree.html +0 -2451
- package/docs/classes/AVLTreeNode.html +0 -499
- package/docs/classes/AaTree.html +0 -172
- package/docs/classes/AbstractBinaryTree.html +0 -2118
- package/docs/classes/AbstractBinaryTreeNode.html +0 -524
- package/docs/classes/AbstractEdge.html +0 -295
- package/docs/classes/AbstractGraph.html +0 -1043
- package/docs/classes/AbstractVertex.html +0 -258
- package/docs/classes/ArrayDeque.html +0 -439
- package/docs/classes/BST.html +0 -2297
- package/docs/classes/BSTNode.html +0 -503
- package/docs/classes/BTree.html +0 -172
- package/docs/classes/BinaryIndexedTree.html +0 -341
- package/docs/classes/BinaryTree.html +0 -2133
- package/docs/classes/BinaryTreeNode.html +0 -501
- package/docs/classes/Character.html +0 -220
- package/docs/classes/CoordinateMap.html +0 -483
- package/docs/classes/CoordinateSet.html +0 -444
- package/docs/classes/Deque.html +0 -975
- package/docs/classes/DirectedEdge.html +0 -366
- package/docs/classes/DirectedGraph.html +0 -1443
- package/docs/classes/DirectedVertex.html +0 -254
- package/docs/classes/DoublyLinkedList.html +0 -968
- package/docs/classes/DoublyLinkedListNode.html +0 -297
- package/docs/classes/HashTable.html +0 -172
- package/docs/classes/Heap.html +0 -423
- package/docs/classes/HeapItem.html +0 -255
- package/docs/classes/Matrix2D.html +0 -502
- package/docs/classes/MatrixNTI2D.html +0 -240
- package/docs/classes/MaxHeap.html +0 -436
- package/docs/classes/MaxPriorityQueue.html +0 -836
- package/docs/classes/MinHeap.html +0 -437
- package/docs/classes/MinPriorityQueue.html +0 -838
- package/docs/classes/Navigator.html +0 -313
- package/docs/classes/ObjectDeque.html +0 -455
- package/docs/classes/Pair.html +0 -172
- package/docs/classes/PriorityQueue.html +0 -760
- package/docs/classes/Queue.html +0 -392
- package/docs/classes/RBTree.html +0 -2388
- package/docs/classes/RBTreeNode.html +0 -516
- package/docs/classes/SegmentTree.html +0 -434
- package/docs/classes/SegmentTreeNode.html +0 -357
- package/docs/classes/SinglyLinkedList.html +0 -788
- package/docs/classes/SinglyLinkedListNode.html +0 -270
- package/docs/classes/SkipLinkedList.html +0 -172
- package/docs/classes/SplayTree.html +0 -172
- package/docs/classes/Stack.html +0 -368
- package/docs/classes/TreeMap.html +0 -172
- package/docs/classes/TreeMultiSet.html +0 -2297
- package/docs/classes/TreeMultiSetNode.html +0 -499
- package/docs/classes/TreeNode.html +0 -343
- package/docs/classes/TreeSet.html +0 -172
- package/docs/classes/Trie.html +0 -372
- package/docs/classes/TrieNode.html +0 -280
- package/docs/classes/TwoThreeTree.html +0 -172
- package/docs/classes/UndirectedEdge.html +0 -337
- package/docs/classes/UndirectedGraph.html +0 -1210
- package/docs/classes/UndirectedVertex.html +0 -254
- package/docs/classes/Vector2D.html +0 -805
- package/docs/enums/CP.html +0 -181
- package/docs/enums/FamilyPosition.html +0 -181
- package/docs/enums/LoopType.html +0 -182
- package/docs/enums/RBColor.html +0 -174
- package/docs/enums/TopologicalProperty.html +0 -181
- package/docs/index.html +0 -645
- package/docs/interfaces/IAVLTree.html +0 -1378
- package/docs/interfaces/IAVLTreeNode.html +0 -405
- package/docs/interfaces/IAbstractBinaryTree.html +0 -1124
- package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -384
- package/docs/interfaces/IAbstractGraph.html +0 -433
- package/docs/interfaces/IBST.html +0 -1271
- package/docs/interfaces/IBSTNode.html +0 -408
- package/docs/interfaces/IDirectedGraph.html +0 -572
- package/docs/interfaces/IUNDirectedGraph.html +0 -465
- package/docs/modules.html +0 -262
- package/docs/types/AVLTreeOptions.html +0 -150
- package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -152
- package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -152
- package/docs/types/AbstractBinaryTreeOptions.html +0 -156
- package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -152
- package/docs/types/BSTComparator.html +0 -162
- package/docs/types/BSTOptions.html +0 -152
- package/docs/types/BinaryTreeDeletedResult.html +0 -159
- package/docs/types/BinaryTreeNodeId.html +0 -147
- package/docs/types/BinaryTreeNodePropertyName.html +0 -147
- package/docs/types/BinaryTreeOptions.html +0 -150
- package/docs/types/DFSOrderPattern.html +0 -147
- package/docs/types/DijkstraResult.html +0 -167
- package/docs/types/Direction.html +0 -147
- package/docs/types/EdgeId.html +0 -147
- package/docs/types/HeapOptions.html +0 -168
- package/docs/types/IdObject.html +0 -157
- package/docs/types/KeyValObject.html +0 -152
- package/docs/types/NavigatorParams.html +0 -181
- package/docs/types/NodeOrPropertyName.html +0 -147
- package/docs/types/PriorityQueueComparator.html +0 -167
- package/docs/types/PriorityQueueDFSOrderPattern.html +0 -147
- package/docs/types/PriorityQueueOptions.html +0 -161
- package/docs/types/RBTreeOptions.html +0 -150
- package/docs/types/RecursiveAVLTreeNode.html +0 -152
- package/docs/types/RecursiveBSTNode.html +0 -152
- package/docs/types/RecursiveBinaryTreeNode.html +0 -152
- package/docs/types/RecursiveTreeMultiSetNode.html +0 -152
- package/docs/types/SegmentTreeNodeVal.html +0 -147
- package/docs/types/TopologicalStatus.html +0 -147
- package/docs/types/TreeMultiSetOptions.html +0 -152
- package/docs/types/Turning.html +0 -147
- package/docs/types/VertexId.html +0 -147
- package/notes/bst.test.ts +0 -181
- package/notes/note.md +0 -34
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { DijkstraResult, VertexId } from '../types';
|
|
2
2
|
import { IAbstractGraph } from '../interfaces';
|
|
3
3
|
export declare abstract class AbstractVertex<T = number> {
|
|
4
|
+
/**
|
|
5
|
+
* The function is a protected constructor that takes an id and an optional value as parameters.
|
|
6
|
+
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
|
|
7
|
+
* used to uniquely identify the vertex object.
|
|
8
|
+
* @param {T} [val] - The parameter "val" is an optional parameter of type T. It is used to assign a value to the
|
|
9
|
+
* vertex. If no value is provided, it will be set to undefined.
|
|
10
|
+
*/
|
|
4
11
|
protected constructor(id: VertexId, val?: T);
|
|
5
12
|
private _id;
|
|
6
13
|
get id(): VertexId;
|
|
@@ -10,6 +17,15 @@ export declare abstract class AbstractVertex<T = number> {
|
|
|
10
17
|
set val(value: T | undefined);
|
|
11
18
|
}
|
|
12
19
|
export declare abstract class AbstractEdge<T = number> {
|
|
20
|
+
/**
|
|
21
|
+
* The above function is a protected constructor that initializes the weight, value, and hash code properties of an
|
|
22
|
+
* object.
|
|
23
|
+
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
|
|
24
|
+
* a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
|
|
25
|
+
* will be assigned.
|
|
26
|
+
* @param {T} [val] - The `val` parameter is of type `T`, which means it can be any type. It is an optional parameter,
|
|
27
|
+
* meaning it can be omitted when creating an instance of the class.
|
|
28
|
+
*/
|
|
13
29
|
protected constructor(weight?: number, val?: T);
|
|
14
30
|
private _val;
|
|
15
31
|
get val(): T | undefined;
|
|
@@ -19,6 +35,15 @@ export declare abstract class AbstractEdge<T = number> {
|
|
|
19
35
|
set weight(v: number);
|
|
20
36
|
protected _hashCode: string;
|
|
21
37
|
get hashCode(): string;
|
|
38
|
+
/**
|
|
39
|
+
* 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.
|
|
40
|
+
* 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.
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* The function sets the value of the _hashCode property to the provided string.
|
|
44
|
+
* @param {string} v - The parameter "v" is of type string and represents the value that will be assigned to the
|
|
45
|
+
* "_hashCode" property.
|
|
46
|
+
*/
|
|
22
47
|
protected _setHashCode(v: string): void;
|
|
23
48
|
}
|
|
24
49
|
export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E extends AbstractEdge<any>> implements IAbstractGraph<V, E> {
|
|
@@ -41,22 +66,35 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
41
66
|
*/
|
|
42
67
|
abstract createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
|
|
43
68
|
abstract removeEdge(edge: E): E | null;
|
|
69
|
+
abstract getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
70
|
+
abstract degreeOf(vertexOrId: V | VertexId): number;
|
|
71
|
+
abstract edgeSet(): E[];
|
|
72
|
+
abstract edgesOf(vertexOrId: V | VertexId): E[];
|
|
73
|
+
abstract getNeighbors(vertexOrId: V | VertexId): V[];
|
|
74
|
+
abstract getEndsOfEdge(edge: E): [V, V] | null;
|
|
75
|
+
protected abstract _addEdgeOnly(edge: E): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* The function "getVertex" returns the vertex with the specified ID or null if it doesn't exist.
|
|
78
|
+
* @param {VertexId} vertexId - The `vertexId` parameter is the identifier of the vertex that you want to retrieve from
|
|
79
|
+
* the `_vertices` map.
|
|
80
|
+
* @returns The method `getVertex` returns the vertex with the specified `vertexId` if it exists in the `_vertices`
|
|
81
|
+
* map. If the vertex does not exist, it returns `null`.
|
|
82
|
+
*/
|
|
44
83
|
getVertex(vertexId: VertexId): V | null;
|
|
45
84
|
/**
|
|
46
85
|
* The function checks if a vertex exists in a graph.
|
|
47
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can
|
|
86
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
48
87
|
* (`VertexId`).
|
|
49
|
-
* @returns
|
|
88
|
+
* @returns a boolean value.
|
|
50
89
|
*/
|
|
51
90
|
hasVertex(vertexOrId: V | VertexId): boolean;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
addVertex(newVertex: V): boolean;
|
|
91
|
+
addVertex(vertex: V): boolean;
|
|
92
|
+
addVertex(id: VertexId, val?: V['val']): boolean;
|
|
55
93
|
/**
|
|
56
94
|
* The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
57
95
|
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
58
96
|
* (`VertexId`).
|
|
59
|
-
* @returns The method
|
|
97
|
+
* @returns The method is returning a boolean value.
|
|
60
98
|
*/
|
|
61
99
|
removeVertex(vertexOrId: V | VertexId): boolean;
|
|
62
100
|
/**
|
|
@@ -67,21 +105,17 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
67
105
|
* were removed.
|
|
68
106
|
*/
|
|
69
107
|
removeAllVertices(vertices: V[] | VertexId[]): boolean;
|
|
70
|
-
abstract degreeOf(vertexOrId: V | VertexId): number;
|
|
71
|
-
abstract edgeSet(): E[];
|
|
72
|
-
abstract edgesOf(vertexOrId: V | VertexId): E[];
|
|
73
108
|
/**
|
|
74
|
-
* The function checks if there is an edge between two vertices
|
|
75
|
-
* @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the
|
|
76
|
-
* a vertex in a graph, while V represents the type of the vertex itself.
|
|
77
|
-
* @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in
|
|
78
|
-
* or a `V` type.
|
|
79
|
-
* @returns
|
|
80
|
-
* vertices `v1` and `v2`, and `false` otherwise.
|
|
109
|
+
* The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
|
|
110
|
+
* @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the unique
|
|
111
|
+
* identifier of a vertex in a graph, while V represents the type of the vertex object itself.
|
|
112
|
+
* @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
|
|
113
|
+
* `VertexId` or a `V` type, which represents the type of the vertex.
|
|
114
|
+
* @returns A boolean value is being returned.
|
|
81
115
|
*/
|
|
82
116
|
hasEdge(v1: VertexId | V, v2: VertexId | V): boolean;
|
|
83
|
-
|
|
84
|
-
|
|
117
|
+
addEdge(edge: E): boolean;
|
|
118
|
+
addEdge(src: V | VertexId, dest: V | VertexId, weight?: number, val?: E['val']): boolean;
|
|
85
119
|
/**
|
|
86
120
|
* The function sets the weight of an edge between two vertices in a graph.
|
|
87
121
|
* @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
|
|
@@ -94,15 +128,12 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
94
128
|
* the weight of the edge and return true. If the edge does not exist, the function will return false.
|
|
95
129
|
*/
|
|
96
130
|
setEdgeWeight(srcOrId: VertexId | V, destOrId: VertexId | V, weight: number): boolean;
|
|
97
|
-
abstract getNeighbors(vertexOrId: V | VertexId): V[];
|
|
98
131
|
/**
|
|
99
132
|
* The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
|
|
100
133
|
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
|
|
101
134
|
* It is the starting vertex for finding paths.
|
|
102
|
-
* @param {V | VertexId} v2 - The parameter `v2` represents
|
|
103
|
-
*
|
|
104
|
-
* @returns an array of arrays of vertices (V[][]). Each inner array represents a path between the given vertices (v1
|
|
105
|
-
* and v2).
|
|
135
|
+
* @param {V | VertexId} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
|
|
136
|
+
* @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`V[][]`).
|
|
106
137
|
*/
|
|
107
138
|
getAllPathsBetween(v1: V | VertexId, v2: V | VertexId): V[][];
|
|
108
139
|
/**
|
|
@@ -114,32 +145,37 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
114
145
|
/**
|
|
115
146
|
* The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
|
|
116
147
|
* weights or using a breadth-first search algorithm.
|
|
117
|
-
* @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or
|
|
118
|
-
* @param {V | VertexId} v2 - The parameter `v2` represents the
|
|
119
|
-
*
|
|
148
|
+
* @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or its ID.
|
|
149
|
+
* @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
|
|
150
|
+
* you want to find the minimum cost or weight from the source vertex `v1`.
|
|
120
151
|
* @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
|
|
121
152
|
* If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
|
|
122
153
|
* the edges. If isWeight is set to false or not provided, the function will calculate the
|
|
123
154
|
* @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertices (`v1`
|
|
124
|
-
* and `v2`)
|
|
125
|
-
* If `isWeight` is `false` or not provided, it
|
|
126
|
-
*
|
|
155
|
+
* and `v2`). If the `isWeight` parameter is `true`, it calculates the minimum weight among all paths between the
|
|
156
|
+
* vertices. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
|
|
157
|
+
* minimum number of
|
|
127
158
|
*/
|
|
128
159
|
getMinCostBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): number | null;
|
|
129
160
|
/**
|
|
130
161
|
* The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
|
|
131
162
|
* using a breadth-first search algorithm.
|
|
132
|
-
* @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex
|
|
133
|
-
*
|
|
134
|
-
*
|
|
163
|
+
* @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
|
|
164
|
+
* object (`V`) or a vertex ID (`VertexId`).
|
|
165
|
+
* @param {V | VertexId} v2 - V | VertexId - The second vertex or vertex ID between which we want to find the minimum
|
|
166
|
+
* path.
|
|
135
167
|
* @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
|
|
136
168
|
* minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
|
|
137
|
-
* to false, the function will use breadth-first search (BFS) to find the minimum path.
|
|
169
|
+
* to false, the function will use breadth-first search (BFS) to find the minimum path.
|
|
138
170
|
* @returns The function `getMinPathBetween` returns an array of vertices (`V[]`) representing the minimum path between
|
|
139
|
-
* two vertices (`v1` and `v2`). If no path
|
|
171
|
+
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `null`.
|
|
140
172
|
*/
|
|
141
173
|
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
|
|
142
174
|
/**
|
|
175
|
+
* Dijkstra algorithm time: O(VE) space: O(V + E)
|
|
176
|
+
* /
|
|
177
|
+
|
|
178
|
+
/**
|
|
143
179
|
* Dijkstra algorithm time: O(VE) space: O(V + E)
|
|
144
180
|
* The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
|
|
145
181
|
* a graph without using a heap data structure.
|
|
@@ -159,6 +195,14 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
159
195
|
dijkstraWithoutHeap(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
|
|
160
196
|
/**
|
|
161
197
|
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
198
|
+
*
|
|
199
|
+
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
|
|
200
|
+
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
|
|
201
|
+
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
|
|
202
|
+
*
|
|
203
|
+
* /
|
|
204
|
+
|
|
205
|
+
/**
|
|
162
206
|
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
163
207
|
* The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
|
|
164
208
|
* optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
|
|
@@ -177,11 +221,30 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
177
221
|
*/
|
|
178
222
|
dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
|
|
179
223
|
/**
|
|
224
|
+
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
225
|
+
* /
|
|
226
|
+
|
|
227
|
+
/**
|
|
180
228
|
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
181
229
|
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
182
230
|
*/
|
|
183
|
-
abstract getEndsOfEdge(edge: E): [V, V] | null;
|
|
184
231
|
/**
|
|
232
|
+
* BellmanFord time:O(VE) space:O(V)
|
|
233
|
+
* one to rest pairs
|
|
234
|
+
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
235
|
+
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
236
|
+
*/
|
|
237
|
+
/**
|
|
238
|
+
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
239
|
+
* all pairs
|
|
240
|
+
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
241
|
+
*/
|
|
242
|
+
/**
|
|
243
|
+
* BellmanFord time:O(VE) space:O(V)
|
|
244
|
+
* one to rest pairs
|
|
245
|
+
* /
|
|
246
|
+
|
|
247
|
+
/**
|
|
185
248
|
* BellmanFord time:O(VE) space:O(V)
|
|
186
249
|
* one to rest pairs
|
|
187
250
|
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
@@ -206,11 +269,11 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
206
269
|
minPath: V[];
|
|
207
270
|
};
|
|
208
271
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
|
|
213
|
-
|
|
272
|
+
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
273
|
+
* all pairs
|
|
274
|
+
* /
|
|
275
|
+
|
|
276
|
+
/**
|
|
214
277
|
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
215
278
|
* all pairs
|
|
216
279
|
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
@@ -226,6 +289,14 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
226
289
|
predecessor: (V | null)[][];
|
|
227
290
|
};
|
|
228
291
|
/**
|
|
292
|
+
* Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
|
|
293
|
+
* Tarjan can find cycles in directed or undirected graph
|
|
294
|
+
* Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
|
|
295
|
+
* Tarjan solve the bi-connected components of undirected graphs;
|
|
296
|
+
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
297
|
+
* /
|
|
298
|
+
|
|
299
|
+
/**
|
|
229
300
|
* Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
|
|
230
301
|
* Tarjan can find cycles in directed or undirected graph
|
|
231
302
|
* Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
|
|
@@ -254,19 +325,8 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
|
|
|
254
325
|
SCCs: Map<number, V[]>;
|
|
255
326
|
cycles: Map<number, V[]>;
|
|
256
327
|
};
|
|
257
|
-
|
|
258
|
-
* BellmanFord time:O(VE) space:O(V)
|
|
259
|
-
* one to rest pairs
|
|
260
|
-
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
261
|
-
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
262
|
-
*/
|
|
328
|
+
protected _addVertexOnly(newVertex: V): boolean;
|
|
263
329
|
protected _getVertex(vertexOrId: VertexId | V): V | null;
|
|
264
|
-
/**
|
|
265
|
-
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
266
|
-
* all pairs
|
|
267
|
-
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
268
|
-
*/
|
|
269
330
|
protected _getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
270
|
-
/**--- start find cycles --- */
|
|
271
331
|
protected _setVertices(value: Map<VertexId, V>): void;
|
|
272
332
|
}
|