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

Function countDependents

src/ui-server/api/map.ts:784–804  ·  view source on GitHub ↗

* Per module: how many files outside it reference into it, and across how many * modules those files sit. * * One pass over the edge list. A pair whose two ends land in the same module is * internal cohesion, not blast radius, and is skipped; a pair touching a file * outside the chosen root has

(
  pairs: ReadonlyArray<{ source: string; target: string }>,
  moduleOfFile: Map<string, string>
)

Source from the content-addressed store, hash-verified

782 * references — twelve calls from one file are one file that has to be re-read.
783 */
784function countDependents(
785 pairs: ReadonlyArray<{ source: string; target: string }>,
786 moduleOfFile: Map<string, string>
787): Map<string, { files: number; modules: number }> {
788 const incoming = new Map<string, Set<string>>();
789 for (const pair of pairs) {
790 const from = moduleOfFile.get(pair.source);
791 const to = moduleOfFile.get(pair.target);
792 if (from === undefined || to === undefined || from === to) continue;
793 let seen = incoming.get(to);
794 if (!seen) incoming.set(to, (seen = new Set()));
795 seen.add(pair.source);
796 }
797 const out = new Map<string, { files: number; modules: number }>();
798 for (const [module, files] of incoming) {
799 const modules = new Set<string>();
800 for (const file of files) modules.add(moduleOfFile.get(file)!);
801 out.set(module, { files: files.size, modules: modules.size });
802 }
803 return out;
804}
805
806/**
807 * The circular imports inside the chosen root (see {@link findFileCycles}).

Callers 1

buildMapFunction · 0.85

Calls 3

getMethod · 0.65
setMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected