data-structure-typed 0.9.16 → 1.12.9

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.
Files changed (199) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.idea/data-structure-typed.iml +2 -0
  3. package/README.md +102 -1
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +57 -0
  5. package/dist/data-structures/binary-tree/avl-tree.js +57 -0
  6. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +27 -0
  7. package/dist/data-structures/binary-tree/binary-indexed-tree.js +27 -0
  8. package/dist/data-structures/binary-tree/binary-tree.d.ts +215 -9
  9. package/dist/data-structures/binary-tree/binary-tree.js +283 -15
  10. package/dist/data-structures/binary-tree/bst.d.ts +16 -0
  11. package/dist/data-structures/binary-tree/bst.js +12 -0
  12. package/dist/data-structures/binary-tree/segment-tree.d.ts +4 -0
  13. package/dist/data-structures/binary-tree/segment-tree.js +4 -0
  14. package/dist/data-structures/binary-tree/tree-multiset.d.ts +4 -0
  15. package/dist/data-structures/binary-tree/tree-multiset.js +4 -0
  16. package/dist/data-structures/graph/abstract-graph.d.ts +163 -13
  17. package/dist/data-structures/graph/abstract-graph.js +166 -12
  18. package/dist/data-structures/graph/directed-graph.d.ts +111 -1
  19. package/dist/data-structures/graph/directed-graph.js +122 -0
  20. package/dist/data-structures/graph/undirected-graph.d.ts +63 -0
  21. package/dist/data-structures/graph/undirected-graph.js +67 -0
  22. package/dist/data-structures/hash/coordinate-map.d.ts +32 -0
  23. package/dist/data-structures/hash/coordinate-map.js +32 -0
  24. package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
  25. package/dist/data-structures/hash/coordinate-set.js +25 -0
  26. package/dist/data-structures/heap/heap.d.ts +26 -31
  27. package/dist/data-structures/heap/heap.js +23 -32
  28. package/dist/data-structures/heap/max-heap.d.ts +6 -1
  29. package/dist/data-structures/heap/max-heap.js +6 -1
  30. package/dist/data-structures/heap/min-heap.d.ts +7 -1
  31. package/dist/data-structures/heap/min-heap.js +7 -1
  32. package/dist/data-structures/index.d.ts +0 -1
  33. package/dist/data-structures/index.js +0 -1
  34. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -6
  35. package/dist/data-structures/linked-list/doubly-linked-list.js +45 -8
  36. package/dist/data-structures/linked-list/singly-linked-list.d.ts +11 -8
  37. package/dist/data-structures/linked-list/singly-linked-list.js +4 -0
  38. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  39. package/dist/data-structures/matrix/matrix.js +11 -0
  40. package/dist/data-structures/matrix/matrix2d.d.ts +82 -2
  41. package/dist/data-structures/matrix/matrix2d.js +82 -2
  42. package/dist/data-structures/matrix/navigator.d.ts +32 -0
  43. package/dist/data-structures/matrix/navigator.js +28 -0
  44. package/dist/data-structures/matrix/vector2d.d.ts +139 -15
  45. package/dist/data-structures/matrix/vector2d.js +139 -15
  46. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +8 -0
  47. package/dist/data-structures/priority-queue/max-priority-queue.js +8 -0
  48. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +8 -0
  49. package/dist/data-structures/priority-queue/min-priority-queue.js +8 -0
  50. package/dist/data-structures/priority-queue/priority-queue.d.ts +130 -0
  51. package/dist/data-structures/priority-queue/priority-queue.js +126 -0
  52. package/dist/data-structures/queue/deque.d.ts +69 -0
  53. package/dist/data-structures/queue/deque.js +69 -0
  54. package/dist/data-structures/queue/queue.d.ts +30 -32
  55. package/dist/data-structures/queue/queue.js +30 -32
  56. package/dist/data-structures/stack/stack.d.ts +26 -31
  57. package/dist/data-structures/stack/stack.js +26 -31
  58. package/dist/data-structures/trie/trie.d.ts +26 -6
  59. package/dist/data-structures/trie/trie.js +26 -7
  60. package/dist/data-structures/types/avl-tree.d.ts +1 -1
  61. package/dist/data-structures/types/binary-tree.d.ts +1 -1
  62. package/dist/data-structures/types/index.d.ts +1 -1
  63. package/dist/data-structures/types/index.js +1 -1
  64. package/dist/data-structures/types/singly-linked-list.d.ts +1 -5
  65. package/dist/data-structures/types/tree-multiset.d.ts +1 -1
  66. package/dist/{data-structures → utils}/trampoline.d.ts +5 -7
  67. package/dist/utils/types/index.d.ts +1 -0
  68. package/dist/utils/types/index.js +17 -0
  69. package/dist/{data-structures → utils}/types/utils.d.ts +8 -0
  70. package/dist/{data-structures → utils}/types/utils.js +1 -0
  71. package/dist/utils/utils.d.ts +1 -1
  72. package/docs/.nojekyll +1 -0
  73. package/docs/assets/highlight.css +85 -0
  74. package/docs/assets/main.js +58 -0
  75. package/docs/assets/search.js +1 -0
  76. package/docs/assets/style.css +1367 -0
  77. package/docs/classes/AVLTree.html +2046 -0
  78. package/docs/classes/AVLTreeNode.html +423 -0
  79. package/docs/classes/AaTree.html +117 -0
  80. package/docs/classes/AbstractEdge.html +198 -0
  81. package/docs/classes/AbstractGraph.html +891 -0
  82. package/docs/classes/AbstractVertex.html +164 -0
  83. package/docs/classes/ArrayDeque.html +384 -0
  84. package/docs/classes/BST.html +1893 -0
  85. package/docs/classes/BSTNode.html +425 -0
  86. package/docs/classes/BTree.html +117 -0
  87. package/docs/classes/BinaryIndexedTree.html +244 -0
  88. package/docs/classes/BinaryTree.html +1754 -0
  89. package/docs/classes/BinaryTreeNode.html +396 -0
  90. package/docs/classes/Character.html +165 -0
  91. package/docs/classes/CoordinateMap.html +394 -0
  92. package/docs/classes/CoordinateSet.html +355 -0
  93. package/docs/classes/Deque.html +617 -0
  94. package/docs/classes/DirectedEdge.html +247 -0
  95. package/docs/classes/DirectedGraph.html +1207 -0
  96. package/docs/classes/DirectedVertex.html +154 -0
  97. package/docs/classes/DoublyLinkedList.html +619 -0
  98. package/docs/classes/DoublyLinkedListNode.html +160 -0
  99. package/docs/classes/Heap.html +315 -0
  100. package/docs/classes/Matrix2D.html +447 -0
  101. package/docs/classes/MatrixNTI2D.html +181 -0
  102. package/docs/classes/MaxHeap.html +325 -0
  103. package/docs/classes/MaxPriorityQueue.html +668 -0
  104. package/docs/classes/MinHeap.html +326 -0
  105. package/docs/classes/MinPriorityQueue.html +668 -0
  106. package/docs/classes/Navigator.html +285 -0
  107. package/docs/classes/ObjectDeque.html +289 -0
  108. package/docs/classes/PriorityQueue.html +643 -0
  109. package/docs/classes/Queue.html +337 -0
  110. package/docs/classes/RBTree.html +117 -0
  111. package/docs/classes/SegmentTree.html +234 -0
  112. package/docs/classes/SegmentTreeNode.html +302 -0
  113. package/docs/classes/SinglyLinkedList.html +1035 -0
  114. package/docs/classes/SinglyLinkedListNode.html +304 -0
  115. package/docs/classes/SplayTree.html +117 -0
  116. package/docs/classes/Stack.html +313 -0
  117. package/docs/classes/TreeMultiSet.html +1897 -0
  118. package/docs/classes/Trie.html +317 -0
  119. package/docs/classes/TrieNode.html +221 -0
  120. package/docs/classes/TwoThreeTree.html +117 -0
  121. package/docs/classes/UndirectedEdge.html +220 -0
  122. package/docs/classes/UndirectedGraph.html +1006 -0
  123. package/docs/classes/UndirectedVertex.html +154 -0
  124. package/docs/classes/Vector2D.html +746 -0
  125. package/docs/enums/CP.html +126 -0
  126. package/docs/enums/FamilyPosition.html +126 -0
  127. package/docs/enums/LoopType.html +119 -0
  128. package/docs/index.html +288 -0
  129. package/docs/modules.html +146 -0
  130. package/jest.config.js +5 -0
  131. package/package.json +19 -11
  132. package/rename_clear_files.sh +29 -0
  133. package/src/assets/complexities-diff.jpg +0 -0
  134. package/src/assets/data-structure-complexities.jpg +0 -0
  135. package/src/data-structures/binary-tree/avl-tree.ts +57 -0
  136. package/src/data-structures/binary-tree/binary-indexed-tree.ts +27 -0
  137. package/src/data-structures/binary-tree/binary-tree.ts +288 -18
  138. package/src/data-structures/binary-tree/bst.ts +16 -1
  139. package/src/data-structures/binary-tree/segment-tree.ts +5 -0
  140. package/src/data-structures/binary-tree/tree-multiset.ts +4 -0
  141. package/src/data-structures/diagrams/README.md +5 -7
  142. package/src/data-structures/graph/abstract-graph.ts +167 -15
  143. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  144. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  145. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  146. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  147. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  148. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  149. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  150. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  151. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  152. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  153. package/src/data-structures/graph/directed-graph.ts +127 -5
  154. package/src/data-structures/graph/undirected-graph.ts +67 -1
  155. package/src/data-structures/hash/coordinate-map.ts +32 -0
  156. package/src/data-structures/hash/coordinate-set.ts +25 -0
  157. package/src/data-structures/heap/heap.ts +27 -32
  158. package/src/data-structures/heap/max-heap.ts +6 -1
  159. package/src/data-structures/heap/min-heap.ts +7 -1
  160. package/src/data-structures/index.ts +0 -1
  161. package/src/data-structures/linked-list/doubly-linked-list.ts +49 -8
  162. package/src/data-structures/linked-list/singly-linked-list.ts +39 -8
  163. package/src/data-structures/matrix/matrix.ts +11 -0
  164. package/src/data-structures/matrix/matrix2d.ts +82 -2
  165. package/src/data-structures/matrix/navigator.ts +32 -0
  166. package/src/data-structures/matrix/vector2d.ts +139 -15
  167. package/src/data-structures/priority-queue/max-priority-queue.ts +8 -0
  168. package/src/data-structures/priority-queue/min-priority-queue.ts +8 -0
  169. package/src/data-structures/priority-queue/priority-queue.ts +130 -0
  170. package/src/data-structures/queue/deque.ts +69 -0
  171. package/src/data-structures/queue/queue.ts +30 -32
  172. package/src/data-structures/stack/stack.ts +26 -31
  173. package/src/data-structures/trie/trie.ts +26 -7
  174. package/src/data-structures/types/avl-tree.ts +1 -1
  175. package/src/data-structures/types/binary-tree.ts +1 -1
  176. package/src/data-structures/types/bst.ts +1 -1
  177. package/src/data-structures/types/index.ts +1 -1
  178. package/src/data-structures/types/navigator.ts +1 -0
  179. package/src/data-structures/types/singly-linked-list.ts +1 -15
  180. package/src/data-structures/types/tree-multiset.ts +1 -1
  181. package/src/{data-structures → utils}/trampoline.ts +6 -6
  182. package/src/utils/types/index.ts +1 -0
  183. package/src/{data-structures → utils}/types/utils.ts +7 -0
  184. package/src/utils/utils.ts +12 -2
  185. package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
  186. package/tests/unit/data-structures/graph/abstract-graph.ts +0 -0
  187. package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
  188. package/tests/unit/data-structures/graph/index.ts +3 -0
  189. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
  190. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
  191. package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
  192. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
  193. package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
  194. package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
  195. package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
  196. package/src/data-structures/graph/diagrams/edge-list.png +0 -0
  197. package/src/data-structures/graph/diagrams/max-flow.png +0 -0
  198. package/src/data-structures/graph/diagrams/mst.png +0 -0
  199. /package/dist/{data-structures → utils}/trampoline.js +0 -0
