directed-graph-typed 1.48.0 → 1.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/data-structures/base/index.d.ts +1 -0
  2. package/dist/data-structures/base/index.js +17 -0
  3. package/dist/data-structures/base/iterable-base.d.ts +232 -0
  4. package/dist/data-structures/base/iterable-base.js +312 -0
  5. package/dist/data-structures/binary-tree/avl-tree.d.ts +28 -19
  6. package/dist/data-structures/binary-tree/avl-tree.js +22 -11
  7. package/dist/data-structures/binary-tree/binary-tree.d.ts +158 -152
  8. package/dist/data-structures/binary-tree/binary-tree.js +241 -215
  9. package/dist/data-structures/binary-tree/bst.d.ts +64 -48
  10. package/dist/data-structures/binary-tree/bst.js +94 -65
  11. package/dist/data-structures/binary-tree/rb-tree.d.ts +39 -39
  12. package/dist/data-structures/binary-tree/rb-tree.js +42 -49
  13. package/dist/data-structures/binary-tree/tree-multimap.d.ts +60 -34
  14. package/dist/data-structures/binary-tree/tree-multimap.js +59 -27
  15. package/dist/data-structures/graph/abstract-graph.d.ts +92 -53
  16. package/dist/data-structures/graph/abstract-graph.js +130 -103
  17. package/dist/data-structures/graph/directed-graph.d.ts +70 -52
  18. package/dist/data-structures/graph/directed-graph.js +111 -65
  19. package/dist/data-structures/graph/map-graph.d.ts +5 -5
  20. package/dist/data-structures/graph/map-graph.js +8 -8
  21. package/dist/data-structures/graph/undirected-graph.d.ts +51 -32
  22. package/dist/data-structures/graph/undirected-graph.js +117 -54
  23. package/dist/data-structures/hash/hash-map.d.ts +160 -44
  24. package/dist/data-structures/hash/hash-map.js +314 -82
  25. package/dist/data-structures/heap/heap.d.ts +50 -7
  26. package/dist/data-structures/heap/heap.js +60 -30
  27. package/dist/data-structures/index.d.ts +1 -0
  28. package/dist/data-structures/index.js +1 -0
  29. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +42 -55
  30. package/dist/data-structures/linked-list/doubly-linked-list.js +50 -77
  31. package/dist/data-structures/linked-list/singly-linked-list.d.ts +36 -55
  32. package/dist/data-structures/linked-list/singly-linked-list.js +44 -77
  33. package/dist/data-structures/queue/deque.d.ts +35 -167
  34. package/dist/data-structures/queue/deque.js +43 -249
  35. package/dist/data-structures/queue/queue.d.ts +49 -48
  36. package/dist/data-structures/queue/queue.js +69 -82
  37. package/dist/data-structures/stack/stack.d.ts +43 -10
  38. package/dist/data-structures/stack/stack.js +50 -31
  39. package/dist/data-structures/trie/trie.d.ts +41 -6
  40. package/dist/data-structures/trie/trie.js +53 -32
  41. package/dist/interfaces/binary-tree.d.ts +6 -6
  42. package/dist/types/common.d.ts +11 -8
  43. package/dist/types/common.js +6 -1
  44. package/dist/types/data-structures/base/base.d.ts +5 -0
  45. package/dist/types/data-structures/base/base.js +2 -0
  46. package/dist/types/data-structures/base/index.d.ts +1 -0
  47. package/dist/types/data-structures/base/index.js +17 -0
  48. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
  49. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
  50. package/dist/types/data-structures/binary-tree/bst.d.ts +6 -6
  51. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
  52. package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
  53. package/dist/types/data-structures/hash/hash-map.d.ts +4 -0
  54. package/dist/types/data-structures/index.d.ts +1 -0
  55. package/dist/types/data-structures/index.js +1 -0
  56. package/package.json +2 -2
  57. package/src/data-structures/base/index.ts +1 -0
  58. package/src/data-structures/base/iterable-base.ts +329 -0
  59. package/src/data-structures/binary-tree/avl-tree.ts +37 -25
  60. package/src/data-structures/binary-tree/binary-tree.ts +336 -296
  61. package/src/data-structures/binary-tree/bst.ts +135 -89
  62. package/src/data-structures/binary-tree/rb-tree.ts +60 -69
  63. package/src/data-structures/binary-tree/tree-multimap.ts +86 -49
  64. package/src/data-structures/graph/abstract-graph.ts +136 -104
  65. package/src/data-structures/graph/directed-graph.ts +114 -65
  66. package/src/data-structures/graph/map-graph.ts +8 -8
  67. package/src/data-structures/graph/undirected-graph.ts +124 -56
  68. package/src/data-structures/hash/hash-map.ts +335 -84
  69. package/src/data-structures/heap/heap.ts +63 -36
  70. package/src/data-structures/index.ts +1 -0
  71. package/src/data-structures/linked-list/doubly-linked-list.ts +54 -83
  72. package/src/data-structures/linked-list/singly-linked-list.ts +49 -84
  73. package/src/data-structures/queue/deque.ts +43 -275
  74. package/src/data-structures/queue/queue.ts +71 -86
  75. package/src/data-structures/stack/stack.ts +53 -34
  76. package/src/data-structures/trie/trie.ts +58 -35
  77. package/src/interfaces/binary-tree.ts +5 -6
  78. package/src/types/common.ts +11 -8
  79. package/src/types/data-structures/base/base.ts +6 -0
  80. package/src/types/data-structures/base/index.ts +1 -0
  81. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -3
  82. package/src/types/data-structures/binary-tree/binary-tree.ts +6 -5
  83. package/src/types/data-structures/binary-tree/bst.ts +6 -6
  84. package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
  85. package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -3
  86. package/src/types/data-structures/hash/hash-map.ts +2 -0
  87. package/src/types/data-structures/heap/heap.ts +1 -1
  88. package/src/types/data-structures/index.ts +1 -0
  89. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
