min-heap-typed 2.0.5 → 2.1.1

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 (101) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +186 -83
  2. package/dist/data-structures/base/iterable-element-base.js +149 -107
  3. package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
  4. package/dist/data-structures/base/iterable-entry-base.js +59 -116
  5. package/dist/data-structures/base/linear-base.d.ts +250 -192
  6. package/dist/data-structures/base/linear-base.js +137 -274
  7. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  8. package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
  9. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  10. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  11. package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
  12. package/dist/data-structures/binary-tree/avl-tree.js +208 -195
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
  14. package/dist/data-structures/binary-tree/binary-tree.js +602 -873
  15. package/dist/data-structures/binary-tree/bst.d.ts +258 -306
  16. package/dist/data-structures/binary-tree/bst.js +505 -481
  17. package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  18. package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
  19. package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
  20. package/dist/data-structures/binary-tree/tree-counter.js +172 -203
  21. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  22. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
  23. package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
  24. package/dist/data-structures/graph/abstract-graph.js +267 -237
  25. package/dist/data-structures/graph/directed-graph.d.ts +108 -224
  26. package/dist/data-structures/graph/directed-graph.js +146 -233
  27. package/dist/data-structures/graph/map-graph.d.ts +49 -55
  28. package/dist/data-structures/graph/map-graph.js +56 -59
  29. package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
  30. package/dist/data-structures/graph/undirected-graph.js +129 -149
  31. package/dist/data-structures/hash/hash-map.d.ts +164 -338
  32. package/dist/data-structures/hash/hash-map.js +270 -457
  33. package/dist/data-structures/heap/heap.d.ts +214 -289
  34. package/dist/data-structures/heap/heap.js +340 -349
  35. package/dist/data-structures/heap/max-heap.d.ts +11 -47
  36. package/dist/data-structures/heap/max-heap.js +11 -66
  37. package/dist/data-structures/heap/min-heap.d.ts +12 -47
  38. package/dist/data-structures/heap/min-heap.js +11 -66
  39. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  40. package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
  41. package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  42. package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
  43. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  44. package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
  45. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  46. package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
  47. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  48. package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
  49. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
  50. package/dist/data-structures/priority-queue/priority-queue.js +8 -83
  51. package/dist/data-structures/queue/deque.d.ts +227 -254
  52. package/dist/data-structures/queue/deque.js +309 -348
  53. package/dist/data-structures/queue/queue.d.ts +180 -201
  54. package/dist/data-structures/queue/queue.js +265 -248
  55. package/dist/data-structures/stack/stack.d.ts +124 -102
  56. package/dist/data-structures/stack/stack.js +181 -125
  57. package/dist/data-structures/trie/trie.d.ts +164 -165
  58. package/dist/data-structures/trie/trie.js +189 -172
  59. package/dist/interfaces/binary-tree.d.ts +56 -6
  60. package/dist/interfaces/graph.d.ts +16 -0
  61. package/dist/types/data-structures/base/base.d.ts +1 -1
  62. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
  63. package/dist/types/utils/utils.d.ts +1 -0
  64. package/dist/utils/utils.d.ts +1 -1
  65. package/dist/utils/utils.js +2 -1
  66. package/package.json +2 -2
  67. package/src/data-structures/base/iterable-element-base.ts +238 -115
  68. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  69. package/src/data-structures/base/linear-base.ts +271 -277
  70. package/src/data-structures/binary-tree/avl-tree-counter.ts +196 -217
  71. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +188 -102
  72. package/src/data-structures/binary-tree/avl-tree.ts +237 -206
  73. package/src/data-structures/binary-tree/binary-tree.ts +665 -896
  74. package/src/data-structures/binary-tree/bst.ts +565 -572
  75. package/src/data-structures/binary-tree/red-black-tree.ts +157 -223
  76. package/src/data-structures/binary-tree/tree-counter.ts +195 -219
  77. package/src/data-structures/binary-tree/tree-multi-map.ts +127 -98
  78. package/src/data-structures/graph/abstract-graph.ts +339 -264
  79. package/src/data-structures/graph/directed-graph.ts +146 -236
  80. package/src/data-structures/graph/map-graph.ts +63 -60
  81. package/src/data-structures/graph/undirected-graph.ts +129 -152
  82. package/src/data-structures/hash/hash-map.ts +274 -496
  83. package/src/data-structures/heap/heap.ts +389 -402
  84. package/src/data-structures/heap/max-heap.ts +12 -76
  85. package/src/data-structures/heap/min-heap.ts +13 -76
  86. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  87. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  88. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  89. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  90. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  91. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  92. package/src/data-structures/queue/deque.ts +381 -357
  93. package/src/data-structures/queue/queue.ts +310 -264
  94. package/src/data-structures/stack/stack.ts +217 -131
  95. package/src/data-structures/trie/trie.ts +240 -175
  96. package/src/interfaces/binary-tree.ts +240 -6
  97. package/src/interfaces/graph.ts +37 -0
  98. package/src/types/data-structures/base/base.ts +5 -5
  99. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  100. package/src/types/utils/utils.ts +2 -0
  101. package/src/utils/utils.ts +9 -14
