data-structure-typed 1.48.4 → 1.48.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.
Files changed (83) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -6
  3. package/dist/cjs/data-structures/base/iterable-base.js +3 -3
  4. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  5. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +5 -3
  6. package/dist/cjs/data-structures/binary-tree/avl-tree.js +6 -4
  7. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +18 -15
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js +16 -13
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/bst.d.ts +15 -11
  12. package/dist/cjs/data-structures/binary-tree/bst.js +17 -13
  13. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +19 -13
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js +20 -14
  16. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +21 -14
  18. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +25 -18
  19. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  20. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +52 -52
  21. package/dist/cjs/data-structures/graph/abstract-graph.js +78 -78
  22. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/directed-graph.d.ts +47 -47
  24. package/dist/cjs/data-structures/graph/directed-graph.js +56 -56
  25. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/map-graph.d.ts +5 -5
  27. package/dist/cjs/data-structures/graph/map-graph.js +8 -8
  28. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +29 -29
  30. package/dist/cjs/data-structures/graph/undirected-graph.js +57 -57
  31. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  32. package/dist/cjs/data-structures/hash/hash-map.d.ts +8 -8
  33. package/dist/cjs/data-structures/hash/hash-map.js +2 -2
  34. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  35. package/dist/cjs/interfaces/binary-tree.d.ts +1 -1
  36. package/dist/cjs/types/data-structures/base/base.d.ts +3 -3
  37. package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -6
  38. package/dist/mjs/data-structures/base/iterable-base.js +1 -1
  39. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +5 -3
  40. package/dist/mjs/data-structures/binary-tree/avl-tree.js +6 -4
  41. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +18 -15
  42. package/dist/mjs/data-structures/binary-tree/binary-tree.js +17 -14
  43. package/dist/mjs/data-structures/binary-tree/bst.d.ts +15 -11
  44. package/dist/mjs/data-structures/binary-tree/bst.js +17 -13
  45. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +19 -13
  46. package/dist/mjs/data-structures/binary-tree/rb-tree.js +20 -14
  47. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +21 -14
  48. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +25 -18
  49. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +52 -52
  50. package/dist/mjs/data-structures/graph/abstract-graph.js +79 -79
  51. package/dist/mjs/data-structures/graph/directed-graph.d.ts +47 -47
  52. package/dist/mjs/data-structures/graph/directed-graph.js +56 -56
  53. package/dist/mjs/data-structures/graph/map-graph.d.ts +5 -5
  54. package/dist/mjs/data-structures/graph/map-graph.js +8 -8
  55. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +29 -29
  56. package/dist/mjs/data-structures/graph/undirected-graph.js +59 -59
  57. package/dist/mjs/data-structures/hash/hash-map.d.ts +8 -8
  58. package/dist/mjs/data-structures/hash/hash-map.js +3 -3
  59. package/dist/mjs/interfaces/binary-tree.d.ts +1 -1
  60. package/dist/mjs/types/data-structures/base/base.d.ts +3 -3
  61. package/dist/umd/data-structure-typed.js +302 -280
  62. package/dist/umd/data-structure-typed.min.js +2 -2
  63. package/dist/umd/data-structure-typed.min.js.map +1 -1
  64. package/package.json +1 -1
  65. package/src/data-structures/base/iterable-base.ts +6 -6
  66. package/src/data-structures/binary-tree/avl-tree.ts +8 -5
  67. package/src/data-structures/binary-tree/binary-tree.ts +23 -19
  68. package/src/data-structures/binary-tree/bst.ts +19 -14
  69. package/src/data-structures/binary-tree/rb-tree.ts +20 -14
  70. package/src/data-structures/binary-tree/tree-multimap.ts +27 -19
  71. package/src/data-structures/graph/abstract-graph.ts +82 -82
  72. package/src/data-structures/graph/directed-graph.ts +56 -56
  73. package/src/data-structures/graph/map-graph.ts +8 -8
  74. package/src/data-structures/graph/undirected-graph.ts +59 -59
  75. package/src/data-structures/hash/hash-map.ts +8 -8
  76. package/src/interfaces/binary-tree.ts +1 -1
  77. package/src/types/data-structures/base/base.ts +3 -3
  78. package/test/integration/bst.test.ts +1 -1
  79. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +1 -1
  80. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +3 -3
  81. package/test/unit/data-structures/graph/directed-graph.test.ts +15 -15
  82. package/test/unit/data-structures/graph/map-graph.test.ts +3 -3
  83. package/test/unit/data-structures/graph/undirected-graph.test.ts +12 -12