@@ -1,7 +1,7 @@
1
1
  import type { DijkstraResult, IGraph, VertexId } from '../types';
2
2
  export declare class AbstractVertex {
3
3
  constructor(id: VertexId);
4
- private _id;
4
+ protected _id: VertexId;
5
5
  get id(): VertexId;
6
6
  set id(v: VertexId);
7
7
  }
@@ -19,49 +19,179 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
19
19
  protected _vertices: Map<VertexId, V>;
20
20
  abstract removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
21
21
  abstract removeEdge(edge: E): E | null;
22
+ /**
23
+ * The function `getVertex` returns the vertex object associated with a given vertex ID or vertex object, or null if it
24
+ * does not exist.
25
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
26
+ * @returns The function `getVertex` returns the vertex object (`V`) corresponding to the given `vertexOrId` parameter.
27
+ * If the vertex is found in the `_vertices` map, it is returned. Otherwise, `null` is returned.
28
+ */
22
29
  getVertex(vertexOrId: VertexId | V): V | null;
30
+ /**
31
+ * The function `getVertexId` returns the id of a vertex, whether it is passed as an instance of `AbstractVertex` or as
32
+ * a `VertexId`.
33
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
34
+ * (`VertexId`).
35
+ * @returns the id of the vertex.
36
+ */
23
37
  getVertexId(vertexOrId: V | VertexId): VertexId;