@@ -5,43 +5,33 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { VertexKey } from '../../types';
8
+ import type { GraphOptions, VertexKey } from '../../types';
9
9
  import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
10
10
  import { IGraph } from '../../interfaces';
11
11
  export declare class DirectedVertex<V = any> extends AbstractVertex<V> {
12
- /**
13
- * The constructor function initializes a vertex with an optional value.
14
- * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
15
- * used to uniquely identify the vertex within a graph or data structure.
16
- * @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
17
- * vertex. If no value is provided, the vertex will be initialized with a default value.
18
- */
19
12
  constructor(key: VertexKey, value?: V);
20
13
  }
21
14
  export declare class DirectedEdge<E = any> extends AbstractEdge<E> {
22
15
  src: VertexKey;
23
16
  dest: VertexKey;
24
- /**
25
- * The constructor function initializes the source and destination vertexMap of an edge, along with an optional weight
26
- * and value.
27
- * @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
28
- * a graph.
29
- * @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
30
- * `VertexKey`, which is likely a unique identifier for a vertex in a graph.
31
- * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
32
- * @param {E} [value] - The `value` parameter is an optional parameter of type `E`. It represents the value associated with
33
- * the edge.
34
- */
35
17
  constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
36
18
  }
37
19
  /**
38
- *
20
+ * Directed graph implementation.
21
+ * @template V - Vertex value type.
22
+ * @template E - Edge value type.
23
+ * @template VO - Concrete vertex class (extends AbstractVertex<V>).
24
+ * @template EO - Concrete edge class (extends AbstractEdge<E>).
25
+ * @remarks Time O(1), Space O(1)
26
+ * @example examples will be generated by unit test
39
27
  */
