data-structure-typed 1.48.3 → 1.48.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +6 -6
- package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -6
- package/dist/cjs/data-structures/base/iterable-base.js +3 -3
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +5 -3
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +6 -4
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +18 -15
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +16 -13
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +15 -11
- package/dist/cjs/data-structures/binary-tree/bst.js +17 -13
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +19 -13
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +20 -14
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +21 -14
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +25 -18
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +53 -52
- package/dist/cjs/data-structures/graph/abstract-graph.js +82 -78
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +70 -52
- package/dist/cjs/data-structures/graph/directed-graph.js +111 -65
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +5 -5
- package/dist/cjs/data-structures/graph/map-graph.js +8 -8
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +51 -32
- package/dist/cjs/data-structures/graph/undirected-graph.js +117 -54
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +8 -8
- package/dist/cjs/data-structures/hash/hash-map.js +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/base/base.d.ts +3 -3
- package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -6
- package/dist/mjs/data-structures/base/iterable-base.js +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +5 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +6 -4
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +18 -15
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +17 -14
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +15 -11
- package/dist/mjs/data-structures/binary-tree/bst.js +17 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +19 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +20 -14
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +21 -14
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +25 -18
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +53 -52
- package/dist/mjs/data-structures/graph/abstract-graph.js +83 -79
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +70 -52
- package/dist/mjs/data-structures/graph/directed-graph.js +111 -65
- package/dist/mjs/data-structures/graph/map-graph.d.ts +5 -5
- package/dist/mjs/data-structures/graph/map-graph.js +8 -8
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +51 -32
- package/dist/mjs/data-structures/graph/undirected-graph.js +119 -56
- package/dist/mjs/data-structures/hash/hash-map.d.ts +8 -8
- package/dist/mjs/data-structures/hash/hash-map.js +3 -3
- package/dist/mjs/interfaces/binary-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/base/base.d.ts +3 -3
- package/dist/umd/data-structure-typed.js +413 -285
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/base/iterable-base.ts +6 -6
- package/src/data-structures/binary-tree/avl-tree.ts +8 -5
- package/src/data-structures/binary-tree/binary-tree.ts +23 -19
- package/src/data-structures/binary-tree/bst.ts +19 -14
- package/src/data-structures/binary-tree/rb-tree.ts +20 -14
- package/src/data-structures/binary-tree/tree-multimap.ts +27 -19
- package/src/data-structures/graph/abstract-graph.ts +87 -82
- package/src/data-structures/graph/directed-graph.ts +114 -65
- package/src/data-structures/graph/map-graph.ts +8 -8
- package/src/data-structures/graph/undirected-graph.ts +124 -56
- package/src/data-structures/hash/hash-map.ts +8 -8
- package/src/interfaces/binary-tree.ts +1 -1
- package/src/types/data-structures/base/base.ts +3 -3
- package/test/integration/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +3 -3
- package/test/unit/data-structures/graph/directed-graph.test.ts +52 -15
- package/test/unit/data-structures/graph/map-graph.test.ts +3 -3
- package/test/unit/data-structures/graph/undirected-graph.test.ts +42 -5
|
@@ -23,7 +23,7 @@ export class DirectedEdge extends AbstractEdge {
|
|
|
23
23
|
src;
|
|
24
24
|
dest;
|
|
25
25
|
/**
|
|
26
|
-
* The constructor function initializes the source and destination
|
|
26
|
+
* The constructor function initializes the source and destination vertexMap of an edge, along with an optional weight
|
|
27
27
|
* and value.
|
|
28
28
|
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
29
29
|
* a graph.
|
|
@@ -61,7 +61,7 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
61
61
|
/**
|
|
62
62
|
* The function creates a new vertex with an optional value and returns it.
|
|
63
63
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
64
|
-
* could be a number or a string depending on how you want to identify your
|
|
64
|
+
* could be a number or a string depending on how you want to identify your vertexMap.
|
|
65
65
|
* @param [value] - The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
66
66
|
* it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be
|
|
67
67
|
* assigned the same value as the 'key' parameter
|
|
@@ -75,7 +75,7 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
75
75
|
* 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.
|
|
76
76
|
*/
|
|
77
77
|
/**
|
|
78
|
-
* The function creates a directed edge between two
|
|
78
|
+
* The function creates a directed edge between two vertexMap with an optional weight and value.
|
|
79
79
|
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
80
80
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
81
81
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
@@ -88,43 +88,43 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
88
88
|
return new DirectedEdge(src, dest, weight ?? 1, value);
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
|
-
* Time Complexity: O(|V|) where |V| is the number of
|
|
91
|
+
* Time Complexity: O(|V|) where |V| is the number of vertexMap
|
|
92
92
|
* Space Complexity: O(1)
|
|
93
93
|
*/
|
|
94
94
|
/**
|
|
95
|
-
* Time Complexity: O(|V|) where |V| is the number of
|
|
95
|
+
* Time Complexity: O(|V|) where |V| is the number of vertexMap
|
|
96
96
|
* Space Complexity: O(1)
|
|
97
97
|
*
|
|
98
|
-
* The `getEdge` function retrieves an edge between two
|
|
98
|
+
* The `getEdge` function retrieves an edge between two vertexMap based on their source and destination IDs.
|
|
99
99
|
* @param {VO | VertexKey | undefined} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
100
100
|
* @param {VO | VertexKey | undefined} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
101
101
|
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `undefined` if the
|
|
102
102
|
* destination is not specified.
|
|
103
|
-
* @returns the first edge found between the source and destination
|
|
103
|
+
* @returns the first edge found between the source and destination vertexMap, or undefined if no such edge is found.
|
|
104
104
|
*/
|
|
105
105
|
getEdge(srcOrKey, destOrKey) {
|
|
106
|
-
let
|
|
106
|
+
let edgeMap = [];
|
|
107
107
|
if (srcOrKey !== undefined && destOrKey !== undefined) {
|
|
108
108
|
const src = this._getVertex(srcOrKey);
|
|
109
109
|
const dest = this._getVertex(destOrKey);
|
|
110
110
|
if (src && dest) {
|
|
111
111
|
const srcOutEdges = this._outEdgeMap.get(src);
|
|
112
112
|
if (srcOutEdges) {
|
|
113
|
-
|
|
113
|
+
edgeMap = srcOutEdges.filter(edge => edge.dest === dest.key);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
return
|
|
117
|
+
return edgeMap[0] || undefined;
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
120
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
121
121
|
* Space Complexity: O(1)
|
|
122
122
|
*/
|
|
123
123
|
/**
|
|
124
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
124
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
125
125
|
* Space Complexity: O(1)
|
|
126
126
|
*
|
|
127
|
-
* The function removes an edge between two
|
|
127
|
+
* The function removes an edge between two vertexMap in a graph and returns the removed edge.
|
|
128
128
|
* @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
|
|
129
129
|
* @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
130
130
|
* @returns the removed edge (EO) if it exists, or undefined if either the source or destination vertex does not exist.
|
|
@@ -147,48 +147,94 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
147
147
|
return removed;
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
|
-
* Time Complexity: O(
|
|
150
|
+
* Time Complexity: O(E) where E is the number of edgeMap
|
|
151
151
|
* Space Complexity: O(1)
|
|
152
152
|
*/
|
|
153
153
|
/**
|
|
154
|
-
* Time Complexity: O(
|
|
154
|
+
* Time Complexity: O(E) where E is the number of edgeMap
|
|
155
155
|
* Space Complexity: O(1)
|
|
156
156
|
*
|
|
157
|
-
* The function removes an edge from a graph and returns the removed edge
|
|
158
|
-
* @param {EO}
|
|
159
|
-
*
|
|
160
|
-
* @
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
* The `deleteEdge` function removes an edge from a graph and returns the removed edge.
|
|
158
|
+
* @param {EO | VertexKey} edgeOrSrcVertexKey - The `edge` parameter can be either an `EO` object (edge object) or
|
|
159
|
+
* a `VertexKey` (key of a vertex).
|
|
160
|
+
* @param {VertexKey} [destVertexKey] - The `destVertexKey` parameter is an optional parameter that
|
|
161
|
+
* represents the key of the destination vertex of the edge. It is used to specify the destination
|
|
162
|
+
* vertex when the `edge` parameter is a vertex key. If `destVertexKey` is not provided, the function
|
|
163
|
+
* assumes that the `edge`
|
|
164
|
+
* @returns the removed edge (EO) or undefined if no edge was removed.
|
|
165
|
+
*/
|
|
166
|
+
deleteEdge(edgeOrSrcVertexKey, destVertexKey) {
|
|
163
167
|
let removed = undefined;
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
let src, dest;
|
|
169
|
+
if (this.isVertexKey(edgeOrSrcVertexKey)) {
|
|
170
|
+
if (this.isVertexKey(destVertexKey)) {
|
|
171
|
+
src = this._getVertex(edgeOrSrcVertexKey);
|
|
172
|
+
dest = this._getVertex(destVertexKey);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
src = this._getVertex(edgeOrSrcVertexKey.src);
|
|
180
|
+
dest = this._getVertex(edgeOrSrcVertexKey.dest);
|
|
181
|
+
}
|
|
166
182
|
if (src && dest) {
|
|
167
183
|
const srcOutEdges = this._outEdgeMap.get(src);
|
|
168
184
|
if (srcOutEdges && srcOutEdges.length > 0) {
|
|
169
|
-
arrayRemove(srcOutEdges, (edge) => edge.src === src.key);
|
|
185
|
+
arrayRemove(srcOutEdges, (edge) => edge.src === src.key && edge.dest === dest?.key);
|
|
170
186
|
}
|
|
171
187
|
const destInEdges = this._inEdgeMap.get(dest);
|
|
172
188
|
if (destInEdges && destInEdges.length > 0) {
|
|
173
|
-
removed = arrayRemove(destInEdges, (edge) => edge.dest === dest.key)[0];
|
|
189
|
+
removed = arrayRemove(destInEdges, (edge) => edge.src === src.key && edge.dest === dest.key)[0];
|
|
174
190
|
}
|
|
175
191
|
}
|
|
176
192
|
return removed;
|
|
177
193
|
}
|
|
178
194
|
/**
|
|
179
|
-
* Time Complexity: O(
|
|
195
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
196
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
197
|
+
*/
|
|
198
|
+
/**
|
|
199
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
200
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
201
|
+
*
|
|
202
|
+
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
203
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
204
|
+
* (`VertexKey`).
|
|
205
|
+
* @returns The method is returning a boolean value.
|
|
206
|
+
*/
|
|
207
|
+
deleteVertex(vertexOrKey) {
|
|
208
|
+
let vertexKey;
|
|
209
|
+
let vertex;
|
|
210
|
+
if (this.isVertexKey(vertexOrKey)) {
|
|
211
|
+
vertex = this.getVertex(vertexOrKey);
|
|
212
|
+
vertexKey = vertexOrKey;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
vertex = vertexOrKey;
|
|
216
|
+
vertexKey = this._getVertexKey(vertexOrKey);
|
|
217
|
+
}
|
|
218
|
+
if (vertex) {
|
|
219
|
+
this._outEdgeMap.delete(vertex);
|
|
220
|
+
this._inEdgeMap.delete(vertex);
|
|
221
|
+
}
|
|
222
|
+
return this._vertexMap.delete(vertexKey);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
180
226
|
* Space Complexity: O(1)
|
|
181
227
|
*/
|
|
182
228
|
/**
|
|
183
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
229
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
184
230
|
* Space Complexity: O(1)
|
|
185
231
|
*
|
|
186
|
-
* The function removes
|
|
232
|
+
* The function removes edgeMap between two vertexMap and returns the removed edgeMap.
|
|
187
233
|
* @param {VertexKey | VO} v1 - The parameter `v1` can be either a `VertexKey` or a `VO`. A `VertexKey` represents the
|
|
188
234
|
* unique identifier of a vertex in a graph, while `VO` represents the actual vertex object.
|
|
189
235
|
* @param {VertexKey | VO} v2 - The parameter `v2` represents either a `VertexKey` or a `VO` object. It is used to specify
|
|
190
236
|
* the second vertex in the edge that needs to be removed.
|
|
191
|
-
* @returns an array of removed
|
|
237
|
+
* @returns an array of removed edgeMap (EO[]).
|
|
192
238
|
*/
|
|
193
239
|
deleteEdgesBetween(v1, v2) {
|
|
194
240
|
const removed = [];
|
|
@@ -208,10 +254,10 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
208
254
|
* Time Complexity: O(1)
|
|
209
255
|
* Space Complexity: O(1)
|
|
210
256
|
*
|
|
211
|
-
* The function `incomingEdgesOf` returns an array of incoming
|
|
257
|
+
* The function `incomingEdgesOf` returns an array of incoming edgeMap for a given vertex or vertex ID.
|
|
212
258
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
213
259
|
* (`VertexKey`).
|
|
214
|
-
* @returns The method `incomingEdgesOf` returns an array of
|
|
260
|
+
* @returns The method `incomingEdgesOf` returns an array of edgeMap (`EO[]`).
|
|
215
261
|
*/
|
|
216
262
|
incomingEdgesOf(vertexOrKey) {
|
|
217
263
|
const target = this._getVertex(vertexOrKey);
|
|
@@ -228,10 +274,10 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
228
274
|
* Time Complexity: O(1)
|
|
229
275
|
* Space Complexity: O(1)
|
|
230
276
|
*
|
|
231
|
-
* The function `outgoingEdgesOf` returns an array of outgoing
|
|
277
|
+
* The function `outgoingEdgesOf` returns an array of outgoing edgeMap from a given vertex or vertex ID.
|
|
232
278
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`VO`) or a vertex ID
|
|
233
279
|
* (`VertexKey`).
|
|
234
|
-
* @returns The method `outgoingEdgesOf` returns an array of
|
|
280
|
+
* @returns The method `outgoingEdgesOf` returns an array of edgeMap (`EO[]`).
|
|
235
281
|
*/
|
|
236
282
|
outgoingEdgesOf(vertexOrKey) {
|
|
237
283
|
const target = this._getVertex(vertexOrKey);
|
|
@@ -263,9 +309,9 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
263
309
|
* Time Complexity: O(1)
|
|
264
310
|
* Space Complexity: O(1)
|
|
265
311
|
*
|
|
266
|
-
* The function "inDegreeOf" returns the number of incoming
|
|
312
|
+
* The function "inDegreeOf" returns the number of incoming edgeMap for a given vertex.
|
|
267
313
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
268
|
-
* @returns The number of incoming
|
|
314
|
+
* @returns The number of incoming edgeMap of the specified vertex or vertex ID.
|
|
269
315
|
*/
|
|
270
316
|
inDegreeOf(vertexOrKey) {
|
|
271
317
|
return this.incomingEdgesOf(vertexOrKey).length;
|
|
@@ -278,9 +324,9 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
278
324
|
* Time Complexity: O(1)
|
|
279
325
|
* Space Complexity: O(1)
|
|
280
326
|
*
|
|
281
|
-
* The function `outDegreeOf` returns the number of outgoing
|
|
327
|
+
* The function `outDegreeOf` returns the number of outgoing edgeMap from a given vertex.
|
|
282
328
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
283
|
-
* @returns The number of outgoing
|
|
329
|
+
* @returns The number of outgoing edgeMap from the specified vertex or vertex ID.
|
|
284
330
|
*/
|
|
285
331
|
outDegreeOf(vertexOrKey) {
|
|
286
332
|
return this.outgoingEdgesOf(vertexOrKey).length;
|
|
@@ -293,9 +339,9 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
293
339
|
* Time Complexity: O(1)
|
|
294
340
|
* Space Complexity: O(1)
|
|
295
341
|
*
|
|
296
|
-
* The function "edgesOf" returns an array of both outgoing and incoming
|
|
342
|
+
* The function "edgesOf" returns an array of both outgoing and incoming edgeMap of a given vertex or vertex ID.
|
|
297
343
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
298
|
-
* @returns The function `edgesOf` returns an array of
|
|
344
|
+
* @returns The function `edgesOf` returns an array of edgeMap.
|
|
299
345
|
*/
|
|
300
346
|
edgesOf(vertexOrKey) {
|
|
301
347
|
return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
|
|
@@ -331,17 +377,17 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
331
377
|
return this._getVertex(e.dest);
|
|
332
378
|
}
|
|
333
379
|
/**
|
|
334
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
380
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
335
381
|
* Space Complexity: O(1)
|
|
336
382
|
*/
|
|
337
383
|
/**
|
|
338
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
384
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
339
385
|
* Space Complexity: O(1)
|
|
340
386
|
*
|
|
341
|
-
* The function `getDestinations` returns an array of destination
|
|
387
|
+
* The function `getDestinations` returns an array of destination vertexMap connected to a given vertex.
|
|
342
388
|
* @param {VO | VertexKey | undefined} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
343
389
|
* find the destinations. It can be either a `VO` object, a `VertexKey` value, or `undefined`.
|
|
344
|
-
* @returns an array of
|
|
390
|
+
* @returns an array of vertexMap (VO[]).
|
|
345
391
|
*/
|
|
346
392
|
getDestinations(vertex) {
|
|
347
393
|
if (vertex === undefined) {
|
|
@@ -358,26 +404,26 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
358
404
|
return destinations;
|
|
359
405
|
}
|
|
360
406
|
/**
|
|
361
|
-
* Time Complexity: O(|V| + |E|) where |V| is the number of
|
|
407
|
+
* Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
|
|
362
408
|
* Space Complexity: O(|V|)
|
|
363
409
|
*/
|
|
364
410
|
/**
|
|
365
|
-
* Time Complexity: O(|V| + |E|) where |V| is the number of
|
|
411
|
+
* Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
|
|
366
412
|
* Space Complexity: O(|V|)
|
|
367
413
|
*
|
|
368
|
-
* The `topologicalSort` function performs a topological sort on a graph and returns an array of
|
|
414
|
+
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertexMap or vertex IDs
|
|
369
415
|
* in the sorted order, or undefined if the graph contains a cycle.
|
|
370
416
|
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
371
|
-
* property to use for sorting the
|
|
372
|
-
* specified, the
|
|
373
|
-
* @returns an array of
|
|
417
|
+
* property to use for sorting the vertexMap. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
|
|
418
|
+
* specified, the vertexMap themselves will be used for sorting. If 'key' is specified, the ids of
|
|
419
|
+
* @returns an array of vertexMap or vertex IDs in topological order. If there is a cycle in the graph, it returns undefined.
|
|
374
420
|
*/
|
|
375
421
|
topologicalSort(propertyName) {
|
|
376
422
|
propertyName = propertyName ?? 'key';
|
|
377
423
|
// When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
|
|
378
424
|
// When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
|
|
379
425
|
const statusMap = new Map();
|
|
380
|
-
for (const entry of this.
|
|
426
|
+
for (const entry of this.vertexMap) {
|
|
381
427
|
statusMap.set(entry[1], 0);
|
|
382
428
|
}
|
|
383
429
|
let sorted = [];
|
|
@@ -397,7 +443,7 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
397
443
|
statusMap.set(cur, 2);
|
|
398
444
|
sorted.push(cur);
|
|
399
445
|
};
|
|
400
|
-
for (const entry of this.
|
|
446
|
+
for (const entry of this.vertexMap) {
|
|
401
447
|
if (statusMap.get(entry[1]) === 0) {
|
|
402
448
|
dfs(entry[1]);
|
|
403
449
|
}
|
|
@@ -409,35 +455,35 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
409
455
|
return sorted.reverse();
|
|
410
456
|
}
|
|
411
457
|
/**
|
|
412
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
458
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
413
459
|
* Space Complexity: O(|E|)
|
|
414
460
|
*/
|
|
415
461
|
/**
|
|
416
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
462
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
417
463
|
* Space Complexity: O(|E|)
|
|
418
464
|
*
|
|
419
|
-
* The `edgeSet` function returns an array of all the
|
|
420
|
-
* @returns The `edgeSet()` method returns an array of
|
|
465
|
+
* The `edgeSet` function returns an array of all the edgeMap in the graph.
|
|
466
|
+
* @returns The `edgeSet()` method returns an array of edgeMap (`EO[]`).
|
|
421
467
|
*/
|
|
422
468
|
edgeSet() {
|
|
423
|
-
let
|
|
469
|
+
let edgeMap = [];
|
|
424
470
|
this._outEdgeMap.forEach(outEdges => {
|
|
425
|
-
|
|
471
|
+
edgeMap = [...edgeMap, ...outEdges];
|
|
426
472
|
});
|
|
427
|
-
return
|
|
473
|
+
return edgeMap;
|
|
428
474
|
}
|
|
429
475
|
/**
|
|
430
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
476
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
431
477
|
* Space Complexity: O(1)
|
|
432
478
|
*/
|
|
433
479
|
/**
|
|
434
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
480
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
435
481
|
* Space Complexity: O(1)
|
|
436
482
|
*
|
|
437
|
-
* The function `getNeighbors` returns an array of neighboring
|
|
483
|
+
* The function `getNeighbors` returns an array of neighboring vertexMap of a given vertex or vertex ID in a graph.
|
|
438
484
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
439
485
|
* (`VertexKey`).
|
|
440
|
-
* @returns an array of
|
|
486
|
+
* @returns an array of vertexMap (VO[]).
|
|
441
487
|
*/
|
|
442
488
|
getNeighbors(vertexOrKey) {
|
|
443
489
|
const neighbors = [];
|
|
@@ -462,10 +508,10 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
462
508
|
* Time Complexity: O(1)
|
|
463
509
|
* Space Complexity: O(1)
|
|
464
510
|
*
|
|
465
|
-
* The function "getEndsOfEdge" returns the source and destination
|
|
511
|
+
* The function "getEndsOfEdge" returns the source and destination vertexMap of an edge if it exists in the graph,
|
|
466
512
|
* otherwise it returns undefined.
|
|
467
513
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
|
|
468
|
-
* @returns The function `getEndsOfEdge` returns an array containing two
|
|
514
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
|
|
469
515
|
* graph. If the edge does not exist, it returns `undefined`.
|
|
470
516
|
*/
|
|
471
517
|
getEndsOfEdge(edge) {
|
|
@@ -489,7 +535,7 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
489
535
|
* Time Complexity: O(1)
|
|
490
536
|
* Space Complexity: O(1)
|
|
491
537
|
*
|
|
492
|
-
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination
|
|
538
|
+
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertexMap exist.
|
|
493
539
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
|
|
494
540
|
* needs to be added to the graph.
|
|
495
541
|
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
@@ -32,17 +32,17 @@ export declare class MapEdge<E = any> extends DirectedEdge<E> {
|
|
|
32
32
|
}
|
|
33
33
|
export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVertex<V>, EO extends MapEdge<E> = MapEdge<E>> extends DirectedGraph<V, E, VO, EO> {
|
|
34
34
|
/**
|
|
35
|
-
* The constructor function initializes the
|
|
36
|
-
* @param {MapGraphCoordinate}
|
|
35
|
+
* The constructor function initializes the originCoord and bottomRight properties of a MapGraphCoordinate object.
|
|
36
|
+
* @param {MapGraphCoordinate} originCoord - The `originCoord` parameter is a `MapGraphCoordinate` object that represents the
|
|
37
37
|
* starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
|
|
38
38
|
* graph.
|
|
39
39
|
* @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
|
|
40
40
|
* `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
|
|
41
41
|
* it will default to `undefined`.
|
|
42
42
|
*/
|
|
43
|
-
constructor(
|
|
44
|
-
protected
|
|
45
|
-
get
|
|
43
|
+
constructor(originCoord: MapGraphCoordinate, bottomRight?: MapGraphCoordinate);
|
|
44
|
+
protected _originCoord: MapGraphCoordinate;
|
|
45
|
+
get originCoord(): MapGraphCoordinate;
|
|
46
46
|
protected _bottomRight: MapGraphCoordinate | undefined;
|
|
47
47
|
get bottomRight(): MapGraphCoordinate | undefined;
|
|
48
48
|
/**
|
|
@@ -37,22 +37,22 @@ export class MapEdge extends DirectedEdge {
|
|
|
37
37
|
}
|
|
38
38
|
export class MapGraph extends DirectedGraph {
|
|
39
39
|
/**
|
|
40
|
-
* The constructor function initializes the
|
|
41
|
-
* @param {MapGraphCoordinate}
|
|
40
|
+
* The constructor function initializes the originCoord and bottomRight properties of a MapGraphCoordinate object.
|
|
41
|
+
* @param {MapGraphCoordinate} originCoord - The `originCoord` parameter is a `MapGraphCoordinate` object that represents the
|
|
42
42
|
* starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
|
|
43
43
|
* graph.
|
|
44
44
|
* @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
|
|
45
45
|
* `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
|
|
46
46
|
* it will default to `undefined`.
|
|
47
47
|
*/
|
|
48
|
-
constructor(
|
|
48
|
+
constructor(originCoord, bottomRight) {
|
|
49
49
|
super();
|
|
50
|
-
this.
|
|
50
|
+
this._originCoord = originCoord;
|
|
51
51
|
this._bottomRight = bottomRight;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
get
|
|
55
|
-
return this.
|
|
53
|
+
_originCoord = [0, 0];
|
|
54
|
+
get originCoord() {
|
|
55
|
+
return this._originCoord;
|
|
56
56
|
}
|
|
57
57
|
_bottomRight;
|
|
58
58
|
get bottomRight() {
|
|
@@ -69,7 +69,7 @@ export class MapGraph extends DirectedGraph {
|
|
|
69
69
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
70
70
|
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
71
71
|
*/
|
|
72
|
-
createVertex(key, value, lat = this.
|
|
72
|
+
createVertex(key, value, lat = this.originCoord[0], long = this.originCoord[1]) {
|
|
73
73
|
return new MapVertex(key, value, lat, long);
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
@@ -12,7 +12,7 @@ export declare class UndirectedVertex<V = any> extends AbstractVertex<V> {
|
|
|
12
12
|
constructor(key: VertexKey, value?: V);
|
|
13
13
|
}
|
|
14
14
|
export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
|
|
15
|
-
|
|
15
|
+
vertexMap: [VertexKey, VertexKey];
|
|
16
16
|
/**
|
|
17
17
|
* The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
18
18
|
* value.
|
|
@@ -27,11 +27,11 @@ export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
|
|
|
27
27
|
}
|
|
28
28
|
export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVertex<V> = UndirectedVertex<V>, EO extends UndirectedEdge<E> = UndirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
|
|
29
29
|
/**
|
|
30
|
-
* The constructor initializes a new Map object to store
|
|
30
|
+
* The constructor initializes a new Map object to store edgeMap.
|
|
31
31
|
*/
|
|
32
32
|
constructor();
|
|
33
|
-
protected
|
|
34
|
-
get
|
|
33
|
+
protected _edgeMap: Map<VO, EO[]>;
|
|
34
|
+
get edgeMap(): Map<VO, EO[]>;
|
|
35
35
|
/**
|
|
36
36
|
* The function creates a new vertex with an optional value and returns it.
|
|
37
37
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
|
|
@@ -43,7 +43,7 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
43
43
|
*/
|
|
44
44
|
createVertex(key: VertexKey, value?: VO['value']): VO;
|
|
45
45
|
/**
|
|
46
|
-
* The function creates an undirected edge between two
|
|
46
|
+
* The function creates an undirected edge between two vertexMap with an optional weight and value.
|
|
47
47
|
* @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
48
48
|
* @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
|
|
49
49
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
@@ -54,14 +54,14 @@ 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
|
|
57
|
+
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
58
58
|
* Space Complexity: O(1)
|
|
59
59
|
*/
|
|
60
60
|
/**
|
|
61
|
-
* Time Complexity: O(|E|), where |E| is the number of
|
|
61
|
+
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
62
62
|
* Space Complexity: O(1)
|
|
63
63
|
*
|
|
64
|
-
* The function `getEdge` returns the first edge that connects two
|
|
64
|
+
* The function `getEdge` returns the first edge that connects two vertexMap, or undefined if no such edge exists.
|
|
65
65
|
* @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
66
66
|
* object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
67
67
|
* @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
@@ -70,33 +70,52 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
70
70
|
*/
|
|
71
71
|
getEdge(v1: VO | VertexKey | undefined, v2: VO | VertexKey | undefined): EO | undefined;
|
|
72
72
|
/**
|
|
73
|
-
* Time Complexity: O(|E|), where |E| is the number of
|
|
73
|
+
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
74
74
|
* Space Complexity: O(1)
|
|
75
75
|
*/
|
|
76
76
|
/**
|
|
77
|
-
* Time Complexity: O(|E|), where |E| is the number of
|
|
77
|
+
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
78
78
|
* Space Complexity: O(1)
|
|
79
79
|
*
|
|
80
|
-
* The function removes an edge between two
|
|
80
|
+
* The function removes an edge between two vertexMap in a graph and returns the removed edge.
|
|
81
81
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
82
82
|
* @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
|
|
83
83
|
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
|
|
84
|
-
* @returns the removed edge (EO) if it exists, or undefined if either of the
|
|
84
|
+
* @returns the removed edge (EO) if it exists, or undefined if either of the vertexMap (VO) does not exist.
|
|
85
85
|
*/
|
|
86
86
|
deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | undefined;
|
|
87
87
|
/**
|
|
88
|
-
* Time Complexity: O(
|
|
88
|
+
* Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
|
|
89
89
|
* Space Complexity: O(1)
|
|
90
90
|
*/
|
|
91
91
|
/**
|
|
92
|
-
* Time Complexity: O(
|
|
92
|
+
* Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
|
|
93
93
|
* Space Complexity: O(1)
|
|
94
94
|
*
|
|
95
|
-
* The deleteEdge
|
|
96
|
-
* @param {EO}
|
|
97
|
-
*
|
|
95
|
+
* The function `deleteEdge` deletes an edge between two vertexMap in a graph.
|
|
96
|
+
* @param {EO | VertexKey} edgeOrOneSideVertexKey - The parameter `edgeOrOneSideVertexKey` can be
|
|
97
|
+
* either an edge object or a vertex key.
|
|
98
|
+
* @param {VertexKey} [otherSideVertexKey] - The parameter `otherSideVertexKey` is an optional
|
|
99
|
+
* parameter that represents the key of the vertex on the other side of the edge. It is used when the
|
|
100
|
+
* `edgeOrOneSideVertexKey` parameter is a vertex key, and it specifies the key of the vertex on the
|
|
101
|
+
* other side of the
|
|
102
|
+
* @returns The `deleteEdge` function returns either the deleted edge object (EO) or `undefined`.
|
|
103
|
+
*/
|
|
104
|
+
deleteEdge(edgeOrOneSideVertexKey: EO | VertexKey, otherSideVertexKey?: VertexKey): EO | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
107
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
108
|
+
*/
|
|
109
|
+
/**
|
|
110
|
+
* Time Complexity: O(1) - Constant time for Map operations.
|
|
111
|
+
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
112
|
+
*
|
|
113
|
+
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
114
|
+
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
115
|
+
* (`VertexKey`).
|
|
116
|
+
* @returns The method is returning a boolean value.
|
|
98
117
|
*/
|
|
99
|
-
|
|
118
|
+
deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
100
119
|
/**
|
|
101
120
|
* Time Complexity: O(1)
|
|
102
121
|
* Space Complexity: O(1)
|
|
@@ -105,11 +124,11 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
105
124
|
* Time Complexity: O(1)
|
|
106
125
|
* Space Complexity: O(1)
|
|
107
126
|
*
|
|
108
|
-
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of
|
|
127
|
+
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edgeMap connected to that
|
|
109
128
|
* vertex.
|
|
110
129
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
111
130
|
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
112
|
-
*
|
|
131
|
+
* edgeMap connected to that vertex.
|
|
113
132
|
*/
|
|
114
133
|
degreeOf(vertexOrKey: VertexKey | VO): number;
|
|
115
134
|
/**
|
|
@@ -120,36 +139,36 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
120
139
|
* Time Complexity: O(1)
|
|
121
140
|
* Space Complexity: O(1)
|
|
122
141
|
*
|
|
123
|
-
* The function returns the
|
|
142
|
+
* The function returns the edgeMap of a given vertex or vertex ID.
|
|
124
143
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
|
|
125
144
|
* unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
|
|
126
|
-
* @returns an array of
|
|
145
|
+
* @returns an array of edgeMap.
|
|
127
146
|
*/
|
|
128
147
|
edgesOf(vertexOrKey: VertexKey | VO): EO[];
|
|
129
148
|
/**
|
|
130
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
149
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
131
150
|
* Space Complexity: O(|E|)
|
|
132
151
|
*/
|
|
133
152
|
/**
|
|
134
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
153
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
135
154
|
* Space Complexity: O(|E|)
|
|
136
155
|
*
|
|
137
|
-
* The function "edgeSet" returns an array of unique
|
|
156
|
+
* The function "edgeSet" returns an array of unique edgeMap from a set of edgeMap.
|
|
138
157
|
* @returns The method `edgeSet()` returns an array of type `EO[]`.
|
|
139
158
|
*/
|
|
140
159
|
edgeSet(): EO[];
|
|
141
160
|
/**
|
|
142
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
161
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
143
162
|
* Space Complexity: O(|E|)
|
|
144
163
|
*/
|
|
145
164
|
/**
|
|
146
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
165
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
147
166
|
* Space Complexity: O(|E|)
|
|
148
167
|
*
|
|
149
|
-
* The function "getNeighbors" returns an array of neighboring
|
|
168
|
+
* The function "getNeighbors" returns an array of neighboring vertexMap for a given vertex or vertex ID.
|
|
150
169
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
151
170
|
* (`VertexKey`).
|
|
152
|
-
* @returns an array of
|
|
171
|
+
* @returns an array of vertexMap (VO[]).
|
|
153
172
|
*/
|
|
154
173
|
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
155
174
|
/**
|
|
@@ -160,10 +179,10 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
160
179
|
* Time Complexity: O(1)
|
|
161
180
|
* Space Complexity: O(1)
|
|
162
181
|
*
|
|
163
|
-
* The function "getEndsOfEdge" returns the
|
|
182
|
+
* The function "getEndsOfEdge" returns the vertexMap at the ends of an edge if the edge exists in the graph, otherwise
|
|
164
183
|
* it returns undefined.
|
|
165
184
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
166
|
-
* @returns The function `getEndsOfEdge` returns an array containing two
|
|
185
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
|
|
167
186
|
* graph. If the edge does not exist, it returns `undefined`.
|
|
168
187
|
*/
|
|
169
188
|
getEndsOfEdge(edge: EO): [VO, VO] | undefined;
|
|
@@ -175,7 +194,7 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
175
194
|
* Time Complexity: O(1)
|
|
176
195
|
* Space Complexity: O(1)
|
|
177
196
|
*
|
|
178
|
-
* The function adds an edge to the graph by updating the adjacency list with the
|
|
197
|
+
* The function adds an edge to the graph by updating the adjacency list with the vertexMap of the edge.
|
|
179
198
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
180
199
|
* @returns a boolean value.
|
|
181
200
|
*/
|