85
*/
86
findCycleSlow() {
87
>
for (const [id, node] of this._nodes) {
graph.ts
88
>
const seen = new Set<string>([id]);
89
>
const res = this._findCycle(node, seen);
90
>
if (res) {
91
>
return res;
92
>
}
93
>
}
94
return undefined;
96
97
private _findCycle(node: Node<T>, seen: Set<string>): string | undefined {
98
>
for (const [id, outgoing] of node.outgoing) {
graph.ts
99
>
if (seen.has(id)) {
100
>
return [...seen, id].join(' -> ');
101
>
}
102
>
seen.add(id);
103
>
const value = this._findCycle(outgoing, seen);
104
>
if (value) {
105
>
return value;
106
>
}
107
seen.delete(id);
108
}
109
return undefined;
111
}