@@ -6,7 +6,7 @@ const avl_tree_1 = require("./avl-tree");
6
6
  class TreeMultimapNode extends avl_tree_1.AVLTreeNode {
7
7
  /**
8
8
  * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
9
- * @param {BTNKey} key - The `key` parameter is of type `BTNKey` and represents the unique identifier
9
+ * @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
10
10
  * of the binary tree node.
11
11
  * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
12
12
  * tree node. If no value is provided, it will be `undefined`.
@@ -38,7 +38,7 @@ class TreeMultimap extends avl_tree_1.AVLTree {
38
38
  }
39
39
  /**
40
40
  * The function creates a new BSTNode with the given key, value, and count.
41
- * @param {BTNKey} key - The key parameter is the unique identifier for the binary tree node. It is used to
41
+ * @param {K} key - The key parameter is the unique identifier for the binary tree node. It is used to
42
42
  * distinguish one node from another in the tree.
43
43
  * @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
44
44
  * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
@@ -49,26 +49,38 @@ class TreeMultimap extends avl_tree_1.AVLTree {
49
49
  return new TreeMultimapNode(key, value, count);
50
50
  }
51
51
  createTree(options) {
52
- return new TreeMultimap([], Object.assign({ iterationType: this.iterationType, comparator: this.comparator }, options));
52
+ return new TreeMultimap([], Object.assign({ iterationType: this.iterationType, variant: this.variant }, options));
53
53
  }
54
54
  /**
55
55
  * The function checks if an exemplar is an instance of the TreeMultimapNode class.
56
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
56
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
57
57
  * @returns a boolean value indicating whether the exemplar is an instance of the TreeMultimapNode
58
58
  * class.
59
59
  */
60
60
  isNode(exemplar) {
61
61
  return exemplar instanceof TreeMultimapNode;
62
62
  }
63
+ /**
64
+ * The function "isNotNodeInstance" checks if a potential key is a K.
65
+ * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
66
+ * data type.
67
+ * @returns a boolean value indicating whether the potentialKey is of type number or not.
68
+ */
69
+ isNotNodeInstance(potentialKey) {
70
+ return !(potentialKey instanceof TreeMultimapNode);
71
+ }
63
72
  /**
64
73
  * The function `exemplarToNode` converts an exemplar object into a node object.
65
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`, where `V` represents
66
- * the value type and `N` represents the node type.
74
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, which means it
75
+ * can be one of the following:
76
+ * @param {V} [value] - The `value` parameter is an optional argument that represents the value
77
+ * associated with the node. It is of type `V`, which can be any data type. If no value is provided,
78
+ * it defaults to `undefined`.
67
79
  * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
68
- * times the node should be created. If not provided, it defaults to 1.
69
- * @returns a value of type `N` (the generic type parameter) or `undefined`.
80
+ * times the value should be added to the node. If not provided, it defaults to 1.
81
+ * @returns a node of type `N` or `undefined`.
70
82
  */
71
- exemplarToNode(exemplar, count = 1) {
83
+ exemplarToNode(exemplar, value, count = 1) {
72
84
  let node;
73
85
  if (exemplar === undefined || exemplar === null) {
74
86
  return;
@@ -85,8 +97,8 @@ class TreeMultimap extends avl_tree_1.AVLTree {
85
97
  node = this.createNode(key, value, count);
86
98
  }
87
99
  }
88
- else if (this.isNodeKey(exemplar)) {
89
- node = this.createNode(exemplar, undefined, count);
100
+ else if (this.isNotNodeInstance(exemplar)) {
101
+ node = this.createNode(exemplar, value, count);
90
102
  }
91
103
  else {
92
104
  return;
@@ -101,16 +113,20 @@ class TreeMultimap extends avl_tree_1.AVLTree {
101
113
  * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
102
114
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
103
115
  *
104
- * The `add` function overrides the base class `add` function to add a new node to the tree multimap
105
- * and update the count.
106
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
107
- * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
108
- * times the key or node or entry should be added to the multimap. If not provided, the default value
109
- * is 1.
110
- * @returns either a node (`N`) or `undefined`.
116
+ * The function overrides the add method of a binary tree node and adds a new node to the tree.
117
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
118
+ * entry. It represents the key, node, or entry that you want to add to the binary tree.
119
+ * @param {V} [value] - The `value` parameter represents the value associated with the key in the
120
+ * binary tree node. It is an optional parameter, meaning it can be omitted when calling the `add`
121
+ * method.
122
+ * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
123
+ * be added to the binary tree. By default, it is set to 1, meaning that the key-value pair will be
124
+ * added once. However, you can specify a different value for `count` if you want to add
125
+ * @returns The method is returning either the newly inserted node or `undefined` if the insertion
126
+ * was not successful.
111
127
  */
112
- add(keyOrNodeOrEntry, count = 1) {
113
- const newNode = this.exemplarToNode(keyOrNodeOrEntry, count);
128
+ add(keyOrNodeOrEntry, value, count = 1) {
129
+ const newNode = this.exemplarToNode(keyOrNodeOrEntry, value, count);
114
130
  if (newNode === undefined)
115
131
  return;
116
132
  const orgNodeCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
@@ -163,7 +179,7 @@ class TreeMultimap extends avl_tree_1.AVLTree {
163
179
  return;
164
180
  const m = l + Math.floor((r - l) / 2);
165
181
  const midNode = sorted[m];
166
- this.add([midNode.key, midNode.value], midNode.count);
182
+ this.add(midNode.key, midNode.value, midNode.count);
167
183
  buildBalanceBST(l, m - 1);
168
184
  buildBalanceBST(m + 1, r);
169
185
  };
@@ -179,7 +195,7 @@ class TreeMultimap extends avl_tree_1.AVLTree {
179
195
  if (l <= r) {
180
196
  const m = l + Math.floor((r - l) / 2);
181
197
  const midNode = sorted[m];
182
- this.add([midNode.key, midNode.value], midNode.count);
198
+ this.add(midNode.key, midNode.value, midNode.count);
183
199
  stack.push([m + 1, r]);
184
200
  stack.push([l, m - 1]);
185
201
  }
@@ -280,6 +296,22 @@ class TreeMultimap extends avl_tree_1.AVLTree {
280
296
  super.clear();
281
297
  this._count = 0;
282
298
  }
299
+ /**
300
+ * Time complexity: O(n)
301
+ * Space complexity: O(n)
302
+ */
303
+ /**
304
+ * Time complexity: O(n)
305
+ * Space complexity: O(n)
306
+ *
307
+ * The `clone` function creates a deep copy of a tree object.
308
+ * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
309
+ */
310
+ clone() {
311
+ const cloned = this.createTree();
312
+ this.bfs(node => cloned.add(node.key, node.value, node.count));
313
+ return cloned;
314
+ }
283
315
  /**
284
316
  * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
285
317
  * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
@@ -289,9 +321,9 @@ class TreeMultimap extends avl_tree_1.AVLTree {
289
321
  * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be
290
322
  * added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or
291
323
  * `undefined` if there is no node to add.
292
- * @param {BTNKey | N | undefined} parent - The `parent` parameter represents the parent node to
324
+ * @param {K | N | undefined} parent - The `parent` parameter represents the parent node to
293
325
  * which the new node will be added as a child. It can be either a node object (`N`) or a key value
294
- * (`BTNKey`).
326
+ * (`K`).
295
327
  * @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
296
328
  * added, or `undefined` if no node was added.
297
329
  */
@@ -324,9 +356,9 @@ class TreeMultimap extends avl_tree_1.AVLTree {
324
356
  }
325
357
  /**
326
358
  * The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
327
- * @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node from
328
- * which the values will be swapped. It can be of type `BTNKey`, `N`, or `undefined`.
329
- * @param {BTNKey | N | undefined} destNode - The `destNode` parameter represents the destination
359
+ * @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from
360
+ * which the values will be swapped. It can be of type `K`, `N`, or `undefined`.
361
+ * @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
330
362
  * node where the values from the source node will be swapped to.
331
363
  * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
332
364
  * if either `srcNode` or `destNode` is undefined.
@@ -1,5 +1,7 @@
1
1
  import type { DijkstraResult, VertexKey } from '../../types';
2
+ import { EntryCallback } from "../../types";
2
3
  import { IGraph } from '../../interfaces';
4
+ import { IterableEntryBase } from "../base";
3
5
  export declare abstract class AbstractVertex<V = any> {
4
6
  key: VertexKey;
5
7
  value: V | undefined;
@@ -28,9 +30,10 @@ export declare abstract class AbstractEdge<E = any> {
28
30
  protected _hashCode: string;
29
31
  get hashCode(): string;
30
32
  }
31
- 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> {
32
- protected _vertices: Map<VertexKey, VO>;
33
- get vertices(): Map<VertexKey, VO>;
33
+ export declare abstract class AbstractGraph<V = any, E = any, VO extends AbstractVertex<V> = AbstractVertex<V>, EO extends AbstractEdge<E> = AbstractEdge<E>> extends IterableEntryBase<VertexKey, V | undefined> implements IGraph<V, E, VO, EO> {
34
+ constructor();
35
+ protected _vertexMap: Map<VertexKey, VO>;
36
+ get vertexMap(): Map<VertexKey, VO>;
34
37
  /**
35
38
  * 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.
36
39
  * 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,8 +67,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
64
67
  *
65
68
  * The function "getVertex" returns the vertex with the specified ID or undefined if it doesn't exist.
66
69
  * @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`
70
+ * the `_vertexMap` map.
71
+ * @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertexMap`
69
72
  * map. If the vertex does not exist, it returns `undefined`.
70
73
  */
71
74
  getVertex(vertexKey: VertexKey): VO | undefined;
@@ -85,6 +88,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
85
88
  hasVertex(vertexOrKey: VO | VertexKey): boolean;
86
89
  addVertex(vertex: VO): boolean;
87
90
  addVertex(key: VertexKey, value?: V): boolean;
91
+ isVertexKey(potentialKey: any): potentialKey is VertexKey;
88
92
  /**
89
93
  * Time Complexity: O(1) - Constant time for Map operations.
90
94
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -100,20 +104,20 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
100
104
  */
101
105
  deleteVertex(vertexOrKey: VO | VertexKey): boolean;
102
106
  /**
103
- * Time Complexity: O(K), where K is the number of vertices to be removed.
107
+ * Time Complexity: O(K), where K is the number of vertexMap to be removed.
104
108
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
105
109
  */
106
110
  /**
107
- * Time Complexity: O(K), where K is the number of vertices to be removed.
111
+ * Time Complexity: O(K), where K is the number of vertexMap to be removed.
108
112
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
109
113
  *
110
- * The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
111
- * @param {VO[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`VO[]`) or an array
114
+ * The function removes all vertexMap from a graph and returns a boolean indicating if any vertexMap were removed.
115
+ * @param {VO[] | VertexKey[]} vertexMap - The `vertexMap` parameter can be either an array of vertexMap (`VO[]`) or an array
112
116
  * of vertex IDs (`VertexKey[]`).
113
- * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
117
+ * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertexMap
114
118
  * were removed.
115
119
  */
116
- removeManyVertices(vertices: VO[] | VertexKey[]): boolean;
120
+ removeManyVertices(vertexMap: VO[] | VertexKey[]): boolean;
117
121
  /**
118
122
  * Time Complexity: O(1) - Depends on the implementation in the concrete class.
119
123
  * Space Complexity: O(1) - Depends on the implementation in the concrete class.
@@ -122,7 +126,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
122
126
  * Time Complexity: O(1) - Depends on the implementation in the concrete class.
123
127
  * Space Complexity: O(1) - Depends on the implementation in the concrete class.
124
128
  *
125
- * The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
129
+ * The function checks if there is an edge between two vertexMap and returns a boolean value indicating the result.
126
130
  * @param {VertexKey | VO} v1 - The parameter v1 can be either a VertexKey or a VO. A VertexKey represents the unique
127
131
  * identifier of a vertex in a graph, while VO represents the type of the vertex object itself.
128
132
  * @param {VertexKey | VO} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
@@ -140,14 +144,14 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
140
144
  * Time Complexity: O(1) - Constant time for Map and Edge operations.
141
145
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
142
146
  *
143
- * The function sets the weight of an edge between two vertices in a graph.
147
+ * The function sets the weight of an edge between two vertexMap in a graph.
144
148
  * @param {VertexKey | VO} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `VO` object. It represents
145
149
  * the source vertex of the edge.
146
150
  * @param {VertexKey | VO} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
147
151
  * either a `VertexKey` or a vertex object `VO`.
148
152
  * @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrKey)
149
153
  * and the destination vertex (destOrKey).
150
- * @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
154
+ * @returns a boolean value. If the edge exists between the source and destination vertexMap, the function will update
151
155
  * the weight of the edge and return true. If the edge does not exist, the function will return false.
152
156
  */
153
157
  setEdgeWeight(srcOrKey: VertexKey | VO, destOrKey: VertexKey | VO, weight: number): boolean;
@@ -159,12 +163,12 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
159
163
  * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
160
164
  * Space Complexity: O(P) - Linear space, where P is the number of paths found.
161
165
  *
162
- * The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
166
+ * The function `getAllPathsBetween` finds all paths between two vertexMap in a graph using depth-first search.
163
167
  * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
164
168
  * It is the starting vertex for finding paths.
165
169
  * @param {VO | VertexKey} v2 - The parameter `v2` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
166
170
  * @param limit - The count of limitation of result array.
167
- * @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`VO[][]`).
171
+ * @returns The function `getAllPathsBetween` returns an array of arrays of vertexMap (`VO[][]`).
168
172
  */
169
173
  getAllPathsBetween(v1: VO | VertexKey, v2: VO | VertexKey, limit?: number): VO[][];
170
174
  /**
@@ -176,8 +180,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
176
180
  * Space Complexity: O(1) - Constant space.
177
181
  *
178
182
  * The function calculates the sum of weights along a given path.
179
- * @param {VO[]} path - An array of vertices (VO) representing a path in a graph.
180
- * @returns The function `getPathSumWeight` returns the sum of the weights of the edges in the given path.
183
+ * @param {VO[]} path - An array of vertexMap (VO) representing a path in a graph.
184
+ * @returns The function `getPathSumWeight` returns the sum of the weights of the edgeMap in the given path.
181
185
  */
182
186
  getPathSumWeight(path: VO[]): number;
183
187
  /**
@@ -188,17 +192,17 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
188
192
  * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
189
193
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
190
194
  *
191
- * The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
195
+ * The function `getMinCostBetween` calculates the minimum cost between two vertexMap in a graph, either based on edge
192
196
  * weights or using a breadth-first search algorithm.
193
197
  * @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
194
198
  * @param {VO | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
195
199
  * you want to find the minimum cost or weight from the source vertex `v1`.
196
- * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
200
+ * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edgeMap have weights.
197
201
  * If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
198
- * the edges. If isWeight is set to false or not provided, the function will calculate the
199
- * @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertices (`v1`
202
+ * the edgeMap. If isWeight is set to false or not provided, the function will calculate the
203
+ * @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertexMap (`v1`
200
204
  * and `v2`). If the `isWeight` parameter is `true`, it calculates the minimum weight among all paths between the
201
- * vertices. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
205
+ * vertexMap. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
202
206
  * minimum number of
203
207
  */
204
208
  getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number | undefined;
@@ -210,20 +214,20 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
210
214
  * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
211
215
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
212
216
  *
213
- * The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
217
+ * The function `getMinPathBetween` returns the minimum path between two vertexMap in a graph, either based on weight or
214
218
  * using a breadth-first search algorithm.
215
219
  * @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
216
220
  * object (`VO`) or a vertex ID (`VertexKey`).
217
221
  * @param {VO | VertexKey} v2 - VO | VertexKey - The second vertex or vertex ID between which we want to find the minimum
218
222
  * path.
219
- * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
223
+ * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edgeMap in finding the
220
224
  * minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
221
225
  * to false, the function will use breadth-first search (BFS) to find the minimum path.
222
226
  * @param isDFS - If set to true, it enforces the use of getAllPathsBetween to first obtain all possible paths,
223
227
  * followed by iterative computation of the shortest path. This approach may result in exponential time complexity,
224
228
  * so the default method is to use the Dijkstra algorithm to obtain the shortest weighted path.
225
- * @returns The function `getMinPathBetween` returns an array of vertices (`VO[]`) representing the minimum path between
226
- * two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `undefined`.
229
+ * @returns The function `getMinPathBetween` returns an array of vertexMap (`VO[]`) representing the minimum path between
230
+ * two vertexMap (`v1` and `v2`). If there is no path between the vertexMap, it returns `undefined`.
227
231
  */
228
232
  getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] | undefined;
229
233
  /**
@@ -238,7 +242,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
238
242
  * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
239
243
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
240
244
  *
241
- * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
245
+ * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertexMap in
242
246
  * a graph without using a heap data structure.
243
247
  * @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
244
248
  * vertex object or a vertex ID.
@@ -250,7 +254,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
250
254
  * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
251
255
  * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
252
256
  * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
253
- * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
257
+ * shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
254
258
  * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
255
259
  */
256
260
  dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
@@ -258,7 +262,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
258
262
  * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
259
263
  *
260
264
  * 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.
261
- * 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.
265
+ * 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.
262
266
  * 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.
263
267
  *
264
268
  * /
@@ -278,13 +282,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
278
282
  * start. It can be either a vertex object or a vertex ID.
279
283
  * @param {VO | VertexKey | undefined} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
280
284
  * vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
281
- * will calculate the shortest paths to all other vertices from the source vertex.
285
+ * will calculate the shortest paths to all other vertexMap from the source vertex.
282
286
  * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
283
287
  * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
284
288
  * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
285
289
  * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
286
290
  * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
287
- * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
291
+ * shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
288
292
  * @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
289
293
  */
290
294
  dijkstra(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
@@ -299,16 +303,16 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
299
303
  * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
300
304
  *
301
305
  * one to rest pairs
302
- * 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.
306
+ * 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.
303
307
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
304
- * all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
308
+ * all other vertexMap in a graph, and optionally detects negative cycles and generates the minimum path.
305
309
  * @param {VO | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
306
310
  * start calculating the shortest paths. It can be either a vertex object or a vertex ID.
307
311
  * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
308
312
  * @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
309
- * calculate the minimum distance from the source vertex to all other vertices in the graph. If `getMin` is set to
313
+ * calculate the minimum distance from the source vertex to all other vertexMap in the graph. If `getMin` is set to
310
314
  * `true`, the algorithm will find the minimum distance and update the `min` variable with the minimum
311
- * @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertices from the source
315
+ * @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertexMap from the source
312
316
  * vertex.
313
317
  * @returns The function `bellmanFord` returns an object with the following properties:
314
318
  */
@@ -331,7 +335,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
331
335
  /**
332
336
  * BellmanFord time:O(VE) space:O(VO)
333
337
  * one to rest pairs
334
- * 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.
338
+ * 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.
335
339
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
336
340
  */
337
341
  /**
@@ -339,7 +343,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
339
343
  * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
340
344
  * Not support graph with negative weight cycle
341
345
  * all pairs
342
- * 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.
346
+ * 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.
343
347
  * /
344
348
 
345
349
  /**
@@ -348,13 +352,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
348
352
  *
349
353
  * Not support graph with negative weight cycle
350
354
  * all pairs
351
- * 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.
352
- * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
355
+ * 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.
356
+ * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertexMap in a
353
357
  * graph.
354
358
  * @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
355
- * property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
356
- * `predecessor` property is a 2D array of vertices (or `undefined`) representing the predecessor vertices in the shortest
357
- * path between vertices in the
359
+ * property is a 2D array of numbers representing the shortest path costs between vertexMap in a graph. The
360
+ * `predecessor` property is a 2D array of vertexMap (or `undefined`) representing the predecessor vertexMap in the shortest
361
+ * path between vertexMap in the
358
362
  */
359
363
  floydWarshall(): {
360
364
  costs: number[][];
@@ -365,7 +369,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
365
369
  * Space Complexity: O(V) - Linear space (Tarjan's algorithm).
366
370
  * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
367
371
  * Tarjan can find cycles in directed or undirected graph
368
- * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
372
+ * Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time,
369
373
  * Tarjan solve the bi-connected components of undirected graphs;
370
374
  * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
371
375
  * /
@@ -376,22 +380,22 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
376
380
  *
377
381
  * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
378
382
  * Tarjan can find cycles in directed or undirected graph
379
- * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
383
+ * Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time,
380
384
  * Tarjan solve the bi-connected components of undirected graphs;
381
385
  * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
382
386
  * The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
383
387
  * strongly connected components (SCCs), and cycles in a graph.
384
388
  * @param {boolean} [needCutVertexes] - A boolean value indicating whether or not to calculate and return the
385
- * articulation points in the graph. Articulation points are the vertices in a graph whose removal would increase the
389
+ * articulation points in the graph. Articulation points are the vertexMap in a graph whose removal would increase the
386
390
  * number of connected components in the graph.
387
391
  * @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
388
- * (edges whose removal would increase the number of connected components in the graph).
392
+ * (edgeMap whose removal would increase the number of connected components in the graph).
389
393
  * @param {boolean} [needSCCs] - A boolean value indicating whether the Strongly Connected Components (SCCs) of the
390
394
  * graph are needed. If set to true, the function will calculate and return the SCCs of the graph. If set to false, the
391
395
  * SCCs will not be calculated or returned.
392
396
  * @param {boolean} [needCycles] - A boolean flag indicating whether the algorithm should find cycles in the graph. If
393
397
  * set to true, the algorithm will return a map of cycles, where the keys are the low values of the SCCs and the values
394
- * are arrays of vertices that form cycles within the SCCs.
398
+ * are arrays of vertexMap that form cycles within the SCCs.
395
399
  * @returns The function `tarjan` returns an object with the following properties:
396
400
  */
397
401
  tarjan(needCutVertexes?: boolean, needBridges?: boolean, needSCCs?: boolean, needCycles?: boolean): {
@@ -443,11 +447,46 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
443
447
  * @returns the bridges found using the Tarjan algorithm.
444
448
  */
445
449
  getBridges(): EO[];
446
- [Symbol.iterator](): Iterator<[VertexKey, V | undefined]>;
447
- forEach(callback: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => void): void;
448
- filter(predicate: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => boolean): [VertexKey, V | undefined][];
449
- map<T>(callback: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => T): T[];
450
- reduce<T>(callback: (accumulator: T, entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => T, initialValue: T): T;
450
+ /**
451
+ * Time Complexity: O(n)
452
+ * Space Complexity: O(n)
453
+ */
454
+ /**
455
+ * Time Complexity: O(n)
456
+ * Space Complexity: O(n)
457
+ *
458
+ * The `filter` function iterates over key-value pairs in a data structure and returns an array of
459
+ * pairs that satisfy a given predicate.
460
+ * @param predicate - The `predicate` parameter is a callback function that takes four arguments:
461
+ * `value`, `key`, `index`, and `this`. It is used to determine whether an element should be included
462
+ * in the filtered array. The callback function should return `true` if the element should be
463
+ * included, and `
464
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
465
+ * specify the value of `this` within the `predicate` function. It is used when you want to bind a
466
+ * specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
467
+ * @returns The `filter` method returns an array of key-value pairs `[VertexKey, V | undefined][]`
468
+ * that satisfy the given predicate function.
469
+ */
470
+ filter(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?: any): [VertexKey, V | undefined][];
471
+ /**
472
+ * Time Complexity: O(n)
473
+ * Space Complexity: O(n)
474
+ */
475
+ /**
476
+ * Time Complexity: O(n)
477
+ * Space Complexity: O(n)
478
+ *
479
+ * The `map` function iterates over the elements of a collection and applies a callback function to
480
+ * each element, returning an array of the results.
481
+ * @param callback - The callback parameter is a function that will be called for each element in the
482
+ * map. It takes four arguments:
483
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
484
+ * specify the value of `this` within the callback function. If `thisArg` is provided, it will be
485
+ * used as the `this` value when calling the callback function. If `thisArg` is not provided, `
486
+ * @returns The `map` function is returning an array of type `T[]`.
487
+ */
488
+ map<T>(callback: EntryCallback<VertexKey, V | undefined, T>, thisArg?: any): T[];
489
+ protected _getIterator(): IterableIterator<[VertexKey, V | undefined]>;
451
490
  protected abstract _addEdgeOnly(edge: EO): boolean;
452
491
  protected _addVertexOnly(newVertex: VO): boolean;
453
492
  protected _getVertex(vertexOrKey: VertexKey | VO): VO | undefined;