(root: string)
| 674 | const state = new Map<string, number>(); |
| 675 | const closes = new Set<WireMapLink>(); |
| 676 | const visit = (root: string): void => { |
| 677 | const stack: { id: string; next: number }[] = [{ id: root, next: 0 }]; |
| 678 | state.set(root, 1); |
| 679 | while (stack.length > 0) { |
| 680 | const top = stack[stack.length - 1]!; |
| 681 | const list = out.get(top.id) ?? []; |
| 682 | if (top.next >= list.length) { |
| 683 | state.set(top.id, 2); |
| 684 | stack.pop(); |
| 685 | continue; |
| 686 | } |
| 687 | const link = list[top.next++]!; |
| 688 | const seen = state.get(link.target) ?? 0; |
| 689 | if (seen === 1) { |
| 690 | closes.add(link); |
| 691 | continue; |
| 692 | } |
| 693 | if (seen === 2) continue; |
| 694 | state.set(link.target, 1); |
| 695 | stack.push({ id: link.target, next: 0 }); |
| 696 | } |
| 697 | }; |
| 698 | for (const id of nodes) if (!state.has(id)) visit(id); |
| 699 | return links.filter((l) => !closes.has(l)); |
| 700 | } |
no test coverage detected