38
+ /**
39
+ * The function checks if a vertex exists in a graph.
40
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
41
+ * (`VertexId`).
42
+ * @returns The method `containsVertex` returns a boolean value.
43
+ */
24
44
  containsVertex(vertexOrId: V | VertexId): boolean;
45
+ /**
46
+ * The function `vertexSet()` returns a map of vertices.
47
+ * @returns The method `vertexSet()` returns a map of vertex IDs to vertex objects.
48
+ */
25
49
  vertexSet(): Map<VertexId, V>;
26
50
  abstract getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
51
+ /**
52
+ * The addVertex function adds a new vertex to a graph if it does not already exist.
53
+ * @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
54
+ * @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
55
+ * false. Otherwise, it will add the newVertex to the graph and return true.
56
+ */
27
57
  addVertex(newVertex: V): boolean;
58
+ /**
59
+ * The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
60
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
61
+ * (`VertexId`).
62
+ * @returns The method `removeVertex` returns a boolean value.
63
+ */
28
64
  removeVertex(vertexOrId: V | VertexId): boolean;
65
+ /**
66
+ * The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
67
+ * @param {V[] | VertexId[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
68
+ * of vertex IDs (`VertexId[]`).
69
+ * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
70
+ * were removed.
71
+ */
29
72
  removeAllVertices(vertices: V[] | VertexId[]): boolean;
