data-structure-typed 1.42.7 → 1.42.9
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.
- package/CHANGELOG.md +1 -1
- package/README.md +13 -13
- package/benchmark/report.html +12 -12
- package/benchmark/report.json +106 -106
- package/dist/cjs/src/data-structures/binary-tree/avl-tree.d.ts +88 -23
- package/dist/cjs/src/data-structures/binary-tree/avl-tree.js +88 -23
- package/dist/cjs/src/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/src/data-structures/binary-tree/binary-tree.d.ts +180 -74
- package/dist/cjs/src/data-structures/binary-tree/binary-tree.js +388 -201
- package/dist/cjs/src/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/src/data-structures/binary-tree/bst.d.ts +121 -66
- package/dist/cjs/src/data-structures/binary-tree/bst.js +121 -67
- package/dist/cjs/src/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/src/data-structures/binary-tree/rb-tree.d.ts +72 -5
- package/dist/cjs/src/data-structures/binary-tree/rb-tree.js +95 -18
- package/dist/cjs/src/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/src/data-structures/binary-tree/tree-multimap.d.ts +82 -43
- package/dist/cjs/src/data-structures/binary-tree/tree-multimap.js +82 -43
- package/dist/cjs/src/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/src/data-structures/graph/abstract-graph.d.ts +139 -36
- package/dist/cjs/src/data-structures/graph/abstract-graph.js +147 -36
- package/dist/cjs/src/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/src/data-structures/graph/directed-graph.d.ts +126 -0
- package/dist/cjs/src/data-structures/graph/directed-graph.js +126 -0
- package/dist/cjs/src/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/src/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/cjs/src/data-structures/graph/undirected-graph.js +63 -0
- package/dist/cjs/src/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/src/data-structures/heap/heap.d.ts +175 -12
- package/dist/cjs/src/data-structures/heap/heap.js +175 -12
- package/dist/cjs/src/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/src/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
- package/dist/cjs/src/data-structures/linked-list/doubly-linked-list.js +203 -0
- package/dist/cjs/src/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/src/data-structures/linked-list/singly-linked-list.d.ts +182 -0
- package/dist/cjs/src/data-structures/linked-list/singly-linked-list.js +182 -0
- package/dist/cjs/src/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/src/data-structures/linked-list/skip-linked-list.d.ts +64 -0
- package/dist/cjs/src/data-structures/linked-list/skip-linked-list.js +64 -0
- package/dist/cjs/src/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/src/data-structures/queue/deque.d.ts +113 -3
- package/dist/cjs/src/data-structures/queue/deque.js +113 -3
- package/dist/cjs/src/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/src/data-structures/queue/queue.d.ts +87 -0
- package/dist/cjs/src/data-structures/queue/queue.js +87 -0
- package/dist/cjs/src/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/src/data-structures/stack/stack.d.ts +42 -0
- package/dist/cjs/src/data-structures/stack/stack.js +42 -0
- package/dist/cjs/src/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/src/data-structures/trie/trie.d.ts +76 -0
- package/dist/cjs/src/data-structures/trie/trie.js +76 -1
- package/dist/cjs/src/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/src/data-structures/binary-tree/avl-tree.d.ts +88 -23
- package/dist/mjs/src/data-structures/binary-tree/avl-tree.js +88 -23
- package/dist/mjs/src/data-structures/binary-tree/binary-tree.d.ts +180 -74
- package/dist/mjs/src/data-structures/binary-tree/binary-tree.js +388 -201
- package/dist/mjs/src/data-structures/binary-tree/bst.d.ts +121 -66
- package/dist/mjs/src/data-structures/binary-tree/bst.js +121 -67
- package/dist/mjs/src/data-structures/binary-tree/rb-tree.d.ts +72 -5
- package/dist/mjs/src/data-structures/binary-tree/rb-tree.js +95 -18
- package/dist/mjs/src/data-structures/binary-tree/tree-multimap.d.ts +82 -43
- package/dist/mjs/src/data-structures/binary-tree/tree-multimap.js +82 -43
- package/dist/mjs/src/data-structures/graph/abstract-graph.d.ts +139 -36
- package/dist/mjs/src/data-structures/graph/abstract-graph.js +147 -36
- package/dist/mjs/src/data-structures/graph/directed-graph.d.ts +126 -0
- package/dist/mjs/src/data-structures/graph/directed-graph.js +126 -0
- package/dist/mjs/src/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/mjs/src/data-structures/graph/undirected-graph.js +63 -0
- package/dist/mjs/src/data-structures/heap/heap.d.ts +175 -12
- package/dist/mjs/src/data-structures/heap/heap.js +175 -12
- package/dist/mjs/src/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
- package/dist/mjs/src/data-structures/linked-list/doubly-linked-list.js +203 -0
- package/dist/mjs/src/data-structures/linked-list/singly-linked-list.d.ts +182 -0
- package/dist/mjs/src/data-structures/linked-list/singly-linked-list.js +182 -0
- package/dist/mjs/src/data-structures/linked-list/skip-linked-list.d.ts +64 -0
- package/dist/mjs/src/data-structures/linked-list/skip-linked-list.js +64 -0
- package/dist/mjs/src/data-structures/queue/deque.d.ts +113 -3
- package/dist/mjs/src/data-structures/queue/deque.js +113 -3
- package/dist/mjs/src/data-structures/queue/queue.d.ts +87 -0
- package/dist/mjs/src/data-structures/queue/queue.js +87 -0
- package/dist/mjs/src/data-structures/stack/stack.d.ts +42 -0
- package/dist/mjs/src/data-structures/stack/stack.js +42 -0
- package/dist/mjs/src/data-structures/trie/trie.d.ts +76 -0
- package/dist/mjs/src/data-structures/trie/trie.js +76 -1
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +97 -23
- package/src/data-structures/binary-tree/binary-tree.ts +419 -204
- package/src/data-structures/binary-tree/bst.ts +130 -68
- package/src/data-structures/binary-tree/rb-tree.ts +106 -19
- package/src/data-structures/binary-tree/tree-multimap.ts +88 -44
- package/src/data-structures/graph/abstract-graph.ts +133 -7
- package/src/data-structures/graph/directed-graph.ts +145 -1
- package/src/data-structures/graph/undirected-graph.ts +72 -0
- package/src/data-structures/heap/heap.ts +201 -12
- package/src/data-structures/linked-list/doubly-linked-list.ts +232 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +208 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +74 -0
- package/src/data-structures/queue/deque.ts +127 -3
- package/src/data-structures/queue/queue.ts +99 -0
- package/src/data-structures/stack/stack.ts +48 -0
- package/src/data-structures/trie/trie.ts +87 -4
- package/test/integration/index.html +24 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +19 -2
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +0 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -1
|
@@ -93,6 +93,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
93
93
|
return new DirectedEdge(src, dest, weight ?? 1, value);
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
|
+
* Time Complexity: O(|V|) where |V| is the number of vertices
|
|
97
|
+
* Space Complexity: O(1)
|
|
98
|
+
*/
|
|
99
|
+
/**
|
|
100
|
+
* Time Complexity: O(|V|) where |V| is the number of vertices
|
|
101
|
+
* Space Complexity: O(1)
|
|
102
|
+
*
|
|
96
103
|
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
97
104
|
* @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
98
105
|
* @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
@@ -115,6 +122,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
115
122
|
return edges[0] || null;
|
|
116
123
|
}
|
|
117
124
|
/**
|
|
125
|
+
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
126
|
+
* Space Complexity: O(1)
|
|
127
|
+
*/
|
|
128
|
+
/**
|
|
129
|
+
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
130
|
+
* Space Complexity: O(1)
|
|
131
|
+
*
|
|
118
132
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
119
133
|
* @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
|
|
120
134
|
* @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
@@ -138,6 +152,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
138
152
|
return removed;
|
|
139
153
|
}
|
|
140
154
|
/**
|
|
155
|
+
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
156
|
+
* Space Complexity: O(1)
|
|
157
|
+
*/
|
|
158
|
+
/**
|
|
159
|
+
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
160
|
+
* Space Complexity: O(1)
|
|
161
|
+
*
|
|
141
162
|
* The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
|
|
142
163
|
* @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
143
164
|
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
@@ -160,6 +181,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
160
181
|
return removed;
|
|
161
182
|
}
|
|
162
183
|
/**
|
|
184
|
+
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
185
|
+
* Space Complexity: O(1)
|
|
186
|
+
*/
|
|
187
|
+
/**
|
|
188
|
+
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
189
|
+
* Space Complexity: O(1)
|
|
190
|
+
*
|
|
163
191
|
* The function removes edges between two vertices and returns the removed edges.
|
|
164
192
|
* @param {VertexKey | VO} v1 - The parameter `v1` can be either a `VertexKey` or a `VO`. A `VertexKey` represents the
|
|
165
193
|
* unique identifier of a vertex in a graph, while `VO` represents the actual vertex object.
|
|
@@ -178,6 +206,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
178
206
|
return removed;
|
|
179
207
|
}
|
|
180
208
|
/**
|
|
209
|
+
* Time Complexity: O(1)
|
|
210
|
+
* Space Complexity: O(1)
|
|
211
|
+
*/
|
|
212
|
+
/**
|
|
213
|
+
* Time Complexity: O(1)
|
|
214
|
+
* Space Complexity: O(1)
|
|
215
|
+
*
|
|
181
216
|
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
|
|
182
217
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
183
218
|
* (`VertexKey`).
|
|
@@ -191,6 +226,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
191
226
|
return [];
|
|
192
227
|
}
|
|
193
228
|
/**
|
|
229
|
+
* Time Complexity: O(1)
|
|
230
|
+
* Space Complexity: O(1)
|
|
231
|
+
*/
|
|
232
|
+
/**
|
|
233
|
+
* Time Complexity: O(1)
|
|
234
|
+
* Space Complexity: O(1)
|
|
235
|
+
*
|
|
194
236
|
* The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
|
|
195
237
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`VO`) or a vertex ID
|
|
196
238
|
* (`VertexKey`).
|
|
@@ -204,6 +246,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
204
246
|
return [];
|
|
205
247
|
}
|
|
206
248
|
/**
|
|
249
|
+
* Time Complexity: O(1)
|
|
250
|
+
* Space Complexity: O(1)
|
|
251
|
+
*/
|
|
252
|
+
/**
|
|
253
|
+
* Time Complexity: O(1)
|
|
254
|
+
* Space Complexity: O(1)
|
|
255
|
+
*
|
|
207
256
|
* The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
|
|
208
257
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
209
258
|
* @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
|
|
@@ -212,6 +261,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
212
261
|
return this.outDegreeOf(vertexOrKey) + this.inDegreeOf(vertexOrKey);
|
|
213
262
|
}
|
|
214
263
|
/**
|
|
264
|
+
* Time Complexity: O(1)
|
|
265
|
+
* Space Complexity: O(1)
|
|
266
|
+
*/
|
|
267
|
+
/**
|
|
268
|
+
* Time Complexity: O(1)
|
|
269
|
+
* Space Complexity: O(1)
|
|
270
|
+
*
|
|
215
271
|
* The function "inDegreeOf" returns the number of incoming edges for a given vertex.
|
|
216
272
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
217
273
|
* @returns The number of incoming edges of the specified vertex or vertex ID.
|
|
@@ -220,6 +276,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
220
276
|
return this.incomingEdgesOf(vertexOrKey).length;
|
|
221
277
|
}
|
|
222
278
|
/**
|
|
279
|
+
* Time Complexity: O(1)
|
|
280
|
+
* Space Complexity: O(1)
|
|
281
|
+
*/
|
|
282
|
+
/**
|
|
283
|
+
* Time Complexity: O(1)
|
|
284
|
+
* Space Complexity: O(1)
|
|
285
|
+
*
|
|
223
286
|
* The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
|
|
224
287
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
225
288
|
* @returns The number of outgoing edges from the specified vertex or vertex ID.
|
|
@@ -228,6 +291,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
228
291
|
return this.outgoingEdgesOf(vertexOrKey).length;
|
|
229
292
|
}
|
|
230
293
|
/**
|
|
294
|
+
* Time Complexity: O(1)
|
|
295
|
+
* Space Complexity: O(1)
|
|
296
|
+
*/
|
|
297
|
+
/**
|
|
298
|
+
* Time Complexity: O(1)
|
|
299
|
+
* Space Complexity: O(1)
|
|
300
|
+
*
|
|
231
301
|
* The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
|
|
232
302
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
233
303
|
* @returns The function `edgesOf` returns an array of edges.
|
|
@@ -236,6 +306,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
236
306
|
return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
|
|
237
307
|
}
|
|
238
308
|
/**
|
|
309
|
+
* Time Complexity: O(1)
|
|
310
|
+
* Space Complexity: O(1)
|
|
311
|
+
*/
|
|
312
|
+
/**
|
|
313
|
+
* Time Complexity: O(1)
|
|
314
|
+
* Space Complexity: O(1)
|
|
315
|
+
*
|
|
239
316
|
* The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
|
|
240
317
|
* @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
|
|
241
318
|
* @returns either a vertex object (VO) or null.
|
|
@@ -244,6 +321,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
244
321
|
return this._getVertex(e.src);
|
|
245
322
|
}
|
|
246
323
|
/**
|
|
324
|
+
* Time Complexity: O(1)
|
|
325
|
+
* Space Complexity: O(1)
|
|
326
|
+
*/
|
|
327
|
+
/**
|
|
328
|
+
* Time Complexity: O(1)
|
|
329
|
+
* Space Complexity: O(1)
|
|
330
|
+
*
|
|
247
331
|
* The function "getEdgeDest" returns the destination vertex of an edge.
|
|
248
332
|
* @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
|
|
249
333
|
* @returns either a vertex object of type VO or null.
|
|
@@ -252,6 +336,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
252
336
|
return this._getVertex(e.dest);
|
|
253
337
|
}
|
|
254
338
|
/**
|
|
339
|
+
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
340
|
+
* Space Complexity: O(1)
|
|
341
|
+
*/
|
|
342
|
+
/**
|
|
343
|
+
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
344
|
+
* Space Complexity: O(1)
|
|
345
|
+
*
|
|
255
346
|
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
|
|
256
347
|
* @param {VO | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
257
348
|
* find the destinations. It can be either a `VO` object, a `VertexKey` value, or `null`.
|
|
@@ -272,6 +363,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
272
363
|
return destinations;
|
|
273
364
|
}
|
|
274
365
|
/**
|
|
366
|
+
* Time Complexity: O(|V| + |E|) where |V| is the number of vertices and |E| is the number of edges
|
|
367
|
+
* Space Complexity: O(|V|)
|
|
368
|
+
*/
|
|
369
|
+
/**
|
|
370
|
+
* Time Complexity: O(|V| + |E|) where |V| is the number of vertices and |E| is the number of edges
|
|
371
|
+
* Space Complexity: O(|V|)
|
|
372
|
+
*
|
|
275
373
|
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
|
|
276
374
|
* in the sorted order, or null if the graph contains a cycle.
|
|
277
375
|
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
@@ -316,6 +414,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
316
414
|
return sorted.reverse();
|
|
317
415
|
}
|
|
318
416
|
/**
|
|
417
|
+
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
418
|
+
* Space Complexity: O(|E|)
|
|
419
|
+
*/
|
|
420
|
+
/**
|
|
421
|
+
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
422
|
+
* Space Complexity: O(|E|)
|
|
423
|
+
*
|
|
319
424
|
* The `edgeSet` function returns an array of all the edges in the graph.
|
|
320
425
|
* @returns The `edgeSet()` method returns an array of edges (`EO[]`).
|
|
321
426
|
*/
|
|
@@ -327,6 +432,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
327
432
|
return edges;
|
|
328
433
|
}
|
|
329
434
|
/**
|
|
435
|
+
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
436
|
+
* Space Complexity: O(1)
|
|
437
|
+
*/
|
|
438
|
+
/**
|
|
439
|
+
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
440
|
+
* Space Complexity: O(1)
|
|
441
|
+
*
|
|
330
442
|
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
|
|
331
443
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
332
444
|
* (`VertexKey`).
|
|
@@ -348,6 +460,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
348
460
|
return neighbors;
|
|
349
461
|
}
|
|
350
462
|
/**
|
|
463
|
+
* Time Complexity: O(1)
|
|
464
|
+
* Space Complexity: O(1)
|
|
465
|
+
*/
|
|
466
|
+
/**
|
|
467
|
+
* Time Complexity: O(1)
|
|
468
|
+
* Space Complexity: O(1)
|
|
469
|
+
*
|
|
351
470
|
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
|
|
352
471
|
* otherwise it returns null.
|
|
353
472
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
|
|
@@ -368,6 +487,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
368
487
|
}
|
|
369
488
|
}
|
|
370
489
|
/**
|
|
490
|
+
* Time Complexity: O(1)
|
|
491
|
+
* Space Complexity: O(1)
|
|
492
|
+
*/
|
|
493
|
+
/**
|
|
494
|
+
* Time Complexity: O(1)
|
|
495
|
+
* Space Complexity: O(1)
|
|
496
|
+
*
|
|
371
497
|
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
|
|
372
498
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
|
|
373
499
|
* needs to be added to the graph.
|
|
@@ -54,6 +54,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
54
54
|
*/
|
|
55
55
|
createEdge(v1: VertexKey, v2: VertexKey, weight?: number, value?: EO['value']): EO;
|
|
56
56
|
/**
|
|
57
|
+
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
58
|
+
* Space Complexity: O(1)
|
|
59
|
+
*/
|
|
60
|
+
/**
|
|
61
|
+
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
62
|
+
* Space Complexity: O(1)
|
|
63
|
+
*
|
|
57
64
|
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
58
65
|
* @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
59
66
|
* object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
@@ -63,6 +70,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
63
70
|
*/
|
|
64
71
|
getEdge(v1: VO | VertexKey | null, v2: VO | VertexKey | null): EO | null;
|
|
65
72
|
/**
|
|
73
|
+
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
74
|
+
* Space Complexity: O(1)
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
78
|
+
* Space Complexity: O(1)
|
|
79
|
+
*
|
|
66
80
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
67
81
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
68
82
|
* @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
|
|
@@ -71,12 +85,26 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
71
85
|
*/
|
|
72
86
|
deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | null;
|
|
73
87
|
/**
|
|
88
|
+
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
89
|
+
* Space Complexity: O(1)
|
|
90
|
+
*/
|
|
91
|
+
/**
|
|
92
|
+
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
93
|
+
* Space Complexity: O(1)
|
|
94
|
+
*
|
|
74
95
|
* The deleteEdge function removes an edge between two vertices in a graph.
|
|
75
96
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
76
97
|
* @returns The method is returning either the removed edge (of type EO) or null if the edge was not found.
|
|
77
98
|
*/
|
|
78
99
|
deleteEdge(edge: EO): EO | null;
|
|
79
100
|
/**
|
|
101
|
+
* Time Complexity: O(1)
|
|
102
|
+
* Space Complexity: O(1)
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* Time Complexity: O(1)
|
|
106
|
+
* Space Complexity: O(1)
|
|
107
|
+
*
|
|
80
108
|
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|
|
81
109
|
* vertex.
|
|
82
110
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
@@ -85,6 +113,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
85
113
|
*/
|
|
86
114
|
degreeOf(vertexOrKey: VertexKey | VO): number;
|
|
87
115
|
/**
|
|
116
|
+
* Time Complexity: O(1)
|
|
117
|
+
* Space Complexity: O(1)
|
|
118
|
+
*/
|
|
119
|
+
/**
|
|
120
|
+
* Time Complexity: O(1)
|
|
121
|
+
* Space Complexity: O(1)
|
|
122
|
+
*
|
|
88
123
|
* The function returns the edges of a given vertex or vertex ID.
|
|
89
124
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
|
|
90
125
|
* unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
|
|
@@ -92,11 +127,25 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
92
127
|
*/
|
|
93
128
|
edgesOf(vertexOrKey: VertexKey | VO): EO[];
|
|
94
129
|
/**
|
|
130
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
|
|
131
|
+
* Space Complexity: O(|E|)
|
|
132
|
+
*/
|
|
133
|
+
/**
|
|
134
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
|
|
135
|
+
* Space Complexity: O(|E|)
|
|
136
|
+
*
|
|
95
137
|
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
96
138
|
* @returns The method `edgeSet()` returns an array of type `EO[]`.
|
|
97
139
|
*/
|
|
98
140
|
edgeSet(): EO[];
|
|
99
141
|
/**
|
|
142
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
|
|
143
|
+
* Space Complexity: O(|E|)
|
|
144
|
+
*/
|
|
145
|
+
/**
|
|
146
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
|
|
147
|
+
* Space Complexity: O(|E|)
|
|
148
|
+
*
|
|
100
149
|
* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
|
|
101
150
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
102
151
|
* (`VertexKey`).
|
|
@@ -104,6 +153,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
104
153
|
*/
|
|
105
154
|
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
106
155
|
/**
|
|
156
|
+
* Time Complexity: O(1)
|
|
157
|
+
* Space Complexity: O(1)
|
|
158
|
+
*/
|
|
159
|
+
/**
|
|
160
|
+
* Time Complexity: O(1)
|
|
161
|
+
* Space Complexity: O(1)
|
|
162
|
+
*
|
|
107
163
|
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
108
164
|
* it returns null.
|
|
109
165
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
@@ -112,6 +168,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
112
168
|
*/
|
|
113
169
|
getEndsOfEdge(edge: EO): [VO, VO] | null;
|
|
114
170
|
/**
|
|
171
|
+
* Time Complexity: O(1)
|
|
172
|
+
* Space Complexity: O(1)
|
|
173
|
+
*/
|
|
174
|
+
/**
|
|
175
|
+
* Time Complexity: O(1)
|
|
176
|
+
* Space Complexity: O(1)
|
|
177
|
+
*
|
|
115
178
|
* The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
|
|
116
179
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
117
180
|
* @returns a boolean value.
|
|
@@ -79,6 +79,13 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
79
79
|
return new UndirectedEdge(v1, v2, weight ?? 1, value);
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
+
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
83
|
+
* Space Complexity: O(1)
|
|
84
|
+
*/
|
|
85
|
+
/**
|
|
86
|
+
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
87
|
+
* Space Complexity: O(1)
|
|
88
|
+
*
|
|
82
89
|
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
83
90
|
* @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
84
91
|
* object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
@@ -98,6 +105,13 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
98
105
|
return edges ? edges[0] || null : null;
|
|
99
106
|
}
|
|
100
107
|
/**
|
|
108
|
+
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
109
|
+
* Space Complexity: O(1)
|
|
110
|
+
*/
|
|
111
|
+
/**
|
|
112
|
+
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
113
|
+
* Space Complexity: O(1)
|
|
114
|
+
*
|
|
101
115
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
102
116
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
103
117
|
* @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
|
|
@@ -122,6 +136,13 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
122
136
|
return removed;
|
|
123
137
|
}
|
|
124
138
|
/**
|
|
139
|
+
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
140
|
+
* Space Complexity: O(1)
|
|
141
|
+
*/
|
|
142
|
+
/**
|
|
143
|
+
* Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
|
|
144
|
+
* Space Complexity: O(1)
|
|
145
|
+
*
|
|
125
146
|
* The deleteEdge function removes an edge between two vertices in a graph.
|
|
126
147
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
127
148
|
* @returns The method is returning either the removed edge (of type EO) or null if the edge was not found.
|
|
@@ -130,6 +151,13 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
130
151
|
return this.deleteEdgeBetween(edge.vertices[0], edge.vertices[1]);
|
|
131
152
|
}
|
|
132
153
|
/**
|
|
154
|
+
* Time Complexity: O(1)
|
|
155
|
+
* Space Complexity: O(1)
|
|
156
|
+
*/
|
|
157
|
+
/**
|
|
158
|
+
* Time Complexity: O(1)
|
|
159
|
+
* Space Complexity: O(1)
|
|
160
|
+
*
|
|
133
161
|
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|
|
134
162
|
* vertex.
|
|
135
163
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
@@ -146,6 +174,13 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
146
174
|
}
|
|
147
175
|
}
|
|
148
176
|
/**
|
|
177
|
+
* Time Complexity: O(1)
|
|
178
|
+
* Space Complexity: O(1)
|
|
179
|
+
*/
|
|
180
|
+
/**
|
|
181
|
+
* Time Complexity: O(1)
|
|
182
|
+
* Space Complexity: O(1)
|
|
183
|
+
*
|
|
149
184
|
* The function returns the edges of a given vertex or vertex ID.
|
|
150
185
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
|
|
151
186
|
* unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
|
|
@@ -161,6 +196,13 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
161
196
|
}
|
|
162
197
|
}
|
|
163
198
|
/**
|
|
199
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
|
|
200
|
+
* Space Complexity: O(|E|)
|
|
201
|
+
*/
|
|
202
|
+
/**
|
|
203
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
|
|
204
|
+
* Space Complexity: O(|E|)
|
|
205
|
+
*
|
|
164
206
|
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
165
207
|
* @returns The method `edgeSet()` returns an array of type `EO[]`.
|
|
166
208
|
*/
|
|
@@ -174,6 +216,13 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
174
216
|
return [...edgeSet];
|
|
175
217
|
}
|
|
176
218
|
/**
|
|
219
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
|
|
220
|
+
* Space Complexity: O(|E|)
|
|
221
|
+
*/
|
|
222
|
+
/**
|
|
223
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
|
|
224
|
+
* Space Complexity: O(|E|)
|
|
225
|
+
*
|
|
177
226
|
* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
|
|
178
227
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
179
228
|
* (`VertexKey`).
|
|
@@ -194,6 +243,13 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
194
243
|
return neighbors;
|
|
195
244
|
}
|
|
196
245
|
/**
|
|
246
|
+
* Time Complexity: O(1)
|
|
247
|
+
* Space Complexity: O(1)
|
|
248
|
+
*/
|
|
249
|
+
/**
|
|
250
|
+
* Time Complexity: O(1)
|
|
251
|
+
* Space Complexity: O(1)
|
|
252
|
+
*
|
|
197
253
|
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
198
254
|
* it returns null.
|
|
199
255
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
@@ -214,6 +270,13 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
214
270
|
}
|
|
215
271
|
}
|
|
216
272
|
/**
|
|
273
|
+
* Time Complexity: O(1)
|
|
274
|
+
* Space Complexity: O(1)
|
|
275
|
+
*/
|
|
276
|
+
/**
|
|
277
|
+
* Time Complexity: O(1)
|
|
278
|
+
* Space Complexity: O(1)
|
|
279
|
+
*
|
|
217
280
|
* The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
|
|
218
281
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
219
282
|
* @returns a boolean value.
|