data-structure-typed 1.47.7 → 1.47.8
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 +98 -17
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/cjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/cjs/data-structures/graph/directed-graph.js +28 -28
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/cjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/cjs/data-structures/queue/queue.js +13 -13
- package/dist/cjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/cjs/data-structures/stack/stack.js +7 -7
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/mjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/mjs/data-structures/graph/directed-graph.js +28 -28
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/mjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/mjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/mjs/data-structures/queue/queue.js +13 -13
- package/dist/mjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/mjs/data-structures/stack/stack.js +7 -7
- package/dist/mjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/umd/data-structure-typed.js +161 -161
- 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/binary-tree/segment-tree.ts +10 -10
- package/src/data-structures/graph/abstract-graph.ts +46 -46
- package/src/data-structures/graph/directed-graph.ts +40 -40
- package/src/data-structures/graph/undirected-graph.ts +26 -26
- package/src/data-structures/linked-list/doubly-linked-list.ts +45 -45
- package/src/data-structures/linked-list/singly-linked-list.ts +38 -38
- package/src/data-structures/linked-list/skip-linked-list.ts +4 -4
- package/src/data-structures/queue/queue.ts +13 -13
- package/src/data-structures/stack/stack.ts +9 -9
- package/src/types/data-structures/graph/abstract-graph.ts +2 -2
- package/test/integration/index.html +102 -33
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
- package/test/unit/data-structures/graph/abstract-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +10 -10
- package/test/unit/data-structures/graph/undirected-graph.test.ts +3 -3
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -3
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +1 -1
- package/test/unit/data-structures/stack/stack.test.ts +2 -2
|
@@ -47,13 +47,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
47
47
|
* @param value
|
|
48
48
|
*/
|
|
49
49
|
abstract createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
|
|
50
|
-
abstract deleteEdge(edge: EO): EO |
|
|
51
|
-
abstract getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO |
|
|
50
|
+
abstract deleteEdge(edge: EO): EO | undefined;
|
|
51
|
+
abstract getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
|
|
52
52
|
abstract degreeOf(vertexOrKey: VO | VertexKey): number;
|
|
53
53
|
abstract edgeSet(): EO[];
|
|
54
54
|
abstract edgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
55
55
|
abstract getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
56
|
-
abstract getEndsOfEdge(edge: EO): [VO, VO] |
|
|
56
|
+
abstract getEndsOfEdge(edge: EO): [VO, VO] | undefined;
|
|
57
57
|
/**
|
|
58
58
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
59
59
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -62,13 +62,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
62
62
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
63
63
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
64
64
|
*
|
|
65
|
-
* The function "getVertex" returns the vertex with the specified ID or
|
|
65
|
+
* The function "getVertex" returns the vertex with the specified ID or undefined if it doesn't exist.
|
|
66
66
|
* @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
|
|
67
67
|
* the `_vertices` map.
|
|
68
68
|
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertices`
|
|
69
|
-
* map. If the vertex does not exist, it returns `
|
|
69
|
+
* map. If the vertex does not exist, it returns `undefined`.
|
|
70
70
|
*/
|
|
71
|
-
getVertex(vertexKey: VertexKey): VO |
|
|
71
|
+
getVertex(vertexKey: VertexKey): VO | undefined;
|
|
72
72
|
/**
|
|
73
73
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
74
74
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -201,7 +201,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
201
201
|
* vertices. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
|
|
202
202
|
* minimum number of
|
|
203
203
|
*/
|
|
204
|
-
getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number |
|
|
204
|
+
getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number | undefined;
|
|
205
205
|
/**
|
|
206
206
|
* Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
207
207
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
@@ -223,9 +223,9 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
223
223
|
* followed by iterative computation of the shortest path. This approach may result in exponential time complexity,
|
|
224
224
|
* so the default method is to use the Dijkstra algorithm to obtain the shortest weighted path.
|
|
225
225
|
* @returns The function `getMinPathBetween` returns an array of vertices (`VO[]`) representing the minimum path between
|
|
226
|
-
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `
|
|
226
|
+
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `undefined`.
|
|
227
227
|
*/
|
|
228
|
-
getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] |
|
|
228
|
+
getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] | undefined;
|
|
229
229
|
/**
|
|
230
230
|
* Dijkstra algorithm time: O(VE) space: O(VO + EO)
|
|
231
231
|
* /
|
|
@@ -242,9 +242,9 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
242
242
|
* a graph without using a heap data structure.
|
|
243
243
|
* @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
|
|
244
244
|
* vertex object or a vertex ID.
|
|
245
|
-
* @param {VO | VertexKey |
|
|
245
|
+
* @param {VO | VertexKey | undefined} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
|
|
246
246
|
* parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
|
|
247
|
-
* identifier. If no destination is provided, the value is set to `
|
|
247
|
+
* identifier. If no destination is provided, the value is set to `undefined`.
|
|
248
248
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
249
249
|
* distance from the source vertex to the destination vertex should be calculated and returned in the result. If
|
|
250
250
|
* `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
|
|
@@ -253,7 +253,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
253
253
|
* shortest paths from the source vertex to all other vertices in the graph. If `genPaths
|
|
254
254
|
* @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
|
|
255
255
|
*/
|
|
256
|
-
dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey |
|
|
256
|
+
dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
|
|
257
257
|
/**
|
|
258
258
|
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
259
259
|
*
|
|
@@ -276,7 +276,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
276
276
|
* optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
|
|
277
277
|
* @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
|
|
278
278
|
* start. It can be either a vertex object or a vertex ID.
|
|
279
|
-
* @param {VO | VertexKey |
|
|
279
|
+
* @param {VO | VertexKey | undefined} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
|
|
280
280
|
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
|
|
281
281
|
* will calculate the shortest paths to all other vertices from the source vertex.
|
|
282
282
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
@@ -287,7 +287,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
287
287
|
* shortest paths from the source vertex to all other vertices in the graph. If `genPaths
|
|
288
288
|
* @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
|
|
289
289
|
*/
|
|
290
|
-
dijkstra(src: VO | VertexKey, dest?: VO | VertexKey |
|
|
290
|
+
dijkstra(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
|
|
291
291
|
/**
|
|
292
292
|
* Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
|
|
293
293
|
* Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
|
|
@@ -353,12 +353,12 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
353
353
|
* graph.
|
|
354
354
|
* @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
|
|
355
355
|
* property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
|
|
356
|
-
* `predecessor` property is a 2D array of vertices (or `
|
|
356
|
+
* `predecessor` property is a 2D array of vertices (or `undefined`) representing the predecessor vertices in the shortest
|
|
357
357
|
* path between vertices in the
|
|
358
358
|
*/
|
|
359
359
|
floydWarshall(): {
|
|
360
360
|
costs: number[][];
|
|
361
|
-
predecessor: (VO |
|
|
361
|
+
predecessor: (VO | undefined)[][];
|
|
362
362
|
};
|
|
363
363
|
/**
|
|
364
364
|
* Time Complexity: O(V + E) - Linear time (Tarjan's algorithm).
|
|
@@ -445,6 +445,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
445
445
|
getBridges(): EO[];
|
|
446
446
|
protected abstract _addEdgeOnly(edge: EO): boolean;
|
|
447
447
|
protected _addVertexOnly(newVertex: VO): boolean;
|
|
448
|
-
protected _getVertex(vertexOrKey: VertexKey | VO): VO |
|
|
448
|
+
protected _getVertex(vertexOrKey: VertexKey | VO): VO | undefined;
|
|
449
449
|
protected _getVertexKey(vertexOrKey: VO | VertexKey): VertexKey;
|
|
450
450
|
}
|
|
@@ -58,14 +58,14 @@ export class AbstractGraph {
|
|
|
58
58
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
59
59
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
60
60
|
*
|
|
61
|
-
* The function "getVertex" returns the vertex with the specified ID or
|
|
61
|
+
* The function "getVertex" returns the vertex with the specified ID or undefined if it doesn't exist.
|
|
62
62
|
* @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
|
|
63
63
|
* the `_vertices` map.
|
|
64
64
|
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertices`
|
|
65
|
-
* map. If the vertex does not exist, it returns `
|
|
65
|
+
* map. If the vertex does not exist, it returns `undefined`.
|
|
66
66
|
*/
|
|
67
67
|
getVertex(vertexKey) {
|
|
68
|
-
return this._vertices.get(vertexKey) ||
|
|
68
|
+
return this._vertices.get(vertexKey) || undefined;
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
@@ -302,7 +302,7 @@ export class AbstractGraph {
|
|
|
302
302
|
const vertex2 = this._getVertex(v2);
|
|
303
303
|
const vertex1 = this._getVertex(v1);
|
|
304
304
|
if (!(vertex1 && vertex2)) {
|
|
305
|
-
return
|
|
305
|
+
return undefined;
|
|
306
306
|
}
|
|
307
307
|
const visited = new Map();
|
|
308
308
|
const queue = new Queue([vertex1]);
|
|
@@ -327,7 +327,7 @@ export class AbstractGraph {
|
|
|
327
327
|
}
|
|
328
328
|
cost++;
|
|
329
329
|
}
|
|
330
|
-
return
|
|
330
|
+
return undefined;
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
/**
|
|
@@ -351,7 +351,7 @@ export class AbstractGraph {
|
|
|
351
351
|
* followed by iterative computation of the shortest path. This approach may result in exponential time complexity,
|
|
352
352
|
* so the default method is to use the Dijkstra algorithm to obtain the shortest weighted path.
|
|
353
353
|
* @returns The function `getMinPathBetween` returns an array of vertices (`VO[]`) representing the minimum path between
|
|
354
|
-
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `
|
|
354
|
+
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `undefined`.
|
|
355
355
|
*/
|
|
356
356
|
getMinPathBetween(v1, v2, isWeight, isDFS = false) {
|
|
357
357
|
if (isWeight === undefined)
|
|
@@ -370,7 +370,7 @@ export class AbstractGraph {
|
|
|
370
370
|
}
|
|
371
371
|
index++;
|
|
372
372
|
}
|
|
373
|
-
return allPaths[minIndex] ||
|
|
373
|
+
return allPaths[minIndex] || undefined;
|
|
374
374
|
}
|
|
375
375
|
else {
|
|
376
376
|
return this.dijkstra(v1, v2, true, true)?.minPath ?? [];
|
|
@@ -419,9 +419,9 @@ export class AbstractGraph {
|
|
|
419
419
|
* a graph without using a heap data structure.
|
|
420
420
|
* @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
|
|
421
421
|
* vertex object or a vertex ID.
|
|
422
|
-
* @param {VO | VertexKey |
|
|
422
|
+
* @param {VO | VertexKey | undefined} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
|
|
423
423
|
* parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
|
|
424
|
-
* identifier. If no destination is provided, the value is set to `
|
|
424
|
+
* identifier. If no destination is provided, the value is set to `undefined`.
|
|
425
425
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
426
426
|
* distance from the source vertex to the destination vertex should be calculated and returned in the result. If
|
|
427
427
|
* `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
|
|
@@ -436,9 +436,9 @@ export class AbstractGraph {
|
|
|
436
436
|
if (genPaths === undefined)
|
|
437
437
|
genPaths = false;
|
|
438
438
|
if (dest === undefined)
|
|
439
|
-
dest =
|
|
439
|
+
dest = undefined;
|
|
440
440
|
let minDist = Infinity;
|
|
441
|
-
let minDest =
|
|
441
|
+
let minDest = undefined;
|
|
442
442
|
let minPath = [];
|
|
443
443
|
const paths = [];
|
|
444
444
|
const vertices = this._vertices;
|
|
@@ -446,9 +446,9 @@ export class AbstractGraph {
|
|
|
446
446
|
const seen = new Set();
|
|
447
447
|
const preMap = new Map(); // predecessor
|
|
448
448
|
const srcVertex = this._getVertex(src);
|
|
449
|
-
const destVertex = dest ? this._getVertex(dest) :
|
|
449
|
+
const destVertex = dest ? this._getVertex(dest) : undefined;
|
|
450
450
|
if (!srcVertex) {
|
|
451
|
-
return
|
|
451
|
+
return undefined;
|
|
452
452
|
}
|
|
453
453
|
for (const vertex of vertices) {
|
|
454
454
|
const vertexOrKey = vertex[1];
|
|
@@ -456,10 +456,10 @@ export class AbstractGraph {
|
|
|
456
456
|
distMap.set(vertexOrKey, Infinity);
|
|
457
457
|
}
|
|
458
458
|
distMap.set(srcVertex, 0);
|
|
459
|
-
preMap.set(srcVertex,
|
|
459
|
+
preMap.set(srcVertex, undefined);
|
|
460
460
|
const getMinOfNoSeen = () => {
|
|
461
461
|
let min = Infinity;
|
|
462
|
-
let minV =
|
|
462
|
+
let minV = undefined;
|
|
463
463
|
for (const [key, value] of distMap) {
|
|
464
464
|
if (!seen.has(key)) {
|
|
465
465
|
if (value < min) {
|
|
@@ -507,7 +507,7 @@ export class AbstractGraph {
|
|
|
507
507
|
if (edge) {
|
|
508
508
|
const curFromMap = distMap.get(cur);
|
|
509
509
|
const neighborFromMap = distMap.get(neighbor);
|
|
510
|
-
// TODO after no-non-
|
|
510
|
+
// TODO after no-non-undefined-assertion not ensure the logic
|
|
511
511
|
if (curFromMap !== undefined && neighborFromMap !== undefined) {
|
|
512
512
|
if (edge.weight + curFromMap < neighborFromMap) {
|
|
513
513
|
distMap.set(neighbor, edge.weight + curFromMap);
|
|
@@ -554,7 +554,7 @@ export class AbstractGraph {
|
|
|
554
554
|
* optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
|
|
555
555
|
* @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
|
|
556
556
|
* start. It can be either a vertex object or a vertex ID.
|
|
557
|
-
* @param {VO | VertexKey |
|
|
557
|
+
* @param {VO | VertexKey | undefined} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
|
|
558
558
|
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
|
|
559
559
|
* will calculate the shortest paths to all other vertices from the source vertex.
|
|
560
560
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
@@ -571,9 +571,9 @@ export class AbstractGraph {
|
|
|
571
571
|
if (genPaths === undefined)
|
|
572
572
|
genPaths = false;
|
|
573
573
|
if (dest === undefined)
|
|
574
|
-
dest =
|
|
574
|
+
dest = undefined;
|
|
575
575
|
let minDist = Infinity;
|
|
576
|
-
let minDest =
|
|
576
|
+
let minDest = undefined;
|
|
577
577
|
let minPath = [];
|
|
578
578
|
const paths = [];
|
|
579
579
|
const vertices = this._vertices;
|
|
@@ -581,9 +581,9 @@ export class AbstractGraph {
|
|
|
581
581
|
const seen = new Set();
|
|
582
582
|
const preMap = new Map(); // predecessor
|
|
583
583
|
const srcVertex = this._getVertex(src);
|
|
584
|
-
const destVertex = dest ? this._getVertex(dest) :
|
|
584
|
+
const destVertex = dest ? this._getVertex(dest) : undefined;
|
|
585
585
|
if (!srcVertex)
|
|
586
|
-
return
|
|
586
|
+
return undefined;
|
|
587
587
|
for (const vertex of vertices) {
|
|
588
588
|
const vertexOrKey = vertex[1];
|
|
589
589
|
if (vertexOrKey instanceof AbstractVertex)
|
|
@@ -592,11 +592,11 @@ export class AbstractGraph {
|
|
|
592
592
|
const heap = new PriorityQueue([], { comparator: (a, b) => a.key - b.key });
|
|
593
593
|
heap.add({ key: 0, value: srcVertex });
|
|
594
594
|
distMap.set(srcVertex, 0);
|
|
595
|
-
preMap.set(srcVertex,
|
|
595
|
+
preMap.set(srcVertex, undefined);
|
|
596
596
|
/**
|
|
597
597
|
* The function `getPaths` retrieves all paths from vertices to a specified minimum vertex.
|
|
598
|
-
* @param {VO |
|
|
599
|
-
*
|
|
598
|
+
* @param {VO | undefined} minV - The parameter `minV` is of type `VO | undefined`. It represents the minimum vertex value or
|
|
599
|
+
* undefined.
|
|
600
600
|
*/
|
|
601
601
|
const getPaths = (minV) => {
|
|
602
602
|
for (const vertex of vertices) {
|
|
@@ -732,7 +732,7 @@ export class AbstractGraph {
|
|
|
732
732
|
}
|
|
733
733
|
}
|
|
734
734
|
}
|
|
735
|
-
let minDest =
|
|
735
|
+
let minDest = undefined;
|
|
736
736
|
if (getMin) {
|
|
737
737
|
distMap.forEach((d, v) => {
|
|
738
738
|
if (v !== srcVertex) {
|
|
@@ -808,7 +808,7 @@ export class AbstractGraph {
|
|
|
808
808
|
* graph.
|
|
809
809
|
* @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
|
|
810
810
|
* property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
|
|
811
|
-
* `predecessor` property is a 2D array of vertices (or `
|
|
811
|
+
* `predecessor` property is a 2D array of vertices (or `undefined`) representing the predecessor vertices in the shortest
|
|
812
812
|
* path between vertices in the
|
|
813
813
|
*/
|
|
814
814
|
floydWarshall() {
|
|
@@ -821,7 +821,7 @@ export class AbstractGraph {
|
|
|
821
821
|
costs[i] = [];
|
|
822
822
|
predecessor[i] = [];
|
|
823
823
|
for (let j = 0; j < n; j++) {
|
|
824
|
-
predecessor[i][j] =
|
|
824
|
+
predecessor[i][j] = undefined;
|
|
825
825
|
}
|
|
826
826
|
}
|
|
827
827
|
for (let i = 0; i < n; i++) {
|
|
@@ -913,7 +913,7 @@ export class AbstractGraph {
|
|
|
913
913
|
}
|
|
914
914
|
const childLow = lowMap.get(neighbor);
|
|
915
915
|
const curLow = lowMap.get(cur);
|
|
916
|
-
// TODO after no-non-
|
|
916
|
+
// TODO after no-non-undefined-assertion not ensure the logic
|
|
917
917
|
if (curLow !== undefined && childLow !== undefined) {
|
|
918
918
|
lowMap.set(cur, Math.min(curLow, childLow));
|
|
919
919
|
}
|
|
@@ -937,7 +937,7 @@ export class AbstractGraph {
|
|
|
937
937
|
}
|
|
938
938
|
}
|
|
939
939
|
};
|
|
940
|
-
dfs(root,
|
|
940
|
+
dfs(root, undefined);
|
|
941
941
|
let SCCs = new Map();
|
|
942
942
|
const getSCCs = () => {
|
|
943
943
|
const SCCs = new Map();
|
|
@@ -1031,7 +1031,7 @@ export class AbstractGraph {
|
|
|
1031
1031
|
}
|
|
1032
1032
|
_getVertex(vertexOrKey) {
|
|
1033
1033
|
const vertexKey = this._getVertexKey(vertexOrKey);
|
|
1034
|
-
return this._vertices.get(vertexKey) ||
|
|
1034
|
+
return this._vertices.get(vertexKey) || undefined;
|
|
1035
1035
|
}
|
|
1036
1036
|
_getVertexKey(vertexOrKey) {
|
|
1037
1037
|
return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
|
|
@@ -74,13 +74,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
74
74
|
* Space Complexity: O(1)
|
|
75
75
|
*
|
|
76
76
|
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
77
|
-
* @param {VO | VertexKey |
|
|
78
|
-
* @param {VO | VertexKey |
|
|
79
|
-
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `
|
|
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
80
|
* destination is not specified.
|
|
81
|
-
* @returns the first edge found between the source and destination vertices, or
|
|
81
|
+
* @returns the first edge found between the source and destination vertices, or undefined if no such edge is found.
|
|
82
82
|
*/
|
|
83
|
-
getEdge(srcOrKey: VO | VertexKey |
|
|
83
|
+
getEdge(srcOrKey: VO | VertexKey | undefined, destOrKey: VO | VertexKey | undefined): EO | undefined;
|
|
84
84
|
/**
|
|
85
85
|
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
86
86
|
* Space Complexity: O(1)
|
|
@@ -92,9 +92,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
92
92
|
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
93
93
|
* @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
|
|
94
94
|
* @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
95
|
-
* @returns the removed edge (EO) if it exists, or
|
|
95
|
+
* @returns the removed edge (EO) if it exists, or undefined if either the source or destination vertex does not exist.
|
|
96
96
|
*/
|
|
97
|
-
deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO |
|
|
97
|
+
deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
|
|
98
98
|
/**
|
|
99
99
|
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
100
100
|
* Space Complexity: O(1)
|
|
@@ -103,12 +103,12 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
103
103
|
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
104
104
|
* Space Complexity: O(1)
|
|
105
105
|
*
|
|
106
|
-
* The function removes an edge from a graph and returns the removed edge, or
|
|
106
|
+
* The function removes an edge from a graph and returns the removed edge, or undefined if the edge was not found.
|
|
107
107
|
* @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
108
108
|
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
109
|
-
* @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `
|
|
109
|
+
* @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `undefined` if the edge does not exist.
|
|
110
110
|
*/
|
|
111
|
-
deleteEdge(edge: EO): EO |
|
|
111
|
+
deleteEdge(edge: EO): EO | undefined;
|
|
112
112
|
/**
|
|
113
113
|
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
114
114
|
* Space Complexity: O(1)
|
|
@@ -213,11 +213,11 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
213
213
|
* Time Complexity: O(1)
|
|
214
214
|
* Space Complexity: O(1)
|
|
215
215
|
*
|
|
216
|
-
* The function "getEdgeSrc" returns the source vertex of an edge, or
|
|
216
|
+
* The function "getEdgeSrc" returns the source vertex of an edge, or undefined if the edge does not exist.
|
|
217
217
|
* @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
|
|
218
|
-
* @returns either a vertex object (VO) or
|
|
218
|
+
* @returns either a vertex object (VO) or undefined.
|
|
219
219
|
*/
|
|
220
|
-
getEdgeSrc(e: EO): VO |
|
|
220
|
+
getEdgeSrc(e: EO): VO | undefined;
|
|
221
221
|
/**
|
|
222
222
|
* Time Complexity: O(1)
|
|
223
223
|
* Space Complexity: O(1)
|
|
@@ -228,9 +228,9 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
228
228
|
*
|
|
229
229
|
* The function "getEdgeDest" returns the destination vertex of an edge.
|
|
230
230
|
* @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
|
|
231
|
-
* @returns either a vertex object of type VO or
|
|
231
|
+
* @returns either a vertex object of type VO or undefined.
|
|
232
232
|
*/
|
|
233
|
-
getEdgeDest(e: EO): VO |
|
|
233
|
+
getEdgeDest(e: EO): VO | undefined;
|
|
234
234
|
/**
|
|
235
235
|
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
236
236
|
* Space Complexity: O(1)
|
|
@@ -240,11 +240,11 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
240
240
|
* Space Complexity: O(1)
|
|
241
241
|
*
|
|
242
242
|
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
|
|
243
|
-
* @param {VO | VertexKey |
|
|
244
|
-
* find the destinations. It can be either a `VO` object, a `VertexKey` value, or `
|
|
243
|
+
* @param {VO | VertexKey | undefined} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
244
|
+
* find the destinations. It can be either a `VO` object, a `VertexKey` value, or `undefined`.
|
|
245
245
|
* @returns an array of vertices (VO[]).
|
|
246
246
|
*/
|
|
247
|
-
getDestinations(vertex: VO | VertexKey |
|
|
247
|
+
getDestinations(vertex: VO | VertexKey | undefined): VO[];
|
|
248
248
|
/**
|
|
249
249
|
* Time Complexity: O(|V| + |E|) where |V| is the number of vertices and |E| is the number of edges
|
|
250
250
|
* Space Complexity: O(|V|)
|
|
@@ -254,13 +254,13 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
254
254
|
* Space Complexity: O(|V|)
|
|
255
255
|
*
|
|
256
256
|
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
|
|
257
|
-
* in the sorted order, or
|
|
257
|
+
* in the sorted order, or undefined if the graph contains a cycle.
|
|
258
258
|
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
259
259
|
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
|
|
260
260
|
* specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
|
|
261
|
-
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns
|
|
261
|
+
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns undefined.
|
|
262
262
|
*/
|
|
263
|
-
topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> |
|
|
263
|
+
topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | undefined;
|
|
264
264
|
/**
|
|
265
265
|
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
266
266
|
* Space Complexity: O(|E|)
|
|
@@ -296,12 +296,12 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
296
296
|
* Space Complexity: O(1)
|
|
297
297
|
*
|
|
298
298
|
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
|
|
299
|
-
* otherwise it returns
|
|
299
|
+
* otherwise it returns undefined.
|
|
300
300
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
|
|
301
301
|
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
|
|
302
|
-
* graph. If the edge does not exist, it returns `
|
|
302
|
+
* graph. If the edge does not exist, it returns `undefined`.
|
|
303
303
|
*/
|
|
304
|
-
getEndsOfEdge(edge: EO): [VO, VO] |
|
|
304
|
+
getEndsOfEdge(edge: EO): [VO, VO] | undefined;
|
|
305
305
|
/**
|
|
306
306
|
* Time Complexity: O(1)
|
|
307
307
|
* Space Complexity: O(1)
|
|
@@ -96,15 +96,15 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
96
96
|
* Space Complexity: O(1)
|
|
97
97
|
*
|
|
98
98
|
* The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
|
|
99
|
-
* @param {VO | VertexKey |
|
|
100
|
-
* @param {VO | VertexKey |
|
|
101
|
-
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `
|
|
99
|
+
* @param {VO | VertexKey | undefined} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
100
|
+
* @param {VO | VertexKey | undefined} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
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 vertices, or
|
|
103
|
+
* @returns the first edge found between the source and destination vertices, or undefined if no such edge is found.
|
|
104
104
|
*/
|
|
105
105
|
getEdge(srcOrKey, destOrKey) {
|
|
106
106
|
let edges = [];
|
|
107
|
-
if (srcOrKey !==
|
|
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) {
|
|
@@ -114,7 +114,7 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
return edges[0] ||
|
|
117
|
+
return edges[0] || undefined;
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
@@ -127,14 +127,14 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
127
127
|
* The function removes an edge between two vertices 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
|
-
* @returns the removed edge (EO) if it exists, or
|
|
130
|
+
* @returns the removed edge (EO) if it exists, or undefined if either the source or destination vertex does not exist.
|
|
131
131
|
*/
|
|
132
132
|
deleteEdgeSrcToDest(srcOrKey, destOrKey) {
|
|
133
133
|
const src = this._getVertex(srcOrKey);
|
|
134
134
|
const dest = this._getVertex(destOrKey);
|
|
135
|
-
let removed =
|
|
135
|
+
let removed = undefined;
|
|
136
136
|
if (!src || !dest) {
|
|
137
|
-
return
|
|
137
|
+
return undefined;
|
|
138
138
|
}
|
|
139
139
|
const srcOutEdges = this._outEdgeMap.get(src);
|
|
140
140
|
if (srcOutEdges) {
|
|
@@ -142,7 +142,7 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
142
142
|
}
|
|
143
143
|
const destInEdges = this._inEdgeMap.get(dest);
|
|
144
144
|
if (destInEdges) {
|
|
145
|
-
removed = arrayRemove(destInEdges, (edge) => edge.src === src.key)[0] ||
|
|
145
|
+
removed = arrayRemove(destInEdges, (edge) => edge.src === src.key)[0] || undefined;
|
|
146
146
|
}
|
|
147
147
|
return removed;
|
|
148
148
|
}
|
|
@@ -154,13 +154,13 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
154
154
|
* Time Complexity: O(|E|) where |E| is the number of edges
|
|
155
155
|
* Space Complexity: O(1)
|
|
156
156
|
*
|
|
157
|
-
* The function removes an edge from a graph and returns the removed edge, or
|
|
157
|
+
* The function removes an edge from a graph and returns the removed edge, or undefined if the edge was not found.
|
|
158
158
|
* @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
159
159
|
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
160
|
-
* @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `
|
|
160
|
+
* @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `undefined` if the edge does not exist.
|
|
161
161
|
*/
|
|
162
162
|
deleteEdge(edge) {
|
|
163
|
-
let removed =
|
|
163
|
+
let removed = undefined;
|
|
164
164
|
const src = this._getVertex(edge.src);
|
|
165
165
|
const dest = this._getVertex(edge.dest);
|
|
166
166
|
if (src && dest) {
|
|
@@ -308,9 +308,9 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
308
308
|
* Time Complexity: O(1)
|
|
309
309
|
* Space Complexity: O(1)
|
|
310
310
|
*
|
|
311
|
-
* The function "getEdgeSrc" returns the source vertex of an edge, or
|
|
311
|
+
* The function "getEdgeSrc" returns the source vertex of an edge, or undefined if the edge does not exist.
|
|
312
312
|
* @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
|
|
313
|
-
* @returns either a vertex object (VO) or
|
|
313
|
+
* @returns either a vertex object (VO) or undefined.
|
|
314
314
|
*/
|
|
315
315
|
getEdgeSrc(e) {
|
|
316
316
|
return this._getVertex(e.src);
|
|
@@ -325,7 +325,7 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
325
325
|
*
|
|
326
326
|
* The function "getEdgeDest" returns the destination vertex of an edge.
|
|
327
327
|
* @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
|
|
328
|
-
* @returns either a vertex object of type VO or
|
|
328
|
+
* @returns either a vertex object of type VO or undefined.
|
|
329
329
|
*/
|
|
330
330
|
getEdgeDest(e) {
|
|
331
331
|
return this._getVertex(e.dest);
|
|
@@ -339,12 +339,12 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
339
339
|
* Space Complexity: O(1)
|
|
340
340
|
*
|
|
341
341
|
* The function `getDestinations` returns an array of destination vertices connected to a given vertex.
|
|
342
|
-
* @param {VO | VertexKey |
|
|
343
|
-
* find the destinations. It can be either a `VO` object, a `VertexKey` value, or `
|
|
342
|
+
* @param {VO | VertexKey | undefined} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
343
|
+
* find the destinations. It can be either a `VO` object, a `VertexKey` value, or `undefined`.
|
|
344
344
|
* @returns an array of vertices (VO[]).
|
|
345
345
|
*/
|
|
346
346
|
getDestinations(vertex) {
|
|
347
|
-
if (vertex ===
|
|
347
|
+
if (vertex === undefined) {
|
|
348
348
|
return [];
|
|
349
349
|
}
|
|
350
350
|
const destinations = [];
|
|
@@ -366,11 +366,11 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
366
366
|
* Space Complexity: O(|V|)
|
|
367
367
|
*
|
|
368
368
|
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
|
|
369
|
-
* in the sorted order, or
|
|
369
|
+
* in the sorted order, or undefined if the graph contains a cycle.
|
|
370
370
|
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
371
371
|
* property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
|
|
372
372
|
* specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
|
|
373
|
-
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns
|
|
373
|
+
* @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns undefined.
|
|
374
374
|
*/
|
|
375
375
|
topologicalSort(propertyName) {
|
|
376
376
|
propertyName = propertyName ?? 'key';
|
|
@@ -403,7 +403,7 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
if (hasCycle)
|
|
406
|
-
return
|
|
406
|
+
return undefined;
|
|
407
407
|
if (propertyName === 'key')
|
|
408
408
|
sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.key : vertex));
|
|
409
409
|
return sorted.reverse();
|
|
@@ -446,7 +446,7 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
446
446
|
const outEdges = this.outgoingEdgesOf(vertex);
|
|
447
447
|
for (const outEdge of outEdges) {
|
|
448
448
|
const neighbor = this._getVertex(outEdge.dest);
|
|
449
|
-
// TODO after no-non-
|
|
449
|
+
// TODO after no-non-undefined-assertion not ensure the logic
|
|
450
450
|
if (neighbor) {
|
|
451
451
|
neighbors.push(neighbor);
|
|
452
452
|
}
|
|
@@ -463,14 +463,14 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
463
463
|
* Space Complexity: O(1)
|
|
464
464
|
*
|
|
465
465
|
* The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
|
|
466
|
-
* otherwise it returns
|
|
466
|
+
* otherwise it returns undefined.
|
|
467
467
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
|
|
468
468
|
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
|
|
469
|
-
* graph. If the edge does not exist, it returns `
|
|
469
|
+
* graph. If the edge does not exist, it returns `undefined`.
|
|
470
470
|
*/
|
|
471
471
|
getEndsOfEdge(edge) {
|
|
472
472
|
if (!this.hasEdge(edge.src, edge.dest)) {
|
|
473
|
-
return
|
|
473
|
+
return undefined;
|
|
474
474
|
}
|
|
475
475
|
const v1 = this._getVertex(edge.src);
|
|
476
476
|
const v2 = this._getVertex(edge.dest);
|
|
@@ -478,7 +478,7 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
478
478
|
return [v1, v2];
|
|
479
479
|
}
|
|
480
480
|
else {
|
|
481
|
-
return
|
|
481
|
+
return undefined;
|
|
482
482
|
}
|
|
483
483
|
}
|
|
484
484
|
/**
|
|
@@ -501,7 +501,7 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
501
501
|
}
|
|
502
502
|
const srcVertex = this._getVertex(edge.src);
|
|
503
503
|
const destVertex = this._getVertex(edge.dest);
|
|
504
|
-
// TODO after no-non-
|
|
504
|
+
// TODO after no-non-undefined-assertion not ensure the logic
|
|
505
505
|
if (srcVertex && destVertex) {
|
|
506
506
|
const srcOutEdges = this._outEdgeMap.get(srcVertex);
|
|
507
507
|
if (srcOutEdges) {
|