min-heap-typed 1.39.4 → 1.39.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.
@@ -16,20 +16,20 @@ export declare abstract class AbstractVertex<V = any> {
16
16
  get val(): V | undefined;
17
17
  set val(value: V | undefined);
18
18
  }
19
- export declare abstract class AbstractEdge<V = any> {
19
+ export declare abstract class AbstractEdge<VO = any> {
20
20
  /**
21
21
  * The above function is a protected constructor that initializes the weight, value, and hash code properties of an
22
22
  * object.
23
23
  * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
24
24
  * a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
25
25
  * will be assigned.
26
- * @param {V} [val] - The `val` parameter is of type `V`, which means it can be any type. It is an optional parameter,
26
+ * @param {VO} [val] - The `val` parameter is of type `VO`, which means it can be any type. It is an optional parameter,
27
27
  * meaning it can be omitted when creating an instance of the class.
28
28
  */
29
- protected constructor(weight?: number, val?: V);
29
+ protected constructor(weight?: number, val?: VO);
30
30
  private _val;
31
- get val(): V | undefined;
32
- set val(value: V | undefined);
31
+ get val(): VO | undefined;
32
+ set val(value: VO | undefined);
33
33
  private _weight;
34
34
  get weight(): number;
35
35
  set weight(v: number);
@@ -46,16 +46,16 @@ export declare abstract class AbstractEdge<V = any> {
46
46
  */
47
47
  protected _setHashCode(v: string): void;
48
48
  }
49
- export declare abstract class AbstractGraph<V extends AbstractVertex<any> = AbstractVertex<any>, E extends AbstractEdge<any> = AbstractEdge<any>> implements IGraph<V, E> {
49
+ export declare abstract class AbstractGraph<V = any, E = any, VO extends AbstractVertex<V> = AbstractVertex<V>, EO extends AbstractEdge<E> = AbstractEdge<E>> implements IGraph<V, E, VO, EO> {
50
50
  private _vertices;
51
- get vertices(): Map<VertexKey, V>;
51
+ get vertices(): Map<VertexKey, VO>;
52
52
  /**
53
53
  * 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.
54
54
  * 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.
55
55
  * @param key
56
56
  * @param val
57
57
  */
58
- abstract createVertex(key: VertexKey, val?: V): V;
58
+ abstract createVertex(key: VertexKey, val?: V): VO;
59
59
  /**
60
60
  * 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.
61
61
  * 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.
@@ -64,14 +64,14 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
64
64
  * @param weight
65
65
  * @param val
66
66
  */
67
- abstract createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): E;
68
- abstract deleteEdge(edge: E): E | null;
69
- abstract getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
70
- abstract degreeOf(vertexOrKey: V | VertexKey): number;
71
- abstract edgeSet(): E[];
72
- abstract edgesOf(vertexOrKey: V | VertexKey): E[];
73
- abstract getNeighbors(vertexOrKey: V | VertexKey): V[];
74
- abstract getEndsOfEdge(edge: E): [V, V] | null;
67
+ abstract createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): EO;
68
+ abstract deleteEdge(edge: EO): EO | null;
69
+ abstract getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | null;
70
+ abstract degreeOf(vertexOrKey: VO | VertexKey): number;
71
+ abstract edgeSet(): EO[];
72
+ abstract edgesOf(vertexOrKey: VO | VertexKey): EO[];
73
+ abstract getNeighbors(vertexOrKey: VO | VertexKey): VO[];
74
+ abstract getEndsOfEdge(edge: EO): [VO, VO] | null;
75
75
  /**
76
76
  * The function "getVertex" returns the vertex with the specified ID or null if it doesn't exist.
77
77
  * @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
@@ -79,73 +79,73 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
79
79
  * @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertices`
80
80
  * map. If the vertex does not exist, it returns `null`.
81
81
  */
82
- getVertex(vertexKey: VertexKey): V | null;
82
+ getVertex(vertexKey: VertexKey): VO | null;
83
83
  /**
84
84
  * The function checks if a vertex exists in a graph.
85
- * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
85
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
86
86
  * (`VertexKey`).
87
87
  * @returns a boolean value.
88
88
  */
89
- hasVertex(vertexOrKey: V | VertexKey): boolean;
90
- addVertex(vertex: V): boolean;
91
- addVertex(key: VertexKey, val?: V['val']): boolean;
89
+ hasVertex(vertexOrKey: VO | VertexKey): boolean;
90
+ addVertex(vertex: VO): boolean;
91
+ addVertex(key: VertexKey, val?: V): boolean;
92
92
  /**
93
93
  * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
94
- * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
94
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
95
95
  * (`VertexKey`).
96
96
  * @returns The method is returning a boolean value.
97
97
  */
98
- deleteVertex(vertexOrKey: V | VertexKey): boolean;
98
+ deleteVertex(vertexOrKey: VO | VertexKey): boolean;
99
99
  /**
100
100
  * The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
101
- * @param {V[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
101
+ * @param {VO[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`VO[]`) or an array
102
102
  * of vertex IDs (`VertexKey[]`).
103
103
  * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
104
104
  * were removed.
105
105
  */
106
- removeManyVertices(vertices: V[] | VertexKey[]): boolean;
106
+ removeManyVertices(vertices: VO[] | VertexKey[]): boolean;
107
107
  /**
108
108
  * The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
109
- * @param {VertexKey | V} v1 - The parameter v1 can be either a VertexKey or a V. A VertexKey represents the unique
110
- * identifier of a vertex in a graph, while V represents the type of the vertex object itself.
111
- * @param {VertexKey | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
112
- * `VertexKey` or a `V` type, which represents the type of the vertex.
109
+ * @param {VertexKey | VO} v1 - The parameter v1 can be either a VertexKey or a VO. A VertexKey represents the unique
110
+ * identifier of a vertex in a graph, while VO represents the type of the vertex object itself.
111
+ * @param {VertexKey | VO} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
112
+ * `VertexKey` or a `VO` type, which represents the type of the vertex.
113
113
  * @returns A boolean value is being returned.
114
114
  */
115
- hasEdge(v1: VertexKey | V, v2: VertexKey | V): boolean;
116
- addEdge(edge: E): boolean;
117
- addEdge(src: V | VertexKey, dest: V | VertexKey, weight?: number, val?: E['val']): boolean;
115
+ hasEdge(v1: VertexKey | VO, v2: VertexKey | VO): boolean;
116
+ addEdge(edge: EO): boolean;
117
+ addEdge(src: VO | VertexKey, dest: VO | VertexKey, weight?: number, val?: E): boolean;
118
118
  /**
119
119
  * The function sets the weight of an edge between two vertices in a graph.
120
- * @param {VertexKey | V} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `V` object. It represents
120
+ * @param {VertexKey | VO} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `VO` object. It represents
121
121
  * the source vertex of the edge.
122
- * @param {VertexKey | V} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
123
- * either a `VertexKey` or a vertex object `V`.
122
+ * @param {VertexKey | VO} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
123
+ * either a `VertexKey` or a vertex object `VO`.
124
124
  * @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrKey)
125
125
  * and the destination vertex (destOrKey).
126
126
  * @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
127
127
  * the weight of the edge and return true. If the edge does not exist, the function will return false.
128
128
  */
129
- setEdgeWeight(srcOrKey: VertexKey | V, destOrKey: VertexKey | V, weight: number): boolean;
129
+ setEdgeWeight(srcOrKey: VertexKey | VO, destOrKey: VertexKey | VO, weight: number): boolean;
130
130
  /**
131
131
  * The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
132
- * @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
132
+ * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
133
133
  * It is the starting vertex for finding paths.
134
- * @param {V | VertexKey} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
135
- * @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`V[][]`).
134
+ * @param {VO | VertexKey} v2 - The parameter `v2` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
135
+ * @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`VO[][]`).
136
136
  */
137
- getAllPathsBetween(v1: V | VertexKey, v2: V | VertexKey): V[][];
137
+ getAllPathsBetween(v1: VO | VertexKey, v2: VO | VertexKey): VO[][];
138
138
  /**
139
139
  * The function calculates the sum of weights along a given path.
140
- * @param {V[]} path - An array of vertices (V) representing a path in a graph.
140
+ * @param {VO[]} path - An array of vertices (VO) representing a path in a graph.
141
141
  * @returns The function `getPathSumWeight` returns the sum of the weights of the edges in the given path.
142
142
  */
143
- getPathSumWeight(path: V[]): number;
143
+ getPathSumWeight(path: VO[]): number;
144
144
  /**
145
145
  * The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
146
146
  * weights or using a breadth-first search algorithm.
147
- * @param {V | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
148
- * @param {V | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
147
+ * @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
148
+ * @param {VO | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
149
149
  * you want to find the minimum cost or weight from the source vertex `v1`.
150
150
  * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
151
151
  * If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
@@ -155,32 +155,32 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
155
155
  * vertices. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
156
156
  * minimum number of
157
157
  */
158
- getMinCostBetween(v1: V | VertexKey, v2: V | VertexKey, isWeight?: boolean): number | null;
158
+ getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number | null;
159
159
  /**
160
160
  * The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
161
161
  * using a breadth-first search algorithm.
162
- * @param {V | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
163
- * object (`V`) or a vertex ID (`VertexKey`).
164
- * @param {V | VertexKey} v2 - V | VertexKey - The second vertex or vertex ID between which we want to find the minimum
162
+ * @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
163
+ * object (`VO`) or a vertex ID (`VertexKey`).
164
+ * @param {VO | VertexKey} v2 - VO | VertexKey - The second vertex or vertex ID between which we want to find the minimum
165
165
  * path.
166
166
  * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
167
167
  * minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
168
168
  * to false, the function will use breadth-first search (BFS) to find the minimum path.
169
- * @returns The function `getMinPathBetween` returns an array of vertices (`V[]`) representing the minimum path between
169
+ * @returns The function `getMinPathBetween` returns an array of vertices (`VO[]`) representing the minimum path between
170
170
  * two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `null`.
171
171
  */
172
- getMinPathBetween(v1: V | VertexKey, v2: V | VertexKey, isWeight?: boolean): V[] | null;
172
+ getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): VO[] | null;
173
173
  /**
174
- * Dijkstra algorithm time: O(VE) space: O(V + E)
174
+ * Dijkstra algorithm time: O(VE) space: O(VO + EO)
175
175
  * /
176
176
 
177
177
  /**
178
- * Dijkstra algorithm time: O(VE) space: O(V + E)
178
+ * Dijkstra algorithm time: O(VE) space: O(VO + EO)
179
179
  * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
180
180
  * a graph without using a heap data structure.
181
- * @param {V | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
181
+ * @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
182
182
  * vertex object or a vertex ID.
183
- * @param {V | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
183
+ * @param {VO | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
184
184
  * parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
185
185
  * identifier. If no destination is provided, the value is set to `null`.
186
186
  * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
@@ -189,15 +189,15 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
189
189
  * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
190
190
  * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
191
191
  * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
192
- * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<V>`.
192
+ * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
193
193
  */
194
- dijkstraWithoutHeap(src: V | VertexKey, dest?: V | VertexKey | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
194
+ dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
195
195
  /**
196
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
196
+ * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
197
197
  *
198
198
  * 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.
199
199
  * 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.
200
- * 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.
200
+ * 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(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
201
201
  *
202
202
  * /
203
203
 
@@ -205,9 +205,9 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
205
205
  * 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.
206
206
  * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
207
207
  * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
208
- * @param {V | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
208
+ * @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
209
209
  * start. It can be either a vertex object or a vertex ID.
210
- * @param {V | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
210
+ * @param {VO | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
211
211
  * vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
212
212
  * will calculate the shortest paths to all other vertices from the source vertex.
213
213
  * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
@@ -216,21 +216,21 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
216
216
  * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
217
217
  * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
218
218
  * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
219
- * @returns The function `dijkstra` returns an object of type `DijkstraResult<V>`.
219
+ * @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
220
220
  */
221
- dijkstra(src: V | VertexKey, dest?: V | VertexKey | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
221
+ dijkstra(src: VO | VertexKey, dest?: VO | VertexKey | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
222
222
  /**
223
- * BellmanFord time:O(VE) space:O(V)
223
+ * BellmanFord time:O(VE) space:O(VO)
224
224
  * one to rest pairs
225
225
  * /
226
226
 
227
227
  /**
228
- * BellmanFord time:O(VE) space:O(V)
228
+ * BellmanFord time:O(VE) space:O(VO)
229
229
  * one to rest pairs
230
230
  * 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.
231
231
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
232
232
  * all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
233
- * @param {V | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
233
+ * @param {VO | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
234
234
  * start calculating the shortest paths. It can be either a vertex object or a vertex ID.
235
235
  * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
236
236
  * @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
@@ -240,40 +240,40 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
240
240
  * vertex.
241
241
  * @returns The function `bellmanFord` returns an object with the following properties:
242
242
  */
243
- bellmanFord(src: V | VertexKey, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean): {
243
+ bellmanFord(src: VO | VertexKey, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean): {
244
244
  hasNegativeCycle: boolean | undefined;
245
- distMap: Map<V, number>;
246
- preMap: Map<V, V>;
247
- paths: V[][];
245
+ distMap: Map<VO, number>;
246
+ preMap: Map<VO, VO>;
247
+ paths: VO[][];
248
248
  min: number;
249
- minPath: V[];
249
+ minPath: VO[];
250
250
  };
251
251
  /**
252
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
252
+ * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
253
253
  * /
254
254
 
255
255
  /**
256
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
256
+ * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
257
257
  * 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.
258
258
  */
259
259
  /**
260
- * BellmanFord time:O(VE) space:O(V)
260
+ * BellmanFord time:O(VE) space:O(VO)
261
261
  * one to rest pairs
262
262
  * 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.
263
263
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
264
264
  */
265
265
  /**
266
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
266
+ * Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
267
267
  * all pairs
268
268
  * 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.
269
269
  */
270
270
  /**
271
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
271
+ * Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
272
272
  * all pairs
273
273
  * /
274
274
 
275
275
  /**
276
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
276
+ * Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
277
277
  * all pairs
278
278
  * 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.
279
279
  * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
@@ -285,7 +285,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
285
285
  */
286
286
  floyd(): {
287
287
  costs: number[][];
288
- predecessor: (V | null)[][];
288
+ predecessor: (VO | null)[][];
289
289
  };
290
290
  /**
291
291
  * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
@@ -317,16 +317,16 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
317
317
  * @returns The function `tarjan` returns an object with the following properties:
318
318
  */
319
319
  tarjan(needArticulationPoints?: boolean, needBridges?: boolean, needSCCs?: boolean, needCycles?: boolean): {
320
- dfnMap: Map<V, number>;
321
- lowMap: Map<V, number>;
322
- bridges: E[];
323
- articulationPoints: V[];
324
- SCCs: Map<number, V[]>;
325
- cycles: Map<number, V[]>;
320
+ dfnMap: Map<VO, number>;
321
+ lowMap: Map<VO, number>;
322
+ bridges: EO[];
323
+ articulationPoints: VO[];
324
+ SCCs: Map<number, VO[]>;
325
+ cycles: Map<number, VO[]>;
326
326
  };
327
- protected abstract _addEdgeOnly(edge: E): boolean;
328
- protected _addVertexOnly(newVertex: V): boolean;
329
- protected _getVertex(vertexOrKey: VertexKey | V): V | null;
330
- protected _getVertexKey(vertexOrKey: V | VertexKey): VertexKey;
331
- protected _setVertices(value: Map<VertexKey, V>): void;
327
+ protected abstract _addEdgeOnly(edge: EO): boolean;
328
+ protected _addVertexOnly(newVertex: VO): boolean;
329
+ protected _getVertex(vertexOrKey: VertexKey | VO): VO | null;
330
+ protected _getVertexKey(vertexOrKey: VO | VertexKey): VertexKey;
331
+ protected _setVertices(value: Map<VertexKey, VO>): void;
332
332
  }
@@ -44,7 +44,7 @@ class AbstractEdge {
44
44
  * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
45
45
  * a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
46
46
  * will be assigned.
47
- * @param {V} [val] - The `val` parameter is of type `V`, which means it can be any type. It is an optional parameter,
47
+ * @param {VO} [val] - The `val` parameter is of type `VO`, which means it can be any type. It is an optional parameter,
48
48
  * meaning it can be omitted when creating an instance of the class.
49
49
  */
50
50
  constructor(weight, val) {
@@ -100,7 +100,7 @@ class AbstractGraph {
100
100
  }
101
101
  /**
102
102
  * The function checks if a vertex exists in a graph.
103
- * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
103
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
104
104
  * (`VertexKey`).
105
105
  * @returns a boolean value.
106
106
  */
@@ -118,7 +118,7 @@ class AbstractGraph {
118
118
  }
119
119
  /**
120
120
  * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
121
- * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
121
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
122
122
  * (`VertexKey`).
123
123
  * @returns The method is returning a boolean value.
124
124
  */
@@ -128,7 +128,7 @@ class AbstractGraph {
128
128
  }
129
129
  /**
130
130
  * The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
131
- * @param {V[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
131
+ * @param {VO[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`VO[]`) or an array
132
132
  * of vertex IDs (`VertexKey[]`).
133
133
  * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
134
134
  * were removed.
@@ -142,10 +142,10 @@ class AbstractGraph {
142
142
  }
143
143
  /**
144
144
  * The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
145
- * @param {VertexKey | V} v1 - The parameter v1 can be either a VertexKey or a V. A VertexKey represents the unique
146
- * identifier of a vertex in a graph, while V represents the type of the vertex object itself.
147
- * @param {VertexKey | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
148
- * `VertexKey` or a `V` type, which represents the type of the vertex.
145
+ * @param {VertexKey | VO} v1 - The parameter v1 can be either a VertexKey or a VO. A VertexKey represents the unique
146
+ * identifier of a vertex in a graph, while VO represents the type of the vertex object itself.
147
+ * @param {VertexKey | VO} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
148
+ * `VertexKey` or a `VO` type, which represents the type of the vertex.
149
149
  * @returns A boolean value is being returned.
150
150
  */
151
151
  hasEdge(v1, v2) {
@@ -174,10 +174,10 @@ class AbstractGraph {
174
174
  }
175
175
  /**
176
176
  * The function sets the weight of an edge between two vertices in a graph.
177
- * @param {VertexKey | V} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `V` object. It represents
177
+ * @param {VertexKey | VO} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `VO` object. It represents
178
178
  * the source vertex of the edge.
179
- * @param {VertexKey | V} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
180
- * either a `VertexKey` or a vertex object `V`.
179
+ * @param {VertexKey | VO} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
180
+ * either a `VertexKey` or a vertex object `VO`.
181
181
  * @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrKey)
182
182
  * and the destination vertex (destOrKey).
183
183
  * @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
@@ -195,10 +195,10 @@ class AbstractGraph {
195
195
  }
196
196
  /**
197
197
  * The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
198
- * @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
198
+ * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
199
199
  * It is the starting vertex for finding paths.
200
- * @param {V | VertexKey} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
201
- * @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`V[][]`).
200
+ * @param {VO | VertexKey} v2 - The parameter `v2` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
201
+ * @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`VO[][]`).
202
202
  */
203
203
  getAllPathsBetween(v1, v2) {
204
204
  const paths = [];
@@ -227,7 +227,7 @@ class AbstractGraph {
227
227
  }
228
228
  /**
229
229
  * The function calculates the sum of weights along a given path.
230
- * @param {V[]} path - An array of vertices (V) representing a path in a graph.
230
+ * @param {VO[]} path - An array of vertices (VO) representing a path in a graph.
231
231
  * @returns The function `getPathSumWeight` returns the sum of the weights of the edges in the given path.
232
232
  */
233
233
  getPathSumWeight(path) {
@@ -241,8 +241,8 @@ class AbstractGraph {
241
241
  /**
242
242
  * The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
243
243
  * weights or using a breadth-first search algorithm.
244
- * @param {V | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
245
- * @param {V | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
244
+ * @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
245
+ * @param {VO | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
246
246
  * you want to find the minimum cost or weight from the source vertex `v1`.
247
247
  * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
248
248
  * If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
@@ -299,14 +299,14 @@ class AbstractGraph {
299
299
  /**
300
300
  * The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
301
301
  * using a breadth-first search algorithm.
302
- * @param {V | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
303
- * object (`V`) or a vertex ID (`VertexKey`).
304
- * @param {V | VertexKey} v2 - V | VertexKey - The second vertex or vertex ID between which we want to find the minimum
302
+ * @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
303
+ * object (`VO`) or a vertex ID (`VertexKey`).
304
+ * @param {VO | VertexKey} v2 - VO | VertexKey - The second vertex or vertex ID between which we want to find the minimum
305
305
  * path.
306
306
  * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
307
307
  * minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
308
308
  * to false, the function will use breadth-first search (BFS) to find the minimum path.
309
- * @returns The function `getMinPathBetween` returns an array of vertices (`V[]`) representing the minimum path between
309
+ * @returns The function `getMinPathBetween` returns an array of vertices (`VO[]`) representing the minimum path between
310
310
  * two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `null`.
311
311
  */
312
312
  getMinPathBetween(v1, v2, isWeight) {
@@ -356,16 +356,16 @@ class AbstractGraph {
356
356
  }
357
357
  }
358
358
  /**
359
- * Dijkstra algorithm time: O(VE) space: O(V + E)
359
+ * Dijkstra algorithm time: O(VE) space: O(VO + EO)
360
360
  * /
361
361
 
362
362
  /**
363
- * Dijkstra algorithm time: O(VE) space: O(V + E)
363
+ * Dijkstra algorithm time: O(VE) space: O(VO + EO)
364
364
  * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
365
365
  * a graph without using a heap data structure.
366
- * @param {V | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
366
+ * @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
367
367
  * vertex object or a vertex ID.
368
- * @param {V | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
368
+ * @param {VO | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
369
369
  * parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
370
370
  * identifier. If no destination is provided, the value is set to `null`.
371
371
  * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
@@ -374,7 +374,7 @@ class AbstractGraph {
374
374
  * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
375
375
  * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
376
376
  * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
377
- * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<V>`.
377
+ * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
378
378
  */
379
379
  dijkstraWithoutHeap(src, dest, getMinDist, genPaths) {
380
380
  if (getMinDist === undefined)
@@ -479,11 +479,11 @@ class AbstractGraph {
479
479
  return { distMap, preMap, seen, paths, minDist, minPath };
480
480
  }
481
481
  /**
482
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
482
+ * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
483
483
  *
484
484
  * 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.
485
485
  * 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.
486
- * 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.
486
+ * 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(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
487
487
  *
488
488
  * /
489
489
 
@@ -491,9 +491,9 @@ class AbstractGraph {
491
491
  * 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.
492
492
  * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
493
493
  * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
494
- * @param {V | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
494
+ * @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
495
495
  * start. It can be either a vertex object or a vertex ID.
496
- * @param {V | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
496
+ * @param {VO | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
497
497
  * vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
498
498
  * will calculate the shortest paths to all other vertices from the source vertex.
499
499
  * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
@@ -502,7 +502,7 @@ class AbstractGraph {
502
502
  * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
503
503
  * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
504
504
  * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
505
- * @returns The function `dijkstra` returns an object of type `DijkstraResult<V>`.
505
+ * @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
506
506
  */
507
507
  dijkstra(src, dest, getMinDist, genPaths) {
508
508
  var _a;
@@ -535,7 +535,7 @@ class AbstractGraph {
535
535
  preMap.set(srcVertex, null);
536
536
  /**
537
537
  * The function `getPaths` retrieves all paths from vertices to a specified minimum vertex.
538
- * @param {V | null} minV - The parameter `minV` is of type `V | null`. It represents the minimum vertex value or
538
+ * @param {VO | null} minV - The parameter `minV` is of type `VO | null`. It represents the minimum vertex value or
539
539
  * null.
540
540
  */
541
541
  const getPaths = (minV) => {
@@ -607,17 +607,17 @@ class AbstractGraph {
607
607
  return { distMap, preMap, seen, paths, minDist, minPath };
608
608
  }
609
609
  /**
610
- * BellmanFord time:O(VE) space:O(V)
610
+ * BellmanFord time:O(VE) space:O(VO)
611
611
  * one to rest pairs
612
612
  * /
613
613
 
614
614
  /**
615
- * BellmanFord time:O(VE) space:O(V)
615
+ * BellmanFord time:O(VE) space:O(VO)
616
616
  * one to rest pairs
617
617
  * 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.
618
618
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
619
619
  * all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
620
- * @param {V | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
620
+ * @param {VO | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
621
621
  * start calculating the shortest paths. It can be either a vertex object or a vertex ID.
622
622
  * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
623
623
  * @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
@@ -713,31 +713,31 @@ class AbstractGraph {
713
713
  return { hasNegativeCycle, distMap, preMap, paths, min, minPath };
714
714
  }
715
715
  /**
716
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
716
+ * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
717
717
  * /
718
718
 
719
719
  /**
720
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
720
+ * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
721
721
  * 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.
722
722
  */
723
723
  /**
724
- * BellmanFord time:O(VE) space:O(V)
724
+ * BellmanFord time:O(VE) space:O(VO)
725
725
  * one to rest pairs
726
726
  * 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.
727
727
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
728
728
  */
729
729
  /**
730
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
730
+ * Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
731
731
  * all pairs
732
732
  * 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.
733
733
  */
734
734
  /**
735
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
735
+ * Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
736
736
  * all pairs
737
737
  * /
738
738
 
739
739
  /**
740
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
740
+ * Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
741
741
  * all pairs
742
742
  * 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.
743
743
  * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a