min-heap-typed 1.39.4 → 1.39.6

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 (47) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +6 -6
  2. package/dist/data-structures/binary-tree/avl-tree.js +13 -13
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +7 -7
  4. package/dist/data-structures/binary-tree/binary-tree.js +17 -17
  5. package/dist/data-structures/binary-tree/bst.d.ts +6 -6
  6. package/dist/data-structures/binary-tree/bst.js +13 -13
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +2 -2
  8. package/dist/data-structures/binary-tree/rb-tree.js +4 -4
  9. package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -7
  10. package/dist/data-structures/binary-tree/segment-tree.js +16 -16
  11. package/dist/data-structures/binary-tree/tree-multiset.d.ts +6 -6
  12. package/dist/data-structures/binary-tree/tree-multiset.js +18 -18
  13. package/dist/data-structures/graph/abstract-graph.d.ts +96 -96
  14. package/dist/data-structures/graph/abstract-graph.js +64 -64
  15. package/dist/data-structures/graph/directed-graph.d.ts +68 -68
  16. package/dist/data-structures/graph/directed-graph.js +48 -48
  17. package/dist/data-structures/graph/map-graph.d.ts +13 -13
  18. package/dist/data-structures/graph/map-graph.js +15 -15
  19. package/dist/data-structures/graph/undirected-graph.d.ts +42 -42
  20. package/dist/data-structures/graph/undirected-graph.js +32 -32
  21. package/dist/data-structures/hash/hash-table.d.ts +4 -4
  22. package/dist/data-structures/hash/hash-table.js +8 -8
  23. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +31 -31
  24. package/dist/data-structures/linked-list/doubly-linked-list.js +54 -54
  25. package/dist/data-structures/linked-list/singly-linked-list.d.ts +24 -24
  26. package/dist/data-structures/linked-list/singly-linked-list.js +52 -52
  27. package/dist/data-structures/queue/queue.d.ts +1 -1
  28. package/dist/data-structures/queue/queue.js +4 -4
  29. package/dist/interfaces/binary-tree.d.ts +2 -2
  30. package/dist/interfaces/graph.d.ts +3 -3
  31. package/package.json +2 -2
  32. package/src/data-structures/binary-tree/avl-tree.ts +13 -13
  33. package/src/data-structures/binary-tree/binary-tree.ts +18 -18
  34. package/src/data-structures/binary-tree/bst.ts +16 -16
  35. package/src/data-structures/binary-tree/rb-tree.ts +6 -6
  36. package/src/data-structures/binary-tree/segment-tree.ts +15 -15
  37. package/src/data-structures/binary-tree/tree-multiset.ts +18 -18
  38. package/src/data-structures/graph/abstract-graph.ts +156 -154
  39. package/src/data-structures/graph/directed-graph.ts +99 -94
  40. package/src/data-structures/graph/map-graph.ts +22 -25
  41. package/src/data-structures/graph/undirected-graph.ts +62 -60
  42. package/src/data-structures/hash/hash-table.ts +9 -9
  43. package/src/data-structures/linked-list/doubly-linked-list.ts +61 -61
  44. package/src/data-structures/linked-list/singly-linked-list.ts +58 -58
  45. package/src/data-structures/queue/queue.ts +2 -2
  46. package/src/interfaces/binary-tree.ts +2 -2
  47. package/src/interfaces/graph.ts +3 -3