40
28
  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> {
41
29
  /**
42
- * The constructor function initializes an instance of a class.
30
+ * Construct a directed graph with runtime defaults.
31
+ * @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
32
+ * @remarks Time O(1), Space O(1)
43
33
  */
44
- constructor();
34
+ constructor(options?: Partial<GraphOptions<V>>);
45
35
  protected _outEdgeMap: Map<VO, EO[]>;
46
36
  get outEdgeMap(): Map<VO, EO[]>;
47
37
  set outEdgeMap(v: Map<VO, EO[]>);
@@ -49,238 +39,140 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
49
39
  get inEdgeMap(): Map<VO, EO[]>;
50
40
  set inEdgeMap(v: Map<VO, EO[]>);
51
41
  /**
52
- * The function creates a new vertex with an optional value and returns it.
53
- * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
54
- * could be a number or a string depending on how you want to identify your vertexMap.
55
- * @param [value] - The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided,
56
- * it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be
57
- * assigned the same value as the 'key' parameter
58
- * @returns a new instance of a DirectedVertex object, casted as type VO.
42
+ * Construct a directed graph from keys with value initializer `v => v`.
43
+ * @template K - Vertex key type.
44
+ * @param keys - Iterable of vertex keys.
45
+ * @returns DirectedGraph with all keys added.
46
+ * @remarks Time O(V), Space O(V)
47
+ */
48
+ static fromKeys<K extends VertexKey>(keys: Iterable<K>): DirectedGraph<K, any, DirectedVertex<K>, DirectedEdge<any>>;
49
+ /**
50
+ * Construct a directed graph from `[key, value]` entries.
51
+ * @template V - Vertex value type.
52
+ * @param entries - Iterable of `[key, value]` pairs.
53
+ * @returns DirectedGraph with all vertices added.
54
+ * @remarks Time O(V), Space O(V)
59
55
  */
60
- createVertex(key: VertexKey, value?: V): VO;
56
+ static fromEntries<V>(entries: Iterable<[VertexKey, V]>): DirectedGraph<V, any, DirectedVertex<V>, DirectedEdge<any>>;
61
57
  /**
62
- * The function creates a directed edge between two vertexMap with an optional weight and value.
63
- * @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
64
- * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
65
- * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
66
- * weight is provided, it defaults to 1.
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
- * is used to store additional information or data associated with the edge.
69
- * @returns a new instance of a DirectedEdge object, casted as type EO.
58
+ * Create a directed vertex instance. Does not insert into the graph.
59
+ * @param key - Vertex identifier.
60
+ * @param value - Optional payload.
61
+ * @returns Concrete vertex instance.
62
+ * @remarks Time O(1), Space O(1)
63
+ */
64
+ createVertex(key: VertexKey, value?: VO['value']): VO;
65
+ /**
66
+ * Create a directed edge instance. Does not insert into the graph.
67
+ * @param src - Source vertex key.
68
+ * @param dest - Destination vertex key.
69
+ * @param weight - Edge weight; defaults to `defaultEdgeWeight`.
70
+ * @param value - Edge payload.
71
+ * @returns Concrete edge instance.
72
+ * @remarks Time O(1), Space O(1)
70
73
  */
71
74
  createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
72
75
  /**
73
- * Time Complexity: O(|V|) where |V| is the number of vertexMap
74
- * Space Complexity: O(1)
75
- *
76
- * The `getEdge` function retrieves an edge between two vertexMap based on their source and destination IDs.
77
- * @param {VO | VertexKey | undefined} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
78
- * @param {VO | VertexKey | undefined} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
79
- * destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `undefined` if the
80
- * destination is not specified.
81
- * @returns the first edge found between the source and destination vertexMap, or undefined if no such edge is found.
76
+ * Get the unique edge from `src` to `dest`, if present.
77
+ * @param srcOrKey - Source vertex or key.
78
+ * @param destOrKey - Destination vertex or key.
79
+ * @returns Edge instance or `undefined`.
80
+ * @remarks Time O(1) avg, Space O(1)
82
81
  */
83
82
  getEdge(srcOrKey: VO | VertexKey | undefined, destOrKey: VO | VertexKey | undefined): EO | undefined;
84
83
  /**
85
- * Time Complexity: O(|E|) where |E| is the number of edgeMap
86
- * Space Complexity: O(1)
87
- *
88
- * The function removes an edge between two vertexMap in a graph and returns the removed edge.
89
- * @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
90
- * @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
91
- * @returns the removed edge (EO) if it exists, or undefined if either the source or destination vertex does not exist.
84
+ * Delete edge `src -> dest` if present.
85
+ * @param srcOrKey - Source vertex or key.
86
+ * @param destOrKey - Destination vertex or key.
87
+ * @returns Removed edge or `undefined`.
88
+ * @remarks Time O(1) avg, Space O(1)
92
89
  */
93
90
  deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
94
91
  /**
95
- * Time Complexity: O(E) where E is the number of edgeMap
96
- * Space Complexity: O(1)
97
- *
98
- * The `deleteEdge` function removes an edge from a graph and returns the removed edge.
99
- * @param {EO | VertexKey} edgeOrSrcVertexKey - The `edge` parameter can be either an `EO` object (edge object) or
100
- * a `VertexKey` (key of a vertex).
101
- * @param {VertexKey} [destVertexKey] - The `destVertexKey` parameter is an optional parameter that
102
- * represents the key of the destination vertex of the edge. It is used to specify the destination
103
- * vertex when the `edge` parameter is a vertex key. If `destVertexKey` is not provided, the function
104
- * assumes that the `edge`
105
- * @returns the removed edge (EO) or undefined if no edge was removed.
92
+ * Delete an edge by instance or by `(srcKey, destKey)`.
93
+ * @param edgeOrSrcVertexKey - Edge instance or source vertex/key.
94
+ * @param destVertexKey - Optional destination vertex/key when deleting by pair.
95
+ * @returns Removed edge or `undefined`.
96
+ * @remarks Time O(1) avg, Space O(1)
106
97
  */
107
98
  deleteEdge(edgeOrSrcVertexKey: EO | VertexKey, destVertexKey?: VertexKey): EO | undefined;
108
- /**
109
- * Time Complexity: O(1) - Constant time for Map operations.
110
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
111
- *
112
- * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
113
- * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
114
- * (`VertexKey`).
115
- * @returns The method is returning a boolean value.
116
- */
117
99
  deleteVertex(vertexOrKey: VO | VertexKey): boolean;
118
- /**
119
- * Time Complexity: O(|E|) where |E| is the number of edgeMap
120
- * Space Complexity: O(1)
121
- *
122
- * The function removes edgeMap between two vertexMap and returns the removed edgeMap.
123
- * @param {VertexKey | VO} v1 - The parameter `v1` can be either a `VertexKey` or a `VO`. A `VertexKey` represents the
124
- * unique identifier of a vertex in a graph, while `VO` represents the actual vertex object.
125
- * @param {VertexKey | VO} v2 - The parameter `v2` represents either a `VertexKey` or a `VO` object. It is used to specify
126
- * the second vertex in the edge that needs to be removed.
127
- * @returns an array of removed edgeMap (EO[]).
128
- */
129
100
  deleteEdgesBetween(v1: VertexKey | VO, v2: VertexKey | VO): EO[];
130
101
  /**
131
- * Time Complexity: O(1)
132
- * Space Complexity: O(1)
133
- *
134
- * The function `incomingEdgesOf` returns an array of incoming edgeMap for a given vertex or vertex ID.
135
- * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
136
- * (`VertexKey`).
137
- * @returns The method `incomingEdgesOf` returns an array of edgeMap (`EO[]`).
102
+ * Incoming edges of a vertex.
103
+ * @param vertexOrKey - Vertex or key.
104
+ * @returns Array of incoming edges.
105
+ * @remarks Time O(deg_in), Space O(deg_in)
138
106
  */
139
107
  incomingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
140
108
  /**
141
- * Time Complexity: O(1)
142
- * Space Complexity: O(1)
143
- *
144
- * The function `outgoingEdgesOf` returns an array of outgoing edgeMap from a given vertex or vertex ID.
145
- * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`VO`) or a vertex ID
146
- * (`VertexKey`).
147
- * @returns The method `outgoingEdgesOf` returns an array of edgeMap (`EO[]`).
109
+ * Outgoing edges of a vertex.
110
+ * @param vertexOrKey - Vertex or key.
111
+ * @returns Array of outgoing edges.
112
+ * @remarks Time O(deg_out), Space O(deg_out)
148
113
  */
149
114
  outgoingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
150
115
  /**
151
- * Time Complexity: O(1)
152
- * Space Complexity: O(1)
153
- *
154
- * The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
155
- * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
156
- * @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
116
+ * Degree (in + out) of a vertex.
117
+ * @param vertexOrKey - Vertex or key.
118
+ * @returns Non-negative integer.
119
+ * @remarks Time O(1) avg, Space O(1)
157
120
  */
158
121
  degreeOf(vertexOrKey: VertexKey | VO): number;
159
- /**
160
- * Time Complexity: O(1)
161
- * Space Complexity: O(1)
162
- *
163
- * The function "inDegreeOf" returns the number of incoming edgeMap for a given vertex.
164
- * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
165
- * @returns The number of incoming edgeMap of the specified vertex or vertex ID.
166
- */
167
122
  inDegreeOf(vertexOrKey: VertexKey | VO): number;
168
- /**
169
- * Time Complexity: O(1)
170
- * Space Complexity: O(1)
171
- *
172
- * The function `outDegreeOf` returns the number of outgoing edgeMap from a given vertex.
173
- * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
174
- * @returns The number of outgoing edgeMap from the specified vertex or vertex ID.
175
- */
176
123
  outDegreeOf(vertexOrKey: VertexKey | VO): number;
177
124
  /**
178
- * Time Complexity: O(1)
179
- * Space Complexity: O(1)
180
- *
181
- * The function "edgesOf" returns an array of both outgoing and incoming edgeMap of a given vertex or vertex ID.
182
- * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
183
- * @returns The function `edgesOf` returns an array of edgeMap.
125
+ * All incident edges of a vertex.
126
+ * @param vertexOrKey - Vertex or key.
127
+ * @returns Array of incident edges.
128
+ * @remarks Time O(deg_in + deg_out), Space O(deg_in + deg_out)
184
129
  */
185
130
  edgesOf(vertexOrKey: VertexKey | VO): EO[];
186
- /**
187
- * Time Complexity: O(1)
188
- * Space Complexity: O(1)
189
- *
190
- * The function "getEdgeSrc" returns the source vertex of an edge, or undefined if the edge does not exist.
191
- * @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
192
- * @returns either a vertex object (VO) or undefined.
193
- */
194
131
  getEdgeSrc(e: EO): VO | undefined;
195
- /**
196
- * Time Complexity: O(1)
197
- * Space Complexity: O(1)
198
- *
199
- * The function "getEdgeDest" returns the destination vertex of an edge.
200
- * @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
201
- * @returns either a vertex object of type VO or undefined.
202
- */
203
132
  getEdgeDest(e: EO): VO | undefined;
204
133
  /**
205
- * Time Complexity: O(|E|) where |E| is the number of edgeMap
206
- * Space Complexity: O(1)
207
- *
208
- * The function `getDestinations` returns an array of destination vertexMap connected to a given vertex.
209
- * @param {VO | VertexKey | undefined} vertex - The `vertex` parameter represents the starting vertex from which we want to
210
- * find the destinations. It can be either a `VO` object, a `VertexKey` value, or `undefined`.
211
- * @returns an array of vertexMap (VO[]).
134
+ * Direct children reachable by one outgoing edge.
135
+ * @param vertex - Vertex or key.
136
+ * @returns Array of neighbor vertices.
137
+ * @remarks Time O(deg_out), Space O(deg_out)
212
138
  */
213
139
  getDestinations(vertex: VO | VertexKey | undefined): VO[];
214
140
  /**
215
- * Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
216
- * Space Complexity: O(|V|)
217
- *
218
- * The `topologicalSort` function performs a topological sort on a graph and returns an array of vertexMap or vertex IDs
219
- * in the sorted order, or undefined if the graph contains a cycle.
220
- * @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
221
- * property to use for sorting the vertexMap. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
222
- * specified, the vertexMap themselves will be used for sorting. If 'key' is specified, the ids of
223
- * @returns an array of vertexMap or vertex IDs in topological order. If there is a cycle in the graph, it returns undefined.
141
+ * Topological sort if DAG; returns `undefined` if a cycle exists.
142
+ * @param propertyName - `'key'` to map to keys; `'vertex'` to keep instances.
143
+ * @returns Array of keys/vertices, or `undefined` when cycle is found.
144
+ * @remarks Time O(V + E), Space O(V)
224
145
  */
225
146
  topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | undefined;
226
- /**
227
- * Time Complexity: O(|E|) where |E| is the number of edgeMap
228
- * Space Complexity: O(|E|)
229
- *
230
- * The `edgeSet` function returns an array of all the edgeMap in the graph.
231
- * @returns The `edgeSet()` method returns an array of edgeMap (`EO[]`).
232
- */
233
147
  edgeSet(): EO[];
234
- /**
235
- * Time Complexity: O(|E|) where |E| is the number of edgeMap
236
- * Space Complexity: O(1)
237
- *
238
- * The function `getNeighbors` returns an array of neighboring vertexMap of a given vertex or vertex ID in a graph.
239
- * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
240
- * (`VertexKey`).
241
- * @returns an array of vertexMap (VO[]).
242
- */
243
148
  getNeighbors(vertexOrKey: VO | VertexKey): VO[];
244
149
  /**
245
- * Time Complexity: O(1)
246
- * Space Complexity: O(1)
247
- *
248
- * The function "getEndsOfEdge" returns the source and destination vertexMap of an edge if it exists in the graph,
249
- * otherwise it returns undefined.
250
- * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
251
- * @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
252
- * graph. If the edge does not exist, it returns `undefined`.
150
+ * Resolve an edge's `[src, dest]` endpoints to vertex instances.
151
+ * @param edge - Edge instance.
152
+ * @returns `[src, dest]` or `undefined` if either endpoint is missing.
153
+ * @remarks Time O(1), Space O(1)
253
154
  */
254
155
  getEndsOfEdge(edge: EO): [VO, VO] | undefined;
255
156
  /**
256
- * The isEmpty function checks if the graph is empty.
257
- *
258
- * @return A boolean value
157
+ * Whether the graph has no vertices and no edges.
158
+ * @remarks Time O(1), Space O(1)
259
159
  */
260
160
  isEmpty(): boolean;
261
161
  /**
262
- * Time Complexity: O(1)
263
- * Space Complexity: O(1)
264
- *
265
- * The clear function resets the vertex map, in-edge map, and out-edge map.
162
+ * Remove all vertices and edges.
163
+ * @remarks Time O(V + E), Space O(1)
266
164
  */
267
165
  clear(): void;
268
166
  /**
269
- * The clone function creates a new DirectedGraph object with the same vertices and edges as the original.
270
- *
271
- * @return A new instance of the directedgraph class
167
+ * Deep clone as the same concrete class.
168
+ * @returns A new graph of the same concrete class (`this` type).
169
+ * @remarks Time O(V + E), Space O(V + E)
272
170
  */
273
- clone(): DirectedGraph<V, E, VO, EO>;
171
+ clone(): this;
274
172
  /**
275
- * Time Complexity: O(V + E)
276
- * Space Complexity: O(V)
277
- * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
278
- * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
279
- *
280
- * The function `tarjan` implements the Tarjan's algorithm to find strongly connected components in a
281
- * graph.
282
- * @returns The function `tarjan()` returns an object with three properties: `dfnMap`, `lowMap`, and
283
- * `SCCs`.
173
+ * Tarjan's algorithm for strongly connected components.
174
+ * @returns `{ dfnMap, lowMap, SCCs }`.
175
+ * @remarks Time O(V + E), Space O(V + E)
284
176
  */
285
177
  tarjan(): {
286
178
  dfnMap: Map<VO, number>;
@@ -288,36 +180,28 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
288
180
  SCCs: Map<number, VO[]>;
289
181
  };
290
182
  /**
291
- * Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
292
- * Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
293
- *
294
- * The function returns a map that associates each vertex object with its corresponding depth-first
295
- * number.
296
- * @returns A Map object with keys of type VO and values of type number.
183
+ * DFN index map computed by `tarjan()`.
184
+ * @returns Map from vertex to DFN index.
185
+ * @remarks Time O(V), Space O(V)
297
186
  */
298
187
  getDFNMap(): Map<VO, number>;
299
188
  /**
300
- * The function returns a Map object that contains the low values of each vertex in a Tarjan
301
- * algorithm.
302
- * @returns The method `getLowMap()` is returning a `Map` object with keys of type `VO` and values of
303
- * type `number`.
189
+ * LOW link map computed by `tarjan()`.
190
+ * @returns Map from vertex to LOW value.
191
+ * @remarks Time O(V), Space O(V)
304
192
  */
305
193
  getLowMap(): Map<VO, number>;
306
194
  /**
307
- * The function "getSCCs" returns a map of strongly connected components (SCCs) using the Tarjan
308
- * algorithm.
309
- * @returns a map where the keys are numbers and the values are arrays of VO objects.
195
+ * Strongly connected components computed by `tarjan()`.
196
+ * @returns Map from SCC id to vertices.
197
+ * @remarks Time O(#SCC + V), Space O(V)
310
198
  */
311
199
  getSCCs(): Map<number, VO[]>;
312
200
  /**
313
- * Time Complexity: O(1)
314
- * Space Complexity: O(1)
315
- *
316
- * The function `_addEdge` adds an edge to a graph if the source and destination vertexMap exist.
317
- * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
318
- * needs to be added to the graph.
319
- * @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
320
- * source or destination vertex does not exist in the graph.
201
+ * Internal hook to attach a directed edge into adjacency maps.
202
+ * @param edge - Edge instance.
203
+ * @returns `true` if inserted; otherwise `false`.
204
+ * @remarks Time O(1) avg, Space O(1)
321
205
  */
322
206
  protected _addEdge(edge: EO): boolean;
323
207
  }