(id: string)
| 11 | const numbers = new Map<string, number>(), low = new Map<string, number>(); |
| 12 | const stack: string[] = [], active = new Set<string>(), groups: string[][] = []; |
| 13 | const visit = (id: string) => { |
| 14 | numbers.set(id, numbers.size); low.set(id, numbers.get(id)!); stack.push(id); active.add(id); |
| 15 | for (const target of [...adjacent.get(id)!].sort()) { |
| 16 | if (!numbers.has(target)) { visit(target); low.set(id, Math.min(low.get(id)!, low.get(target)!)); } |
| 17 | else if (active.has(target)) low.set(id, Math.min(low.get(id)!, numbers.get(target)!)); |
| 18 | } |
| 19 | if (low.get(id) === numbers.get(id)) { |
| 20 | const group: string[] = []; let next: string; |
| 21 | do { next = stack.pop()!; active.delete(next); group.push(next); } while (next !== id); |
| 22 | groups.push(group.sort()); |
| 23 | } |
| 24 | }; |
| 25 | services.forEach(service => { if (!numbers.has(service.id)) visit(service.id); }); |
| 26 | const membership = new Map(groups.flatMap((group, index) => group.map(id => [id, index] as const))); |
| 27 | const outgoing = groups.map(() => new Set<number>()), incoming = groups.map(() => 0), layers = groups.map(() => 0); |
no test coverage detected