* A module's layer: one above the deepest thing it depends on. * * `visiting` guards a cycle the two-cycle break did not catch (a three-module * loop). Returning 0 there is not an answer, it is a floor — the module still * gets placed above whatever else it depends on, and the loop itself is *
( id: string, out: Map<string, string[]>, layer: Map<string, number>, visiting: Set<string> )
| 639 | * reported separately in {@link MapLayout.moduleCycles}. |
| 640 | */ |
| 641 | function longestPath( |
| 642 | id: string, |
| 643 | out: Map<string, string[]>, |
| 644 | layer: Map<string, number>, |
| 645 | visiting: Set<string> |
| 646 | ): number { |
| 647 | const known = layer.get(id); |
| 648 | if (known !== undefined) return known; |
| 649 | if (visiting.has(id)) return 0; |
| 650 | visiting.add(id); |
| 651 | let value = 0; |
| 652 | for (const next of out.get(id) ?? []) { |
| 653 | value = Math.max(value, longestPath(next, out, layer, visiting) + 1); |
| 654 | } |
| 655 | visiting.delete(id); |
| 656 | layer.set(id, value); |
| 657 | return value; |
| 658 | } |
| 659 | |
| 660 | /** Strongly connected components of three or more modules, in the drawn graph. */ |
| 661 | function moduleCycles(ids: readonly string[], edges: readonly MapEdgeLayout[]): string[][] { |