30
73
  abstract degreeOf(vertexOrId: V | VertexId): number;
31
74
  abstract edgeSet(): E[];
32
75
  abstract edgesOf(vertexOrId: V | VertexId): E[];
76
+ /**
77
+ * The function checks if there is an edge between two vertices in a graph.
78
+ * @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the identifier of
79
+ * a vertex in a graph, while V represents the type of the vertex itself.
80
+ * @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in an edge. It can be either a `VertexId`
81
+ * or a `V` type.
82
+ * @returns The function `containsEdge` returns a boolean value. It returns `true` if there is an edge between the
83
+ * vertices `v1` and `v2`, and `false` otherwise.
84
+ */
33
85
  containsEdge(v1: VertexId | V, v2: VertexId | V): boolean;
34
86
  abstract addEdge(edge: E): boolean;
87
+ /**
88
+ * The function sets the weight of an edge between two vertices in a graph.
89
+ * @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
90
+ * the source vertex of the edge.
91
+ * @param {VertexId | V} destOrId - The `destOrId` parameter represents the destination vertex of the edge. It can be
92
+ * either a `VertexId` or a vertex object `V`.
93
+ * @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrId)
94
+ * and the destination vertex (destOrId).
95
+ * @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
96
+ * the weight of the edge and return true. If the edge does not exist, the function will return false.
97
+ */
35
98
  setEdgeWeight(srcOrId: VertexId | V, destOrId: VertexId | V, weight: number): boolean;
36
99
  abstract getNeighbors(vertexOrId: V | VertexId): V[];
100
+ /**
101
+ * The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
102
+ * @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
103
+ * It is the starting vertex for finding paths.
104
+ * @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex that we
105
+ * want to find paths to from the starting vertex `v1`.
106
+ * @returns an array of arrays of vertices (V[][]). Each inner array represents a path between the given vertices (v1
107
+ * and v2).
108
+ */
37
109
  getAllPathsBetween(v1: V | VertexId, v2: V | VertexId): V[][];
110
+ /**
111
+ * The function calculates the sum of weights along a given path.
112
+ * @param {V[]} path - An array of vertices (V) representing a path in a graph.
113
+ * @returns The function `getPathSumWeight` returns the sum of the weights of the edges in the given path.
114
+ */
38
115
  getPathSumWeight(path: V[]): number;
116
+ /**
117
+ * The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
118
+ * weights or using a breadth-first search algorithm.
119
+ * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or vertex ID of the graph.
120
+ * @param {V | VertexId} v2 - The parameter `v2` represents the second vertex in the graph. It can be either a vertex
121
+ * object or a vertex ID.
122
+ * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
123
+ * If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
124
+ * the edges. If isWeight is set to false or not provided, the function will calculate the
125
+ * @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertices (`v1`
126
+ * and `v2`) in a graph. If the `isWeight` parameter is `true`, it calculates the minimum weight between the vertices.
127
+ * If `isWeight` is `false` or not provided, it calculates the minimum number of edges between the vertices. If the
128
+ * vertices are not
129
+ */
39
130
  getMinCostBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): number | null;