@@ -8,7 +8,7 @@
8
8
  import { uuidV4 } from '../../utils';
9
9
  import { PriorityQueue } from '../priority-queue';
10
10
  import { Queue } from '../queue';
11
- import { IterablePairBase } from "../base";
11
+ import { IterableEntryBase } from "../base";
12
12
  export class AbstractVertex {
13
13
  key;
14
14
  value;
@@ -46,13 +46,13 @@ export class AbstractEdge {
46
46
  return this._hashCode;
47
47
  }
48
48
  }
49
- export class AbstractGraph extends IterablePairBase {
49
+ export class AbstractGraph extends IterableEntryBase {
50
50
  constructor() {
51
51
  super();
52
52
  }
53
- _vertices = new Map();
54
- get vertices() {
55
- return this._vertices;
53
+ _vertexMap = new Map();
54
+ get vertexMap() {
55
+ return this._vertexMap;
56
56
  }
57
57
  /**
58
58
  * Time Complexity: O(1) - Constant time for Map lookup.
@@ -64,12 +64,12 @@ export class AbstractGraph extends IterablePairBase {
64
64
  *
65
65
  * The function "getVertex" returns the vertex with the specified ID or undefined if it doesn't exist.
66
66
  * @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
67
- * the `_vertices` map.
68
- * @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertices`
67
+ * the `_vertexMap` map.
68
+ * @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertexMap`
69
69
  * map. If the vertex does not exist, it returns `undefined`.
70
70
  */
71
71
  getVertex(vertexKey) {
72
- return this._vertices.get(vertexKey) || undefined;
72
+ return this._vertexMap.get(vertexKey) || undefined;
73
73
  }
74
74
  /**
75
75
  * Time Complexity: O(1) - Constant time for Map lookup.
@@ -85,7 +85,7 @@ export class AbstractGraph extends IterablePairBase {
85
85
  * @returns a boolean value.
86
86
  */
87
87
  hasVertex(vertexOrKey) {
88
- return this._vertices.has(this._getVertexKey(vertexOrKey));
88
+ return this._vertexMap.has(this._getVertexKey(vertexOrKey));
89
89
  }
90
90
  /**
91
91
  * Time Complexity: O(1) - Constant time for Map operations.
@@ -119,25 +119,25 @@ export class AbstractGraph extends IterablePairBase {
119
119
  */
120
120
  deleteVertex(vertexOrKey) {
121
121
  const vertexKey = this._getVertexKey(vertexOrKey);
122
- return this._vertices.delete(vertexKey);
122
+ return this._vertexMap.delete(vertexKey);
123
123
  }
124
124
  /**
125
- * Time Complexity: O(K), where K is the number of vertices to be removed.
125
+ * Time Complexity: O(K), where K is the number of vertexMap to be removed.
126
126
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
127
127
  */
128
128
  /**
129
- * Time Complexity: O(K), where K is the number of vertices to be removed.
129
+ * Time Complexity: O(K), where K is the number of vertexMap to be removed.
130
130
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
131
131
  *
132
- * The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
133
- * @param {VO[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`VO[]`) or an array
132
+ * The function removes all vertexMap from a graph and returns a boolean indicating if any vertexMap were removed.
133
+ * @param {VO[] | VertexKey[]} vertexMap - The `vertexMap` parameter can be either an array of vertexMap (`VO[]`) or an array
134
134
  * of vertex IDs (`VertexKey[]`).
135
- * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
135
+ * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertexMap
136
136
  * were removed.
137
137
  */
138
- removeManyVertices(vertices) {
138
+ removeManyVertices(vertexMap) {
139
139
  const removed = [];
140
- for (const v of vertices) {
140
+ for (const v of vertexMap) {
141
141
  removed.push(this.deleteVertex(v));
142
142
  }
143
143
  return removed.length > 0;
@@ -150,7 +150,7 @@ export class AbstractGraph extends IterablePairBase {
150
150
  * Time Complexity: O(1) - Depends on the implementation in the concrete class.
151
151
  * Space Complexity: O(1) - Depends on the implementation in the concrete class.
152
152
  *
153
- * The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
153
+ * The function checks if there is an edge between two vertexMap and returns a boolean value indicating the result.
154
154
  * @param {VertexKey | VO} v1 - The parameter v1 can be either a VertexKey or a VO. A VertexKey represents the unique
155
155
  * identifier of a vertex in a graph, while VO represents the type of the vertex object itself.
156
156
  * @param {VertexKey | VO} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
@@ -193,14 +193,14 @@ export class AbstractGraph extends IterablePairBase {
193
193
  * Time Complexity: O(1) - Constant time for Map and Edge operations.
194
194
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
195
195
  *
196
- * The function sets the weight of an edge between two vertices in a graph.
196
+ * The function sets the weight of an edge between two vertexMap in a graph.
197
197
  * @param {VertexKey | VO} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `VO` object. It represents
198
198
  * the source vertex of the edge.
199
199
  * @param {VertexKey | VO} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
200
200
  * either a `VertexKey` or a vertex object `VO`.
201
201
  * @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrKey)
202
202
  * and the destination vertex (destOrKey).
203
- * @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
203
+ * @returns a boolean value. If the edge exists between the source and destination vertexMap, the function will update
204
204
  * the weight of the edge and return true. If the edge does not exist, the function will return false.
205
205
  */
206
206
  setEdgeWeight(srcOrKey, destOrKey, weight) {
@@ -221,12 +221,12 @@ export class AbstractGraph extends IterablePairBase {
221
221
  * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
222
222
  * Space Complexity: O(P) - Linear space, where P is the number of paths found.
223
223
  *
224
- * The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
224
+ * The function `getAllPathsBetween` finds all paths between two vertexMap in a graph using depth-first search.
225
225
  * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
226
226
  * It is the starting vertex for finding paths.
227
227
  * @param {VO | VertexKey} v2 - The parameter `v2` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
228
228
  * @param limit - The count of limitation of result array.
229
- * @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`VO[][]`).
229
+ * @returns The function `getAllPathsBetween` returns an array of arrays of vertexMap (`VO[][]`).
230
230
  */
231
231
  getAllPathsBetween(v1, v2, limit = 1000) {
232
232
  const paths = [];
@@ -263,8 +263,8 @@ export class AbstractGraph extends IterablePairBase {
263
263
  * Space Complexity: O(1) - Constant space.
264
264
  *
265
265
  * The function calculates the sum of weights along a given path.
266
- * @param {VO[]} path - An array of vertices (VO) representing a path in a graph.
267
- * @returns The function `getPathSumWeight` returns the sum of the weights of the edges in the given path.
266
+ * @param {VO[]} path - An array of vertexMap (VO) representing a path in a graph.
267
+ * @returns The function `getPathSumWeight` returns the sum of the weights of the edgeMap in the given path.
268
268
  */
269
269
  getPathSumWeight(path) {
270
270
  let sum = 0;
@@ -281,17 +281,17 @@ export class AbstractGraph extends IterablePairBase {
281
281
  * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
282
282
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
283
283
  *
284
- * The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
284
+ * The function `getMinCostBetween` calculates the minimum cost between two vertexMap in a graph, either based on edge
285
285
  * weights or using a breadth-first search algorithm.
286
286
  * @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
287
287
  * @param {VO | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
288
288
  * you want to find the minimum cost or weight from the source vertex `v1`.
289
- * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
289
+ * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edgeMap have weights.
290
290
  * If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
291
- * the edges. If isWeight is set to false or not provided, the function will calculate the
292
- * @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertices (`v1`
291
+ * the edgeMap. If isWeight is set to false or not provided, the function will calculate the
292
+ * @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertexMap (`v1`
293
293
  * and `v2`). If the `isWeight` parameter is `true`, it calculates the minimum weight among all paths between the
294
- * vertices. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
294
+ * vertexMap. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
295
295
  * minimum number of
296
296
  */
297
297
  getMinCostBetween(v1, v2, isWeight) {
@@ -346,20 +346,20 @@ export class AbstractGraph extends IterablePairBase {
346
346
  * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
347
347
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
348
348
  *
349
- * The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
349
+ * The function `getMinPathBetween` returns the minimum path between two vertexMap in a graph, either based on weight or
350
350
  * using a breadth-first search algorithm.
351
351
  * @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
352
352
  * object (`VO`) or a vertex ID (`VertexKey`).
353
353
  * @param {VO | VertexKey} v2 - VO | VertexKey - The second vertex or vertex ID between which we want to find the minimum
354
354
  * path.
355
- * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
355
+ * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edgeMap in finding the
356
356
  * minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
357
357
  * to false, the function will use breadth-first search (BFS) to find the minimum path.
358
358
  * @param isDFS - If set to true, it enforces the use of getAllPathsBetween to first obtain all possible paths,
359
359
  * followed by iterative computation of the shortest path. This approach may result in exponential time complexity,
360
360
  * so the default method is to use the Dijkstra algorithm to obtain the shortest weighted path.
361
- * @returns The function `getMinPathBetween` returns an array of vertices (`VO[]`) representing the minimum path between
362
- * two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `undefined`.
361
+ * @returns The function `getMinPathBetween` returns an array of vertexMap (`VO[]`) representing the minimum path between
362
+ * two vertexMap (`v1` and `v2`). If there is no path between the vertexMap, it returns `undefined`.
363
363
  */
364
364
  getMinPathBetween(v1, v2, isWeight, isDFS = false) {
365
365
  if (isWeight === undefined)
@@ -423,7 +423,7 @@ export class AbstractGraph extends IterablePairBase {
423
423
  * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
424
424
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
425
425
  *
426
- * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
426
+ * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertexMap in
427
427
  * a graph without using a heap data structure.
428
428
  * @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
429
429
  * vertex object or a vertex ID.
@@ -435,7 +435,7 @@ export class AbstractGraph extends IterablePairBase {
435
435
  * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
436
436
  * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
437
437
  * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
438
- * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
438
+ * shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
439
439
  * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
440
440
  */
441
441
  dijkstraWithoutHeap(src, dest, getMinDist, genPaths) {
@@ -449,7 +449,7 @@ export class AbstractGraph extends IterablePairBase {
449
449
  let minDest = undefined;
450
450
  let minPath = [];
451
451
  const paths = [];
452
- const vertices = this._vertices;
452
+ const vertexMap = this._vertexMap;
453
453
  const distMap = new Map();
454
454
  const seen = new Set();
455
455
  const preMap = new Map(); // predecessor
@@ -458,7 +458,7 @@ export class AbstractGraph extends IterablePairBase {
458
458
  if (!srcVertex) {
459
459
  return undefined;
460
460
  }
461
- for (const vertex of vertices) {
461
+ for (const vertex of vertexMap) {
462
462
  const vertexOrKey = vertex[1];
463
463
  if (vertexOrKey instanceof AbstractVertex)
464
464
  distMap.set(vertexOrKey, Infinity);
@@ -479,7 +479,7 @@ export class AbstractGraph extends IterablePairBase {
479
479
  return minV;
480
480
  };
481
481
  const getPaths = (minV) => {
482
- for (const vertex of vertices) {
482
+ for (const vertex of vertexMap) {
483
483
  const vertexOrKey = vertex[1];
484
484
  if (vertexOrKey instanceof AbstractVertex) {
485
485
  const path = [vertexOrKey];
@@ -495,7 +495,7 @@ export class AbstractGraph extends IterablePairBase {
495
495
  }
496
496
  }
497
497
  };
498
- for (let i = 1; i < vertices.size; i++) {
498
+ for (let i = 1; i < vertexMap.size; i++) {
499
499
  const cur = getMinOfNoSeen();
500
500
  if (cur) {
501
501
  seen.add(cur);
@@ -544,7 +544,7 @@ export class AbstractGraph extends IterablePairBase {
544
544
  * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
545
545
  *
546
546
  * 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.
547
- * 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.
547
+ * 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 edgeMap.
548
548
  * 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.
549
549
  *
550
550
  * /
@@ -564,13 +564,13 @@ export class AbstractGraph extends IterablePairBase {
564
564
  * start. It can be either a vertex object or a vertex ID.
565
565
  * @param {VO | VertexKey | undefined} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
566
566
  * vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
567
- * will calculate the shortest paths to all other vertices from the source vertex.
567
+ * will calculate the shortest paths to all other vertexMap from the source vertex.
568
568
  * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
569
569
  * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
570
570
  * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
571
571
  * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
572
572
  * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
573
- * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
573
+ * shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
574
574
  * @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
575
575
  */
576
576
  dijkstra(src, dest, getMinDist, genPaths) {
@@ -584,7 +584,7 @@ export class AbstractGraph extends IterablePairBase {
584
584
  let minDest = undefined;
585
585
  let minPath = [];
586
586
  const paths = [];
587
- const vertices = this._vertices;
587
+ const vertexMap = this._vertexMap;
588
588
  const distMap = new Map();
589
589
  const seen = new Set();
590
590
  const preMap = new Map(); // predecessor
@@ -592,7 +592,7 @@ export class AbstractGraph extends IterablePairBase {
592
592
  const destVertex = dest ? this._getVertex(dest) : undefined;
593
593
  if (!srcVertex)
594
594
  return undefined;
595
- for (const vertex of vertices) {
595
+ for (const vertex of vertexMap) {
596
596
  const vertexOrKey = vertex[1];
597
597
  if (vertexOrKey instanceof AbstractVertex)
598
598
  distMap.set(vertexOrKey, Infinity);
@@ -602,12 +602,12 @@ export class AbstractGraph extends IterablePairBase {
602
602
  distMap.set(srcVertex, 0);
603
603
  preMap.set(srcVertex, undefined);
604
604
  /**
605
- * The function `getPaths` retrieves all paths from vertices to a specified minimum vertex.
605
+ * The function `getPaths` retrieves all paths from vertexMap to a specified minimum vertex.
606
606
  * @param {VO | undefined} minV - The parameter `minV` is of type `VO | undefined`. It represents the minimum vertex value or
607
607
  * undefined.
608
608
  */
609
609
  const getPaths = (minV) => {
610
- for (const vertex of vertices) {
610
+ for (const vertex of vertexMap) {
611
611
  const vertexOrKey = vertex[1];
612
612
  if (vertexOrKey instanceof AbstractVertex) {
613
613
  const path = [vertexOrKey];
@@ -685,16 +685,16 @@ export class AbstractGraph extends IterablePairBase {
685
685
  * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
686
686
  *
687
687
  * one to rest pairs
688
- * 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.
688
+ * 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 edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios.
689
689
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
690
- * all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
690
+ * all other vertexMap in a graph, and optionally detects negative cycles and generates the minimum path.
691
691
  * @param {VO | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
692
692
  * start calculating the shortest paths. It can be either a vertex object or a vertex ID.
693
693
  * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
694
694
  * @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
695
- * calculate the minimum distance from the source vertex to all other vertices in the graph. If `getMin` is set to
695
+ * calculate the minimum distance from the source vertex to all other vertexMap in the graph. If `getMin` is set to
696
696
  * `true`, the algorithm will find the minimum distance and update the `min` variable with the minimum
697
- * @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertices from the source
697
+ * @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertexMap from the source
698
698
  * vertex.
699
699
  * @returns The function `bellmanFord` returns an object with the following properties:
700
700
  */
@@ -715,20 +715,20 @@ export class AbstractGraph extends IterablePairBase {
715
715
  hasNegativeCycle = false;
716
716
  if (!srcVertex)
717
717
  return { hasNegativeCycle, distMap, preMap, paths, min, minPath };
718
- const vertices = this._vertices;
719
- const numOfVertices = vertices.size;
720
- const edges = this.edgeSet();
721
- const numOfEdges = edges.length;
722
- this._vertices.forEach(vertex => {
718
+ const vertexMap = this._vertexMap;
719
+ const numOfVertices = vertexMap.size;
720
+ const edgeMap = this.edgeSet();
721
+ const numOfEdges = edgeMap.length;
722
+ this._vertexMap.forEach(vertex => {
723
723
  distMap.set(vertex, Infinity);
724
724
  });
725
725
  distMap.set(srcVertex, 0);
726
726
  for (let i = 1; i < numOfVertices; ++i) {
727
727
  for (let j = 0; j < numOfEdges; ++j) {
728
- const ends = this.getEndsOfEdge(edges[j]);
728
+ const ends = this.getEndsOfEdge(edgeMap[j]);
729
729
  if (ends) {
730
730
  const [s, d] = ends;
731
- const weight = edges[j].weight;
731
+ const weight = edgeMap[j].weight;
732
732
  const sWeight = distMap.get(s);
733
733
  const dWeight = distMap.get(d);
734
734
  if (sWeight !== undefined && dWeight !== undefined) {
@@ -753,7 +753,7 @@ export class AbstractGraph extends IterablePairBase {
753
753
  });
754
754
  }
755
755
  if (genPath) {
756
- for (const vertex of vertices) {
756
+ for (const vertex of vertexMap) {
757
757
  const vertexOrKey = vertex[1];
758
758
  if (vertexOrKey instanceof AbstractVertex) {
759
759
  const path = [vertexOrKey];
@@ -770,10 +770,10 @@ export class AbstractGraph extends IterablePairBase {
770
770
  }
771
771
  }
772
772
  for (let j = 0; j < numOfEdges; ++j) {
773
- const ends = this.getEndsOfEdge(edges[j]);
773
+ const ends = this.getEndsOfEdge(edgeMap[j]);
774
774
  if (ends) {
775
775
  const [s] = ends;
776
- const weight = edges[j].weight;
776
+ const weight = edgeMap[j].weight;
777
777
  const sWeight = distMap.get(s);
778
778
  if (sWeight) {
779
779
  if (sWeight !== Infinity && sWeight + weight < sWeight)
@@ -794,7 +794,7 @@ export class AbstractGraph extends IterablePairBase {
794
794
  /**
795
795
  * BellmanFord time:O(VE) space:O(VO)
796
796
  * one to rest pairs
797
- * 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.
797
+ * 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 edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios.
798
798
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
799
799
  */
800
800
  /**
@@ -802,7 +802,7 @@ export class AbstractGraph extends IterablePairBase {
802
802
  * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
803
803
  * Not support graph with negative weight cycle
804
804
  * all pairs
805
- * 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.
805
+ * 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 edgeMap, and it can simultaneously compute shortest paths between any two nodes.
806
806
  * /
807
807
 
808
808
  /**
@@ -811,16 +811,16 @@ export class AbstractGraph extends IterablePairBase {
811
811
  *
812
812
  * Not support graph with negative weight cycle
813
813
  * all pairs
814
- * 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.
815
- * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
814
+ * 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 edgeMap, and it can simultaneously compute shortest paths between any two nodes.
815
+ * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertexMap in a
816
816
  * graph.
817
817
  * @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
818
- * property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
819
- * `predecessor` property is a 2D array of vertices (or `undefined`) representing the predecessor vertices in the shortest
820
- * path between vertices in the
818
+ * property is a 2D array of numbers representing the shortest path costs between vertexMap in a graph. The
819
+ * `predecessor` property is a 2D array of vertexMap (or `undefined`) representing the predecessor vertexMap in the shortest
820
+ * path between vertexMap in the
821
821
  */
822
822
  floydWarshall() {
823
- const idAndVertices = [...this._vertices];
823
+ const idAndVertices = [...this._vertexMap];
824
824
  const n = idAndVertices.length;
825
825
  const costs = [];
826
826
  const predecessor = [];
@@ -854,7 +854,7 @@ export class AbstractGraph extends IterablePairBase {
854
854
  * Space Complexity: O(V) - Linear space (Tarjan's algorithm).
855
855
  * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
856
856
  * Tarjan can find cycles in directed or undirected graph
857
- * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
857
+ * Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time,
858
858
  * Tarjan solve the bi-connected components of undirected graphs;
859
859
  * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
860
860
  * /
@@ -865,22 +865,22 @@ export class AbstractGraph extends IterablePairBase {
865
865
  *
866
866
  * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
867
867
  * Tarjan can find cycles in directed or undirected graph
868
- * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
868
+ * Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time,
869
869
  * Tarjan solve the bi-connected components of undirected graphs;
870
870
  * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
871
871
  * The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
872
872
  * strongly connected components (SCCs), and cycles in a graph.
873
873
  * @param {boolean} [needCutVertexes] - A boolean value indicating whether or not to calculate and return the
874
- * articulation points in the graph. Articulation points are the vertices in a graph whose removal would increase the
874
+ * articulation points in the graph. Articulation points are the vertexMap in a graph whose removal would increase the
875
875
  * number of connected components in the graph.
876
876
  * @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
877
- * (edges whose removal would increase the number of connected components in the graph).
877
+ * (edgeMap whose removal would increase the number of connected components in the graph).
878
878
  * @param {boolean} [needSCCs] - A boolean value indicating whether the Strongly Connected Components (SCCs) of the
879
879
  * graph are needed. If set to true, the function will calculate and return the SCCs of the graph. If set to false, the
880
880
  * SCCs will not be calculated or returned.
881
881
  * @param {boolean} [needCycles] - A boolean flag indicating whether the algorithm should find cycles in the graph. If
882
882
  * set to true, the algorithm will return a map of cycles, where the keys are the low values of the SCCs and the values
883
- * are arrays of vertices that form cycles within the SCCs.
883
+ * are arrays of vertexMap that form cycles within the SCCs.
884
884
  * @returns The function `tarjan` returns an object with the following properties:
885
885
  */
886
886
  tarjan(needCutVertexes = false, needBridges = false, needSCCs = true, needCycles = false) {
@@ -898,12 +898,12 @@ export class AbstractGraph extends IterablePairBase {
898
898
  needCycles = defaultConfig;
899
899
  const dfnMap = new Map();
900
900
  const lowMap = new Map();
901
- const vertices = this._vertices;
902
- vertices.forEach(v => {
901
+ const vertexMap = this._vertexMap;
902
+ vertexMap.forEach(v => {
903
903
  dfnMap.set(v, -1);
904
904
  lowMap.set(v, Infinity);
905
905
  });
906
- const [root] = vertices.values();
906
+ const [root] = vertexMap.values();
907
907
  const cutVertexes = [];
908
908
  const bridges = [];
909
909
  let dfn = 0;
@@ -1087,7 +1087,7 @@ export class AbstractGraph extends IterablePairBase {
1087
1087
  return mapped;
1088
1088
  }
1089
1089
  *_getIterator() {
1090
- for (const vertex of this._vertices.values()) {
1090
+ for (const vertex of this._vertexMap.values()) {
1091
1091
  yield [vertex.key, vertex.value];
1092
1092
  }
1093
1093
  }
@@ -1096,12 +1096,12 @@ export class AbstractGraph extends IterablePairBase {
1096
1096
  return false;
1097
1097
  // throw (new Error('Duplicated vertex key is not allowed'));
1098
1098
  }
1099
- this._vertices.set(newVertex.key, newVertex);
1099
+ this._vertexMap.set(newVertex.key, newVertex);
1100
1100
  return true;
1101
1101
  }
1102
1102
  _getVertex(vertexOrKey) {
1103
1103
  const vertexKey = this._getVertexKey(vertexOrKey);
1104
- return this._vertices.get(vertexKey) || undefined;
1104
+ return this._vertexMap.get(vertexKey) || undefined;
1105
1105
  }
1106
1106
  _getVertexKey(vertexOrKey) {
1107
1107
  return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;