MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / longestPath

Function longestPath

ui/src/lib/map-model.ts:641–658  ·  view source on GitHub ↗

* 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>
)

Source from the content-addressed store, hash-verified

639 * reported separately in {@link MapLayout.moduleCycles}.
640 */
641function 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. */
661function moduleCycles(ids: readonly string[], edges: readonly MapEdgeLayout[]): string[][] {

Callers 1

buildMapLayoutFunction · 0.85

Calls 5

hasMethod · 0.80
getMethod · 0.65
deleteMethod · 0.65
addMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected