min-heap-typed 1.42.1 → 1.42.2
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.
|
@@ -252,10 +252,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
252
252
|
* Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
|
|
253
253
|
* all pairs
|
|
254
254
|
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
255
|
-
*/
|
|
256
|
-
/**
|
|
257
|
-
* Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
|
|
258
|
-
* all pairs
|
|
259
255
|
* /
|
|
260
256
|
|
|
261
257
|
/**
|
|
@@ -264,12 +260,12 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
264
260
|
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
265
261
|
* The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
|
|
266
262
|
* graph.
|
|
267
|
-
* @returns The function `
|
|
263
|
+
* @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
|
|
268
264
|
* property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
|
|
269
265
|
* `predecessor` property is a 2D array of vertices (or `null`) representing the predecessor vertices in the shortest
|
|
270
266
|
* path between vertices in the
|
|
271
267
|
*/
|
|
272
|
-
|
|
268
|
+
floydWarshall(): {
|
|
273
269
|
costs: number[][];
|
|
274
270
|
predecessor: (VO | null)[][];
|
|
275
271
|
};
|
|
@@ -289,7 +285,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
289
285
|
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
290
286
|
* The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
|
|
291
287
|
* strongly connected components (SCCs), and cycles in a graph.
|
|
292
|
-
* @param {boolean} [
|
|
288
|
+
* @param {boolean} [needCutVertexes] - A boolean value indicating whether or not to calculate and return the
|
|
293
289
|
* articulation points in the graph. Articulation points are the vertices in a graph whose removal would increase the
|
|
294
290
|
* number of connected components in the graph.
|
|
295
291
|
* @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
|
|
@@ -302,14 +298,48 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
302
298
|
* are arrays of vertices that form cycles within the SCCs.
|
|
303
299
|
* @returns The function `tarjan` returns an object with the following properties:
|
|
304
300
|
*/
|
|
305
|
-
tarjan(
|
|
301
|
+
tarjan(needCutVertexes?: boolean, needBridges?: boolean, needSCCs?: boolean, needCycles?: boolean): {
|
|
306
302
|
dfnMap: Map<VO, number>;
|
|
307
303
|
lowMap: Map<VO, number>;
|
|
308
304
|
bridges: EO[];
|
|
309
|
-
|
|
305
|
+
cutVertexes: VO[];
|
|
310
306
|
SCCs: Map<number, VO[]>;
|
|
311
307
|
cycles: Map<number, VO[]>;
|
|
312
308
|
};
|
|
309
|
+
/**
|
|
310
|
+
* The function returns a map that associates each vertex object with its corresponding depth-first
|
|
311
|
+
* number.
|
|
312
|
+
* @returns A Map object with keys of type VO and values of type number.
|
|
313
|
+
*/
|
|
314
|
+
getDFNMap(): Map<VO, number>;
|
|
315
|
+
/**
|
|
316
|
+
* The function returns a Map object that contains the low values of each vertex in a Tarjan
|
|
317
|
+
* algorithm.
|
|
318
|
+
* @returns The method `getLowMap()` is returning a `Map` object with keys of type `VO` and values of
|
|
319
|
+
* type `number`.
|
|
320
|
+
*/
|
|
321
|
+
getLowMap(): Map<VO, number>;
|
|
322
|
+
/**
|
|
323
|
+
* The function `getCycles` returns a map of cycles found using the Tarjan algorithm.
|
|
324
|
+
* @returns The function `getCycles()` is returning a `Map<number, VO[]>`.
|
|
325
|
+
*/
|
|
326
|
+
getCycles(): Map<number, VO[]>;
|
|
327
|
+
/**
|
|
328
|
+
* The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
|
|
329
|
+
* @returns an array of VO objects, specifically the cut vertexes.
|
|
330
|
+
*/
|
|
331
|
+
getCutVertexes(): VO[];
|
|
332
|
+
/**
|
|
333
|
+
* The function "getSCCs" returns a map of strongly connected components (SCCs) using the Tarjan
|
|
334
|
+
* algorithm.
|
|
335
|
+
* @returns a map where the keys are numbers and the values are arrays of VO objects.
|
|
336
|
+
*/
|
|
337
|
+
getSCCs(): Map<number, VO[]>;
|
|
338
|
+
/**
|
|
339
|
+
* The function "getBridges" returns an array of bridges using the Tarjan algorithm.
|
|
340
|
+
* @returns the bridges found using the Tarjan algorithm.
|
|
341
|
+
*/
|
|
342
|
+
getBridges(): EO[];
|
|
313
343
|
protected abstract _addEdgeOnly(edge: EO): boolean;
|
|
314
344
|
protected _addVertexOnly(newVertex: VO): boolean;
|
|
315
345
|
protected _getVertex(vertexOrKey: VertexKey | VO): VO | null;
|
|
@@ -704,10 +704,6 @@ class AbstractGraph {
|
|
|
704
704
|
* Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
|
|
705
705
|
* all pairs
|
|
706
706
|
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
707
|
-
*/
|
|
708
|
-
/**
|
|
709
|
-
* Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
|
|
710
|
-
* all pairs
|
|
711
707
|
* /
|
|
712
708
|
|
|
713
709
|
/**
|
|
@@ -716,12 +712,12 @@ class AbstractGraph {
|
|
|
716
712
|
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
717
713
|
* The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
|
|
718
714
|
* graph.
|
|
719
|
-
* @returns The function `
|
|
715
|
+
* @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
|
|
720
716
|
* property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
|
|
721
717
|
* `predecessor` property is a 2D array of vertices (or `null`) representing the predecessor vertices in the shortest
|
|
722
718
|
* path between vertices in the
|
|
723
719
|
*/
|
|
724
|
-
|
|
720
|
+
floydWarshall() {
|
|
725
721
|
var _a;
|
|
726
722
|
const idAndVertices = [...this._vertices];
|
|
727
723
|
const n = idAndVertices.length;
|
|
@@ -768,7 +764,7 @@ class AbstractGraph {
|
|
|
768
764
|
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
769
765
|
* The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
|
|
770
766
|
* strongly connected components (SCCs), and cycles in a graph.
|
|
771
|
-
* @param {boolean} [
|
|
767
|
+
* @param {boolean} [needCutVertexes] - A boolean value indicating whether or not to calculate and return the
|
|
772
768
|
* articulation points in the graph. Articulation points are the vertices in a graph whose removal would increase the
|
|
773
769
|
* number of connected components in the graph.
|
|
774
770
|
* @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
|
|
@@ -781,13 +777,13 @@ class AbstractGraph {
|
|
|
781
777
|
* are arrays of vertices that form cycles within the SCCs.
|
|
782
778
|
* @returns The function `tarjan` returns an object with the following properties:
|
|
783
779
|
*/
|
|
784
|
-
tarjan(
|
|
780
|
+
tarjan(needCutVertexes = false, needBridges = false, needSCCs = true, needCycles = false) {
|
|
785
781
|
// !! in undirected graph we will not let child visit parent when dfs
|
|
786
782
|
// !! articulation point(in dfs search tree not in graph): (cur !== root && cur.has(child)) && (low(child) >= dfn(cur)) || (cur === root && cur.children() >= 2)
|
|
787
783
|
// !! bridge: low(child) > dfn(cur)
|
|
788
784
|
const defaultConfig = false;
|
|
789
|
-
if (
|
|
790
|
-
|
|
785
|
+
if (needCutVertexes === undefined)
|
|
786
|
+
needCutVertexes = defaultConfig;
|
|
791
787
|
if (needBridges === undefined)
|
|
792
788
|
needBridges = defaultConfig;
|
|
793
789
|
if (needSCCs === undefined)
|
|
@@ -802,7 +798,7 @@ class AbstractGraph {
|
|
|
802
798
|
lowMap.set(v, Infinity);
|
|
803
799
|
});
|
|
804
800
|
const [root] = vertices.values();
|
|
805
|
-
const
|
|
801
|
+
const cutVertexes = [];
|
|
806
802
|
const bridges = [];
|
|
807
803
|
let dfn = 0;
|
|
808
804
|
const dfs = (cur, parent) => {
|
|
@@ -825,10 +821,10 @@ class AbstractGraph {
|
|
|
825
821
|
}
|
|
826
822
|
const curFromMap = dfnMap.get(cur);
|
|
827
823
|
if (childLow !== undefined && curFromMap !== undefined) {
|
|
828
|
-
if (
|
|
824
|
+
if (needCutVertexes) {
|
|
829
825
|
if ((cur === root && childCount >= 2) || (cur !== root && childLow >= curFromMap)) {
|
|
830
826
|
// todo not ensure the logic if (cur === root && childCount >= 2 || ((cur !== root) && (childLow >= curFromMap))) {
|
|
831
|
-
|
|
827
|
+
cutVertexes.push(cur);
|
|
832
828
|
}
|
|
833
829
|
}
|
|
834
830
|
if (needBridges) {
|
|
@@ -873,7 +869,53 @@ class AbstractGraph {
|
|
|
873
869
|
}
|
|
874
870
|
});
|
|
875
871
|
}
|
|
876
|
-
return { dfnMap, lowMap, bridges,
|
|
872
|
+
return { dfnMap, lowMap, bridges, cutVertexes, SCCs, cycles };
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* The function returns a map that associates each vertex object with its corresponding depth-first
|
|
876
|
+
* number.
|
|
877
|
+
* @returns A Map object with keys of type VO and values of type number.
|
|
878
|
+
*/
|
|
879
|
+
getDFNMap() {
|
|
880
|
+
return this.tarjan(false, false, false, false).dfnMap;
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* The function returns a Map object that contains the low values of each vertex in a Tarjan
|
|
884
|
+
* algorithm.
|
|
885
|
+
* @returns The method `getLowMap()` is returning a `Map` object with keys of type `VO` and values of
|
|
886
|
+
* type `number`.
|
|
887
|
+
*/
|
|
888
|
+
getLowMap() {
|
|
889
|
+
return this.tarjan(false, false, false, false).lowMap;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* The function `getCycles` returns a map of cycles found using the Tarjan algorithm.
|
|
893
|
+
* @returns The function `getCycles()` is returning a `Map<number, VO[]>`.
|
|
894
|
+
*/
|
|
895
|
+
getCycles() {
|
|
896
|
+
return this.tarjan(false, false, false, true).cycles;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
|
|
900
|
+
* @returns an array of VO objects, specifically the cut vertexes.
|
|
901
|
+
*/
|
|
902
|
+
getCutVertexes() {
|
|
903
|
+
return this.tarjan(true, false, false, false).cutVertexes;
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* The function "getSCCs" returns a map of strongly connected components (SCCs) using the Tarjan
|
|
907
|
+
* algorithm.
|
|
908
|
+
* @returns a map where the keys are numbers and the values are arrays of VO objects.
|
|
909
|
+
*/
|
|
910
|
+
getSCCs() {
|
|
911
|
+
return this.tarjan(false, false, true, false).SCCs;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* The function "getBridges" returns an array of bridges using the Tarjan algorithm.
|
|
915
|
+
* @returns the bridges found using the Tarjan algorithm.
|
|
916
|
+
*/
|
|
917
|
+
getBridges() {
|
|
918
|
+
return this.tarjan(false, true, false, false).bridges;
|
|
877
919
|
}
|
|
878
920
|
_addVertexOnly(newVertex) {
|
|
879
921
|
if (this.hasVertex(newVertex)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "min-heap-typed",
|
|
3
|
-
"version": "1.42.
|
|
3
|
+
"version": "1.42.2",
|
|
4
4
|
"description": "Min Heap. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -132,6 +132,6 @@
|
|
|
132
132
|
"typescript": "^4.9.5"
|
|
133
133
|
},
|
|
134
134
|
"dependencies": {
|
|
135
|
-
"data-structure-typed": "^1.42.
|
|
135
|
+
"data-structure-typed": "^1.42.2"
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -64,8 +64,7 @@ export abstract class AbstractGraph<
|
|
|
64
64
|
E = any,
|
|
65
65
|
VO extends AbstractVertex<V> = AbstractVertex<V>,
|
|
66
66
|
EO extends AbstractEdge<E> = AbstractEdge<E>
|
|
67
|
-
> implements IGraph<V, E, VO, EO>
|
|
68
|
-
{
|
|
67
|
+
> implements IGraph<V, E, VO, EO> {
|
|
69
68
|
protected _vertices: Map<VertexKey, VO> = new Map<VertexKey, VO>();
|
|
70
69
|
|
|
71
70
|
get vertices(): Map<VertexKey, VO> {
|
|
@@ -236,10 +235,10 @@ export abstract class AbstractGraph<
|
|
|
236
235
|
}
|
|
237
236
|
|
|
238
237
|
const stack: { vertex: VO, path: VO[] }[] = [];
|
|
239
|
-
stack.push({
|
|
238
|
+
stack.push({vertex: vertex1, path: [vertex1]});
|
|
240
239
|
|
|
241
240
|
while (stack.length > 0) {
|
|
242
|
-
const {
|
|
241
|
+
const {vertex, path} = stack.pop()!;
|
|
243
242
|
|
|
244
243
|
if (vertex === vertex2) {
|
|
245
244
|
paths.push(path);
|
|
@@ -250,7 +249,7 @@ export abstract class AbstractGraph<
|
|
|
250
249
|
for (const neighbor of neighbors) {
|
|
251
250
|
if (!path.includes(neighbor)) {
|
|
252
251
|
const newPath = [...path, neighbor];
|
|
253
|
-
stack.push({
|
|
252
|
+
stack.push({vertex: neighbor, path: newPath});
|
|
254
253
|
}
|
|
255
254
|
}
|
|
256
255
|
}
|
|
@@ -258,8 +257,6 @@ export abstract class AbstractGraph<
|
|
|
258
257
|
}
|
|
259
258
|
|
|
260
259
|
|
|
261
|
-
|
|
262
|
-
|
|
263
260
|
/**
|
|
264
261
|
* The function calculates the sum of weights along a given path.
|
|
265
262
|
* @param {VO[]} path - An array of vertices (VO) representing a path in a graph.
|
|
@@ -522,14 +519,14 @@ export abstract class AbstractGraph<
|
|
|
522
519
|
}
|
|
523
520
|
|
|
524
521
|
getMinDist &&
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
522
|
+
distMap.forEach((d, v) => {
|
|
523
|
+
if (v !== srcVertex) {
|
|
524
|
+
if (d < minDist) {
|
|
525
|
+
minDist = d;
|
|
526
|
+
if (genPaths) minDest = v;
|
|
531
527
|
}
|
|
532
|
-
}
|
|
528
|
+
}
|
|
529
|
+
});
|
|
533
530
|
|
|
534
531
|
genPaths && getPaths(minDest);
|
|
535
532
|
|
|
@@ -591,7 +588,7 @@ export abstract class AbstractGraph<
|
|
|
591
588
|
if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Infinity);
|
|
592
589
|
}
|
|
593
590
|
|
|
594
|
-
const heap = new PriorityQueue<{key: number; value: VO}>({comparator: (a, b) => a.key - b.key});
|
|
591
|
+
const heap = new PriorityQueue<{ key: number; value: VO }>({comparator: (a, b) => a.key - b.key});
|
|
595
592
|
heap.add({key: 0, value: srcVertex});
|
|
596
593
|
|
|
597
594
|
distMap.set(srcVertex, 0);
|
|
@@ -802,11 +799,6 @@ export abstract class AbstractGraph<
|
|
|
802
799
|
* Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
|
|
803
800
|
* all pairs
|
|
804
801
|
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
805
|
-
*/
|
|
806
|
-
|
|
807
|
-
/**
|
|
808
|
-
* Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
|
|
809
|
-
* all pairs
|
|
810
802
|
* /
|
|
811
803
|
|
|
812
804
|
/**
|
|
@@ -815,12 +807,12 @@ export abstract class AbstractGraph<
|
|
|
815
807
|
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
|
|
816
808
|
* The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
|
|
817
809
|
* graph.
|
|
818
|
-
* @returns The function `
|
|
810
|
+
* @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
|
|
819
811
|
* property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
|
|
820
812
|
* `predecessor` property is a 2D array of vertices (or `null`) representing the predecessor vertices in the shortest
|
|
821
813
|
* path between vertices in the
|
|
822
814
|
*/
|
|
823
|
-
|
|
815
|
+
floydWarshall(): { costs: number[][]; predecessor: (VO | null)[][] } {
|
|
824
816
|
const idAndVertices = [...this._vertices];
|
|
825
817
|
const n = idAndVertices.length;
|
|
826
818
|
|
|
@@ -871,7 +863,7 @@ export abstract class AbstractGraph<
|
|
|
871
863
|
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
872
864
|
* The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
|
|
873
865
|
* strongly connected components (SCCs), and cycles in a graph.
|
|
874
|
-
* @param {boolean} [
|
|
866
|
+
* @param {boolean} [needCutVertexes] - A boolean value indicating whether or not to calculate and return the
|
|
875
867
|
* articulation points in the graph. Articulation points are the vertices in a graph whose removal would increase the
|
|
876
868
|
* number of connected components in the graph.
|
|
877
869
|
* @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
|
|
@@ -884,13 +876,13 @@ export abstract class AbstractGraph<
|
|
|
884
876
|
* are arrays of vertices that form cycles within the SCCs.
|
|
885
877
|
* @returns The function `tarjan` returns an object with the following properties:
|
|
886
878
|
*/
|
|
887
|
-
tarjan(
|
|
879
|
+
tarjan(needCutVertexes: boolean = false, needBridges: boolean = false, needSCCs: boolean = true, needCycles: boolean = false) {
|
|
888
880
|
// !! in undirected graph we will not let child visit parent when dfs
|
|
889
881
|
// !! articulation point(in dfs search tree not in graph): (cur !== root && cur.has(child)) && (low(child) >= dfn(cur)) || (cur === root && cur.children() >= 2)
|
|
890
882
|
// !! bridge: low(child) > dfn(cur)
|
|
891
883
|
|
|
892
884
|
const defaultConfig = false;
|
|
893
|
-
if (
|
|
885
|
+
if (needCutVertexes === undefined) needCutVertexes = defaultConfig;
|
|
894
886
|
if (needBridges === undefined) needBridges = defaultConfig;
|
|
895
887
|
if (needSCCs === undefined) needSCCs = defaultConfig;
|
|
896
888
|
if (needCycles === undefined) needCycles = defaultConfig;
|
|
@@ -905,7 +897,7 @@ export abstract class AbstractGraph<
|
|
|
905
897
|
|
|
906
898
|
const [root] = vertices.values();
|
|
907
899
|
|
|
908
|
-
const
|
|
900
|
+
const cutVertexes: VO[] = [];
|
|
909
901
|
const bridges: EO[] = [];
|
|
910
902
|
let dfn = 0;
|
|
911
903
|
const dfs = (cur: VO, parent: VO | null) => {
|
|
@@ -929,10 +921,10 @@ export abstract class AbstractGraph<
|
|
|
929
921
|
}
|
|
930
922
|
const curFromMap = dfnMap.get(cur);
|
|
931
923
|
if (childLow !== undefined && curFromMap !== undefined) {
|
|
932
|
-
if (
|
|
924
|
+
if (needCutVertexes) {
|
|
933
925
|
if ((cur === root && childCount >= 2) || (cur !== root && childLow >= curFromMap)) {
|
|
934
926
|
// todo not ensure the logic if (cur === root && childCount >= 2 || ((cur !== root) && (childLow >= curFromMap))) {
|
|
935
|
-
|
|
927
|
+
cutVertexes.push(cur);
|
|
936
928
|
}
|
|
937
929
|
}
|
|
938
930
|
|
|
@@ -983,7 +975,59 @@ export abstract class AbstractGraph<
|
|
|
983
975
|
});
|
|
984
976
|
}
|
|
985
977
|
|
|
986
|
-
return {dfnMap, lowMap, bridges,
|
|
978
|
+
return {dfnMap, lowMap, bridges, cutVertexes, SCCs, cycles};
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* The function returns a map that associates each vertex object with its corresponding depth-first
|
|
983
|
+
* number.
|
|
984
|
+
* @returns A Map object with keys of type VO and values of type number.
|
|
985
|
+
*/
|
|
986
|
+
getDFNMap(): Map<VO, number> {
|
|
987
|
+
return this.tarjan(false, false, false, false).dfnMap;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* The function returns a Map object that contains the low values of each vertex in a Tarjan
|
|
992
|
+
* algorithm.
|
|
993
|
+
* @returns The method `getLowMap()` is returning a `Map` object with keys of type `VO` and values of
|
|
994
|
+
* type `number`.
|
|
995
|
+
*/
|
|
996
|
+
getLowMap(): Map<VO, number> {
|
|
997
|
+
return this.tarjan(false, false, false, false).lowMap;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* The function `getCycles` returns a map of cycles found using the Tarjan algorithm.
|
|
1002
|
+
* @returns The function `getCycles()` is returning a `Map<number, VO[]>`.
|
|
1003
|
+
*/
|
|
1004
|
+
getCycles(): Map<number, VO[]> {
|
|
1005
|
+
return this.tarjan(false, false, false, true).cycles;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/**
|
|
1009
|
+
* The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
|
|
1010
|
+
* @returns an array of VO objects, specifically the cut vertexes.
|
|
1011
|
+
*/
|
|
1012
|
+
getCutVertexes(): VO[] {
|
|
1013
|
+
return this.tarjan(true, false, false, false).cutVertexes;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* The function "getSCCs" returns a map of strongly connected components (SCCs) using the Tarjan
|
|
1018
|
+
* algorithm.
|
|
1019
|
+
* @returns a map where the keys are numbers and the values are arrays of VO objects.
|
|
1020
|
+
*/
|
|
1021
|
+
getSCCs(): Map<number, VO[]> {
|
|
1022
|
+
return this.tarjan(false, false, true, false).SCCs;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* The function "getBridges" returns an array of bridges using the Tarjan algorithm.
|
|
1027
|
+
* @returns the bridges found using the Tarjan algorithm.
|
|
1028
|
+
*/
|
|
1029
|
+
getBridges() {
|
|
1030
|
+
return this.tarjan(false, true, false, false).bridges;
|
|
987
1031
|
}
|
|
988
1032
|
|
|
989
1033
|
protected abstract _addEdgeOnly(edge: EO): boolean;
|