131
+ /**
132
+ * The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
133
+ * using a breadth-first search algorithm.
134
+ * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or its ID.
135
+ * @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex that we
136
+ * want to find the minimum path to from the source vertex `v1`.
137
+ * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
138
+ * minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
139
+ * to false, the function will use breadth-first search (BFS) to find the minimum path. If
140
+ * @returns The function `getMinPathBetween` returns an array of vertices (`V[]`) representing the minimum path between
141
+ * two vertices (`v1` and `v2`). If no path is found, it returns `null`.
142
+ */
40
143
  getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
41
144
  /**
42
145
  * Dijkstra algorithm time: O(VE) space: O(V + E)
43
- * @param src
44
- * @param dest
45
- * @param getMinDist
46
- * @param genPaths
146
+ * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
147
+ * a graph without using a heap data structure.
148
+ * @param {V | VertexId} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
149
+ * vertex object or a vertex ID.
150
+ * @param {V | VertexId | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
151
+ * parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
152
+ * identifier. If no destination is provided, the value is set to `null`.
153
+ * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
154
+ * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
155
+ * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
156
+ * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
157
+ * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
158
+ * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
159
+ * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<V>`.
47
160
  */
48
161
  dijkstraWithoutHeap(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
49
162
  /**
50
163
  * Dijkstra algorithm time: O(logVE) space: O(V + E)
51
- * @param src
52
- * @param dest
53
- * @param getMinDist
54
- * @param genPaths
164
+ * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
165
+ * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
166
+ * @param {V | VertexId} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
167
+ * start. It can be either a vertex object or a vertex ID.
168
+ * @param {V | VertexId | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
169
+ * vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
170
+ * will calculate the shortest paths to all other vertices from the source vertex.
171
+ * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
172
+ * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
173
+ * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
174
+ * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
175
+ * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
176
+ * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
177
+ * @returns The function `dijkstra` returns an object of type `DijkstraResult<V>`.
55
178
  */
56
179
  dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
57
180
  abstract getEndsOfEdge(edge: E): [V, V] | null;
58
181
  /**
59
182
  * BellmanFord time:O(VE) space:O(V)
60
183
  * one to rest pairs
61
- * @param src
62
- * @param scanNegativeCycle
63
- * @param getMin
64
- * @param genPath
184
+ * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
185
+ * all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
186
+ * @param {V | VertexId} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
187
+ * start calculating the shortest paths. It can be either a vertex object or a vertex ID.
188
+ * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
189
+ * @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
190
+ * calculate the minimum distance from the source vertex to all other vertices in the graph. If `getMin` is set to
191
+ * `true`, the algorithm will find the minimum distance and update the `min` variable with the minimum
192
+ * @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertices from the source
193
+ * vertex.
194
+ * @returns The function `bellmanFord` returns an object with the following properties:
65
195
  */
66
196
  bellmanFord(src: V | VertexId, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean): {
67
197
  hasNegativeCycle: boolean | undefined;
@@ -74,6 +204,12 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
74
204
  /**
75
205
  * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
76
206
  * all pairs
207
+ * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
208
+ * graph.
209
+ * @returns The function `floyd()` returns an object with two properties: `costs` and `predecessor`. The `costs`
210
+ * property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
211
+ * `predecessor` property is a 2D array of vertices (or `null`) representing the predecessor vertices in the shortest
212
+ * path between vertices in the
77
213
  */
78
214
  floyd(): {
79
215
  costs: number[][];
@@ -86,6 +222,20 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
86
222
  * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
87
223
  * Tarjan solve the bi-connected components of undirected graphs;
88
224
  * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
225
+ * The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
226
+ * strongly connected components (SCCs), and cycles in a graph.
227
+ * @param {boolean} [needArticulationPoints] - A boolean value indicating whether or not to calculate and return the
228
+ * articulation points in the graph. Articulation points are the vertices in a graph whose removal would increase the
229
+ * number of connected components in the graph.
230
+ * @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
231
+ * (edges whose removal would increase the number of connected components in the graph).
232
+ * @param {boolean} [needSCCs] - A boolean value indicating whether the Strongly Connected Components (SCCs) of the
233
+ * graph are needed. If set to true, the function will calculate and return the SCCs of the graph. If set to false, the
234
+ * SCCs will not be calculated or returned.
235
+ * @param {boolean} [needCycles] - A boolean flag indicating whether the algorithm should find cycles in the graph. If
236
+ * set to true, the algorithm will return a map of cycles, where the keys are the low values of the SCCs and the values
237
+ * are arrays of vertices that form cycles within the SCCs.
238
+ * @returns The function `tarjan` returns an object with the following properties:
89
239
  */
90
240
  tarjan(needArticulationPoints?: boolean, needBridges?: boolean, needSCCs?: boolean, needCycles?: boolean): {
91
241
  dfnMap: Map<V, number>;
@@ -37,6 +37,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.AbstractGraph = exports.AbstractEdge = exports.AbstractVertex = void 0;
40
+ /**
41
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
42
+ * @license MIT
43
+ */
40
44
  var utils_1 = require("../../utils");
41
45
  var priority_queue_1 = require("../priority-queue");
42
46
  var AbstractVertex = /** @class */ (function () {
@@ -96,19 +100,49 @@ var AbstractGraph = /** @class */ (function () {
96
100
  /**--- end find cycles --- */
97
101
  // Minimum Spanning Tree
98
102
  }
103
+ /**
104
+ * The function `getVertex` returns the vertex object associated with a given vertex ID or vertex object, or null if it
105
+ * does not exist.
106
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
107
+ * @returns The function `getVertex` returns the vertex object (`V`) corresponding to the given `vertexOrId` parameter.
108
+ * If the vertex is found in the `_vertices` map, it is returned. Otherwise, `null` is returned.
109
+ */
99
110
  AbstractGraph.prototype.getVertex = function (vertexOrId) {
100
111
  var vertexId = this.getVertexId(vertexOrId);
101
112
  return this._vertices.get(vertexId) || null;
102
113
  };
114
+ /**
115
+ * The function `getVertexId` returns the id of a vertex, whether it is passed as an instance of `AbstractVertex` or as
116
+ * a `VertexId`.
117
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
118
+ * (`VertexId`).
119
+ * @returns the id of the vertex.
120
+ */
103
121
  AbstractGraph.prototype.getVertexId = function (vertexOrId) {
104
122
  return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
105
123
  };
124
+ /**
125
+ * The function checks if a vertex exists in a graph.
126
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
127
+ * (`VertexId`).
128
+ * @returns The method `containsVertex` returns a boolean value.
129
+ */
106
130
  AbstractGraph.prototype.containsVertex = function (vertexOrId) {
107
131
  return this._vertices.has(this.getVertexId(vertexOrId));
108
132
  };
133
+ /**
134
+ * The function `vertexSet()` returns a map of vertices.
135
+ * @returns The method `vertexSet()` returns a map of vertex IDs to vertex objects.
136
+ */
109
137
  AbstractGraph.prototype.vertexSet = function () {
110
138
  return this._vertices;
111
139
  };
140
+ /**
141
+ * The addVertex function adds a new vertex to a graph if it does not already exist.
142
+ * @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
143
+ * @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
144
+ * false. Otherwise, it will add the newVertex to the graph and return true.
145
+ */
112
146
  AbstractGraph.prototype.addVertex = function (newVertex) {
113
147
  if (this.containsVertex(newVertex)) {
114
148
  return false;
@@ -116,10 +150,23 @@ var AbstractGraph = /** @class */ (function () {
116
150
  this._vertices.set(newVertex.id, newVertex);
117
151
  return true;
118
152
  };
153
+ /**
154
+ * The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
155
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
156
+ * (`VertexId`).
157
+ * @returns The method `removeVertex` returns a boolean value.
158
+ */
119
159
  AbstractGraph.prototype.removeVertex = function (vertexOrId) {
120
160
  var vertexId = this.getVertexId(vertexOrId);
121
161
  return this._vertices.delete(vertexId);
122
162
  };
163
+ /**
164
+ * The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
165
+ * @param {V[] | VertexId[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
166
+ * of vertex IDs (`VertexId[]`).
167
+ * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
168
+ * were removed.
169
+ */
123
170
  AbstractGraph.prototype.removeAllVertices = function (vertices) {
124
171
  var e_1, _a;
125
172
  var removed = [];
@@ -138,10 +185,30 @@ var AbstractGraph = /** @class */ (function () {
138
185
  }
139
186
  return removed.length > 0;
140
187
  };
188
+ /**
189
+ * The function checks if there is an edge between two vertices in a graph.
190
+ * @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the identifier of
191
+ * a vertex in a graph, while V represents the type of the vertex itself.
192
+ * @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in an edge. It can be either a `VertexId`
193
+ * or a `V` type.
194
+ * @returns The function `containsEdge` returns a boolean value. It returns `true` if there is an edge between the
195
+ * vertices `v1` and `v2`, and `false` otherwise.
196
+ */
141
197
  AbstractGraph.prototype.containsEdge = function (v1, v2) {
142
198
  var edge = this.getEdge(v1, v2);
143
199
  return !!edge;
144
200
  };
201
+ /**
202
+ * The function sets the weight of an edge between two vertices in a graph.
203
+ * @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
204
+ * the source vertex of the edge.
205
+ * @param {VertexId | V} destOrId - The `destOrId` parameter represents the destination vertex of the edge. It can be
206
+ * either a `VertexId` or a vertex object `V`.
207
+ * @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrId)
208
+ * and the destination vertex (destOrId).
209
+ * @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
210
+ * the weight of the edge and return true. If the edge does not exist, the function will return false.
211
+ */
145
212
  AbstractGraph.prototype.setEdgeWeight = function (srcOrId, destOrId, weight) {
146
213
  var edge = this.getEdge(srcOrId, destOrId);
147
214
  if (edge) {
@@ -152,6 +219,15 @@ var AbstractGraph = /** @class */ (function () {
152
219
  return false;
153
220
  }
154
221
  };
222
+ /**
223
+ * The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
224
+ * @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
225
+ * It is the starting vertex for finding paths.
226
+ * @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex that we
227
+ * want to find paths to from the starting vertex `v1`.
228
+ * @returns an array of arrays of vertices (V[][]). Each inner array represents a path between the given vertices (v1
229
+ * and v2).
230
+ */
155
231
  AbstractGraph.prototype.getAllPathsBetween = function (v1, v2) {
156
232
  var _this = this;
157
233
  var paths = [];
@@ -192,6 +268,11 @@ var AbstractGraph = /** @class */ (function () {
192
268
  dfs(vertex1, vertex2, new Map(), []);
193
269
  return paths;
194
270
  };
271
+ /**
272
+ * The function calculates the sum of weights along a given path.
273
+ * @param {V[]} path - An array of vertices (V) representing a path in a graph.
274
+ * @returns The function `getPathSumWeight` returns the sum of the weights of the edges in the given path.
275
+ */
195
276
  AbstractGraph.prototype.getPathSumWeight = function (path) {
196
277
  var _a;
197
278
  var sum = 0;
@@ -200,6 +281,20 @@ var AbstractGraph = /** @class */ (function () {
200
281
  }
201
282
  return sum;
202
283
  };
284
+ /**
285
+ * The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
286
+ * weights or using a breadth-first search algorithm.
287
+ * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or vertex ID of the graph.
288
+ * @param {V | VertexId} v2 - The parameter `v2` represents the second vertex in the graph. It can be either a vertex
289
+ * object or a vertex ID.
290
+ * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
291
+ * If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
292
+ * the edges. If isWeight is set to false or not provided, the function will calculate the
293
+ * @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertices (`v1`
294
+ * and `v2`) in a graph. If the `isWeight` parameter is `true`, it calculates the minimum weight between the vertices.
295
+ * If `isWeight` is `false` or not provided, it calculates the minimum number of edges between the vertices. If the
296
+ * vertices are not
297
+ */
203
298
  AbstractGraph.prototype.getMinCostBetween = function (v1, v2, isWeight) {
204
299
  var e_3, _a, e_4, _b;
205
300
  if (isWeight === undefined)
@@ -265,6 +360,18 @@ var AbstractGraph = /** @class */ (function () {
265
360
  return null;
266
361
  }
267
362
  };
363
+ /**
364
+ * The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
365
+ * using a breadth-first search algorithm.
366
+ * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or its ID.
367
+ * @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex that we
368
+ * want to find the minimum path to from the source vertex `v1`.
369
+ * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
370
+ * minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
371
+ * to false, the function will use breadth-first search (BFS) to find the minimum path. If
372
+ * @returns The function `getMinPathBetween` returns an array of vertices (`V[]`) representing the minimum path between
373
+ * two vertices (`v1` and `v2`). If no path is found, it returns `null`.
374
+ */
268
375
  AbstractGraph.prototype.getMinPathBetween = function (v1, v2, isWeight) {
269
376
  var e_5, _a;
270
377
  var _this = this;
@@ -339,10 +446,20 @@ var AbstractGraph = /** @class */ (function () {
339
446
  };
340
447
  /**
341
448
  * Dijkstra algorithm time: O(VE) space: O(V + E)
342
- * @param src
343
- * @param dest
344
- * @param getMinDist
345
- * @param genPaths
449
+ * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
450
+ * a graph without using a heap data structure.
451
+ * @param {V | VertexId} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
452
+ * vertex object or a vertex ID.
453
+ * @param {V | VertexId | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
454
+ * parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
455
+ * identifier. If no destination is provided, the value is set to `null`.
456
+ * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
457
+ * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
458
+ * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
459
+ * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
460
+ * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
461
+ * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
462
+ * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<V>`.
346
463
  */
347
464
  AbstractGraph.prototype.dijkstraWithoutHeap = function (src, dest, getMinDist, genPaths) {
348
465
  var e_7, _a, e_8, _b;
@@ -490,10 +607,20 @@ var AbstractGraph = /** @class */ (function () {
490
607
  };
491
608
  /**
492
609
  * Dijkstra algorithm time: O(logVE) space: O(V + E)
493
- * @param src
494
- * @param dest
495
- * @param getMinDist
496
- * @param genPaths
610
+ * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
611
+ * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
612
+ * @param {V | VertexId} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
613
+ * start. It can be either a vertex object or a vertex ID.
614
+ * @param {V | VertexId | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
615
+ * vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
616
+ * will calculate the shortest paths to all other vertices from the source vertex.
617
+ * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
618
+ * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
619
+ * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
620
+ * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
621
+ * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
622
+ * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
623
+ * @returns The function `dijkstra` returns an object of type `DijkstraResult<V>`.
497
624
  */
498
625
  AbstractGraph.prototype.dijkstra = function (src, dest, getMinDist, genPaths) {
499
626
  var e_11, _a, e_12, _b;
@@ -628,10 +755,17 @@ var AbstractGraph = /** @class */ (function () {
628
755
  /**
629
756
  * BellmanFord time:O(VE) space:O(V)
630
757
  * one to rest pairs
631
- * @param src
632
- * @param scanNegativeCycle
633
- * @param getMin
634
- * @param genPath
758
+ * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
759
+ * all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
760
+ * @param {V | VertexId} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
761
+ * start calculating the shortest paths. It can be either a vertex object or a vertex ID.
762
+ * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
763
+ * @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
764
+ * calculate the minimum distance from the source vertex to all other vertices in the graph. If `getMin` is set to
765
+ * `true`, the algorithm will find the minimum distance and update the `min` variable with the minimum
766
+ * @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertices from the source
767
+ * vertex.
768
+ * @returns The function `bellmanFord` returns an object with the following properties:
635
769
  */
636
770
  AbstractGraph.prototype.bellmanFord = function (src, scanNegativeCycle, getMin, genPath) {
637
771
  var e_14, _a;
@@ -732,6 +866,12 @@ var AbstractGraph = /** @class */ (function () {
732
866
  /**
733
867
  * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
734
868
  * all pairs
869
+ * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
870
+ * graph.
871
+ * @returns The function `floyd()` returns an object with two properties: `costs` and `predecessor`. The `costs`
872
+ * property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
873
+ * `predecessor` property is a 2D array of vertices (or `null`) representing the predecessor vertices in the shortest
874
+ * path between vertices in the
735
875
  */
736
876
  AbstractGraph.prototype.floyd = function () {
737
877
  var _a;
@@ -771,6 +911,20 @@ var AbstractGraph = /** @class */ (function () {
771
911
  * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
772
912
  * Tarjan solve the bi-connected components of undirected graphs;
773
913
  * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
914
+ * The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
915
+ * strongly connected components (SCCs), and cycles in a graph.
916
+ * @param {boolean} [needArticulationPoints] - A boolean value indicating whether or not to calculate and return the
917
+ * articulation points in the graph. Articulation points are the vertices in a graph whose removal would increase the
918
+ * number of connected components in the graph.
919
+ * @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
920
+ * (edges whose removal would increase the number of connected components in the graph).
921
+ * @param {boolean} [needSCCs] - A boolean value indicating whether the Strongly Connected Components (SCCs) of the
922
+ * graph are needed. If set to true, the function will calculate and return the SCCs of the graph. If set to false, the
923
+ * SCCs will not be calculated or returned.
924
+ * @param {boolean} [needCycles] - A boolean flag indicating whether the algorithm should find cycles in the graph. If
925
+ * set to true, the algorithm will return a map of cycles, where the keys are the low values of the SCCs and the values
926
+ * are arrays of vertices that form cycles within the SCCs.
927
+ * @returns The function `tarjan` returns an object with the following properties:
774
928
  */
775
929
  AbstractGraph.prototype.tarjan = function (needArticulationPoints, needBridges, needSCCs, needCycles) {
776
930
  // !! in undirected graph we will not let child visit parent when DFS