@@ -16,12 +16,12 @@ class AbstractVertex {
16
16
  * The function is a protected constructor that takes an key and an optional value as parameters.
17
17
  * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
18
18
  * used to uniquely identify the vertex object.
19
- * @param {V} [val] - The parameter "val" is an optional parameter of type V. It is used to assign a value to the
19
+ * @param {V} [value] - The parameter "value" is an optional parameter of type V. It is used to assign a value to the
20
20
  * vertex. If no value is provided, it will be set to undefined.
21
21
  */
22
- constructor(key, val) {
22
+ constructor(key, value) {
23
23
  this._key = key;
24
- this._val = val;
24
+ this._value = value;
25
25
  }
26
26
  get key() {
27
27
  return this._key;
@@ -29,11 +29,11 @@ class AbstractVertex {
29
29
  set key(v) {
30
30
  this._key = v;
31
31
  }
32
- get val() {
33
- return this._val;
32
+ get value() {
33
+ return this._value;
34
34
  }
35
- set val(value) {
36
- this._val = value;
35
+ set value(value) {
36
+ this._value = value;
37
37
  }
38
38
  }
39
39
  exports.AbstractVertex = AbstractVertex;
@@ -44,19 +44,19 @@ 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} [value] - The `value` 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
- constructor(weight, val) {
50
+ constructor(weight, value) {
51
51
  this._weight = weight !== undefined ? weight : 1;
52
- this._val = val;
52
+ this._value = value;
53
53
  this._hashCode = (0, utils_1.uuidV4)();
54
54
  }
55
- get val() {
56
- return this._val;
55
+ get value() {
56
+ return this._value;
57
57
  }
58
- set val(value) {
59
- this._val = value;
58
+ set value(value) {
59
+ this._value = value;
60
60
  }
61
61
  get weight() {
62
62
  return this._weight;
@@ -100,25 +100,25 @@ 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
  */
107
107
  hasVertex(vertexOrKey) {
108
108
  return this._vertices.has(this._getVertexKey(vertexOrKey));
109
109
  }
110
- addVertex(keyOrVertex, val) {
110
+ addVertex(keyOrVertex, value) {
111
111
  if (keyOrVertex instanceof AbstractVertex) {
112
112
  return this._addVertexOnly(keyOrVertex);
113
113
  }
114
114
  else {
115
- const newVertex = this.createVertex(keyOrVertex, val);
115
+ const newVertex = this.createVertex(keyOrVertex, value);
116
116
  return this._addVertexOnly(newVertex);
117
117
  }
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,17 +142,17 @@ 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) {
152
152
  const edge = this.getEdge(v1, v2);
153
153
  return !!edge;
154
154
  }
155
- addEdge(srcOrEdge, dest, weight, val) {
155
+ addEdge(srcOrEdge, dest, weight, value) {
156
156
  if (srcOrEdge instanceof AbstractEdge) {
157
157
  return this._addEdgeOnly(srcOrEdge);
158
158
  }
@@ -164,7 +164,7 @@ class AbstractGraph {
164
164
  srcOrEdge = srcOrEdge.key;
165
165
  if (dest instanceof AbstractVertex)
166
166
  dest = dest.key;
167
- const newEdge = this.createEdge(srcOrEdge, dest, weight, val);
167
+ const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
168
168
  return this._addEdgeOnly(newEdge);
169
169
  }
170
170
  else {
@@ -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)
@@ -406,10 +406,10 @@ class AbstractGraph {
406
406
  const getMinOfNoSeen = () => {
407
407
  let min = Infinity;
408
408
  let minV = null;
409
- for (const [key, val] of distMap) {
409
+ for (const [key, value] of distMap) {
410
410
  if (!seen.has(key)) {
411
- if (val < min) {
412
- min = val;
411
+ if (value < min) {
412
+ min = value;
413
413
  minV = key;
414
414
  }
415
415
  }
@@ -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;
@@ -530,12 +530,12 @@ class AbstractGraph {
530
530
  distMap.set(vertexOrKey, Infinity);
531
531
  }
532
532
  const heap = new priority_queue_1.PriorityQueue({ comparator: (a, b) => a.key - b.key });
533
- heap.add({ key: 0, val: srcVertex });
533
+ heap.add({ key: 0, value: srcVertex });
534
534
  distMap.set(srcVertex, 0);
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) => {
@@ -558,7 +558,7 @@ class AbstractGraph {
558
558
  while (heap.size > 0) {
559
559
  const curHeapNode = heap.poll();
560
560
  const dist = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.key;
561
- const cur = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.val;
561
+ const cur = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.value;
562
562
  if (dist !== undefined) {
563
563
  if (cur) {
564
564
  seen.add(cur);
@@ -579,7 +579,7 @@ class AbstractGraph {
579
579
  const distSrcToNeighbor = distMap.get(neighbor);
580
580
  if (distSrcToNeighbor) {
581
581
  if (dist + weight < distSrcToNeighbor) {
582
- heap.add({ key: dist + weight, val: neighbor });
582
+ heap.add({ key: dist + weight, value: neighbor });
583
583
  preMap.set(neighbor, cur);
584
584
  distMap.set(neighbor, dist + weight);
585
585
  }
@@ -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
@@ -6,12 +6,12 @@ export declare class DirectedVertex<V = any> extends AbstractVertex<V> {
6
6
  * The constructor function initializes a vertex with an optional value.
7
7
  * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
8
8
  * used to uniquely identify the vertex within a graph or data structure.
9
- * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the
9
+ * @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
10
10
  * vertex. If no value is provided, the vertex will be initialized with a default value.
11
11
  */
12
- constructor(key: VertexKey, val?: V);
12
+ constructor(key: VertexKey, value?: V);
13
13
  }
14
- export declare class DirectedEdge<V = any> extends AbstractEdge<V> {
14
+ export declare class DirectedEdge<E = any> extends AbstractEdge<E> {
15
15
  /**
16
16
  * The constructor function initializes the source and destination vertices of an edge, along with an optional weight
17
17
  * and value.
@@ -20,10 +20,10 @@ export declare class DirectedEdge<V = any> extends AbstractEdge<V> {
20
20
  * @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
21
21
  * `VertexKey`, which is likely a unique identifier for a vertex in a graph.
22
22
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
23
- * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value associated with
23
+ * @param {E} [value] - The `value` parameter is an optional parameter of type `E`. It represents the value associated with
24
24
  * the edge.
25
25
  */
26
- constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: V);
26
+ constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
27
27
  private _src;
28
28
  get src(): VertexKey;
29
29
  set src(v: VertexKey);
@@ -31,15 +31,15 @@ export declare class DirectedEdge<V = any> extends AbstractEdge<V> {
31
31
  get dest(): VertexKey;
32
32
  set dest(v: VertexKey);
33
33
  }
34
- export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVertex, E extends DirectedEdge<any> = DirectedEdge> extends AbstractGraph<V, E> implements IGraph<V, E> {
34
+ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V> = DirectedVertex<V>, EO extends DirectedEdge<E> = DirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
35
35
  /**
36
36
  * The constructor function initializes an instance of a class.
37
37
  */
38
38
  constructor();
39
39
  private _outEdgeMap;
40
- get outEdgeMap(): Map<V, E[]>;
40
+ get outEdgeMap(): Map<VO, EO[]>;
41
41
  private _inEdgeMap;
42
- get inEdgeMap(): Map<V, E[]>;
42
+ get inEdgeMap(): Map<VO, EO[]>;
43
43
  /**
44
44
  * 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.
45
45
  * 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.
@@ -48,12 +48,12 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVerte
48
48
  * The function creates a new vertex with an optional value and returns it.
49
49
  * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
50
50
  * could be a number or a string depending on how you want to identify your vertices.
51
- * @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
52
- * it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
51
+ * @param [value] - The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided,
52
+ * it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be
53
53
  * assigned the same value as the 'key' parameter
54
- * @returns a new instance of a DirectedVertex object, casted as type V.
54
+ * @returns a new instance of a DirectedVertex object, casted as type VO.
55
55
  */
56
- createVertex(key: VertexKey, val?: V['val']): V;
56
+ createVertex(key: VertexKey, value?: V): VO;
57
57
  /**
58
58
  * 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.
59
59
  * 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,100 +64,100 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVerte
64
64
  * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
65
65
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
66
66
  * weight is provided, it defaults to 1.
67
- * @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
67
+ * @param [value] - The 'value' parameter is an optional value that can be assigned to the edge. It can be of any type and
68
68
  * is used to store additional information or data associated with the edge.
69
- * @returns a new instance of a DirectedEdge object, casted as type E.
69
+ * @returns a new instance of a DirectedEdge object, casted as type EO.
70
70
  */
71
- createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E['val']): E;
71
+ createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
72
72
  /**
73
73
  * The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
74
- * @param {V | null | VertexKey} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
75
- * @param {V | null | VertexKey} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
76
- * destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexKey`), or `null` if the
74
+ * @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
75
+ * @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
76
+ * destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
77
77
  * destination is not specified.
78
78
  * @returns the first edge found between the source and destination vertices, or null if no such edge is found.
79
79
  */
80
- getEdge(srcOrKey: V | null | VertexKey, destOrKey: V | null | VertexKey): E | null;
80
+ getEdge(srcOrKey: VO | VertexKey | null, destOrKey: VO | VertexKey | null): EO | null;
81
81
  /**
82
82
  * The function removes an edge between two vertices in a graph and returns the removed edge.
83
- * @param {V | VertexKey} srcOrKey - The source vertex or its ID.
84
- * @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
85
- * @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
83
+ * @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
84
+ * @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
85
+ * @returns the removed edge (EO) if it exists, or null if either the source or destination vertex does not exist.
86
86
  */
87
- deleteEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
87
+ deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | null;
88
88
  /**
89
89
  * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
90
- * @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
90
+ * @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
91
91
  * and `dest`, which represent the source and destination vertices of the edge, respectively.
92
- * @returns The method `deleteEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
92
+ * @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `null` if the edge does not exist.
93
93
  */
94
- deleteEdge(edge: E): E | null;
94
+ deleteEdge(edge: EO): EO | null;
95
95
  /**
96
96
  * The function removes edges between two vertices and returns the removed edges.
97
- * @param {VertexKey | V} v1 - The parameter `v1` can be either a `VertexKey` or a `V`. A `VertexKey` represents the
98
- * unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
99
- * @param {VertexKey | V} v2 - The parameter `v2` represents either a `VertexKey` or a `V` object. It is used to specify
97
+ * @param {VertexKey | VO} v1 - The parameter `v1` can be either a `VertexKey` or a `VO`. A `VertexKey` represents the
98
+ * unique identifier of a vertex in a graph, while `VO` represents the actual vertex object.
99
+ * @param {VertexKey | VO} v2 - The parameter `v2` represents either a `VertexKey` or a `VO` object. It is used to specify
100
100
  * the second vertex in the edge that needs to be removed.
101
- * @returns an array of removed edges (E[]).
101
+ * @returns an array of removed edges (EO[]).
102
102
  */
103
- deleteEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[];
103
+ deleteEdgesBetween(v1: VertexKey | VO, v2: VertexKey | VO): EO[];
104
104
  /**
105
105
  * The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
106
- * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
106
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
107
107
  * (`VertexKey`).
108
- * @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
108
+ * @returns The method `incomingEdgesOf` returns an array of edges (`EO[]`).
109
109
  */
110
- incomingEdgesOf(vertexOrKey: V | VertexKey): E[];
110
+ incomingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
111
111
  /**
112
112
  * The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
113
- * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`V`) or a vertex ID
113
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`VO`) or a vertex ID
114
114
  * (`VertexKey`).
115
- * @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
115
+ * @returns The method `outgoingEdgesOf` returns an array of edges (`EO[]`).
116
116
  */
117
- outgoingEdgesOf(vertexOrKey: V | VertexKey): E[];
117
+ outgoingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
118
118
  /**
119
119
  * The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
120
- * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
120
+ * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
121
121
  * @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
122
122
  */
123
- degreeOf(vertexOrKey: VertexKey | V): number;
123
+ degreeOf(vertexOrKey: VertexKey | VO): number;
124
124
  /**
125
125
  * The function "inDegreeOf" returns the number of incoming edges for a given vertex.
126
- * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
126
+ * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
127
127
  * @returns The number of incoming edges of the specified vertex or vertex ID.
128
128
  */
129
- inDegreeOf(vertexOrKey: VertexKey | V): number;
129
+ inDegreeOf(vertexOrKey: VertexKey | VO): number;
130
130
  /**
131
131
  * The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
132
- * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
132
+ * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
133
133
  * @returns The number of outgoing edges from the specified vertex or vertex ID.
134
134
  */
135
- outDegreeOf(vertexOrKey: VertexKey | V): number;
135
+ outDegreeOf(vertexOrKey: VertexKey | VO): number;
136
136
  /**
137
137
  * The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
138
- * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
138
+ * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
139
139
  * @returns The function `edgesOf` returns an array of edges.
140
140
  */
141
- edgesOf(vertexOrKey: VertexKey | V): E[];
141
+ edgesOf(vertexOrKey: VertexKey | VO): EO[];
142
142
  /**
143
143
  * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
144
- * @param {E} e - The parameter "e" is of type E, which represents an edge in a graph.
145
- * @returns either a vertex object (V) or null.
144
+ * @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
145
+ * @returns either a vertex object (VO) or null.
146
146
  */
147
- getEdgeSrc(e: E): V | null;
147
+ getEdgeSrc(e: EO): VO | null;
148
148
  /**
149
149
  * The function "getEdgeDest" returns the destination vertex of an edge.
150
- * @param {E} e - The parameter "e" is of type "E", which represents an edge in a graph.
151
- * @returns either a vertex object of type V or null.
150
+ * @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
151
+ * @returns either a vertex object of type VO or null.
152
152
  */
153
- getEdgeDest(e: E): V | null;
153
+ getEdgeDest(e: EO): VO | null;
154
154
  /**
155
155
  * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
156
- * @param {V | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
157
- * find the destinations. It can be either a `V` object, a `VertexKey` value, or `null`.
158
- * @returns an array of vertices (V[]).
156
+ * @param {VO | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
157
+ * find the destinations. It can be either a `VO` object, a `VertexKey` value, or `null`.
158
+ * @returns an array of vertices (VO[]).
159
159
  */
160
- getDestinations(vertex: V | VertexKey | null): V[];
160
+ getDestinations(vertex: VO | VertexKey | null): VO[];
161
161
  /**
162
162
  * The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
163
163
  * in the sorted order, or null if the graph contains a cycle.
@@ -166,35 +166,35 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVerte
166
166
  * specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
167
167
  * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
168
168
  */
169
- topologicalSort(propertyName?: 'vertex' | 'key'): Array<V | VertexKey> | null;
169
+ topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | null;
170
170
  /**
171
171
  * The `edgeSet` function returns an array of all the edges in the graph.
172
- * @returns The `edgeSet()` method returns an array of edges (`E[]`).
172
+ * @returns The `edgeSet()` method returns an array of edges (`EO[]`).
173
173
  */
174
- edgeSet(): E[];
174
+ edgeSet(): EO[];
175
175
  /**
176
176
  * The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
177
- * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
177
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
178
178
  * (`VertexKey`).
179
- * @returns an array of vertices (V[]).
179
+ * @returns an array of vertices (VO[]).
180
180
  */
181
- getNeighbors(vertexOrKey: V | VertexKey): V[];
181
+ getNeighbors(vertexOrKey: VO | VertexKey): VO[];
182
182
  /**
183
183
  * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
184
184
  * otherwise it returns null.
185
- * @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph.
186
- * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
185
+ * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
186
+ * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
187
187
  * graph. If the edge does not exist, it returns `null`.
188
188
  */
189
- getEndsOfEdge(edge: E): [V, V] | null;
189
+ getEndsOfEdge(edge: EO): [VO, VO] | null;
190
190
  /**
191
191
  * The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
192
- * @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph. It is the edge that
192
+ * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
193
193
  * needs to be added to the graph.
194
194
  * @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
195
195
  * source or destination vertex does not exist in the graph.
196
196
  */
197
- protected _addEdgeOnly(edge: E): boolean;
198
- protected _setOutEdgeMap(value: Map<V, E[]>): void;
199
- protected _setInEdgeMap(value: Map<V, E[]>): void;
197
+ protected _addEdgeOnly(edge: EO): boolean;
198
+ protected _setOutEdgeMap(value: Map<VO, EO[]>): void;
199
+ protected _setInEdgeMap(value: Map<VO, EO[]>): void;
200
200
  }