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

Function foldModuleRows

src/db/queries.ts:5956–6027  ·  view source on GitHub ↗
(
  rows: ReadonlyArray<ModuleGroupRow>,
  options: { topPairsPerLink: number; pairKinds: readonly EdgeKind[] }
)

Source from the content-addressed store, hash-verified

5954}
5955
5956function foldModuleRows(
5957 rows: ReadonlyArray<ModuleGroupRow>,
5958 options: { topPairsPerLink: number; pairKinds: readonly EdgeKind[] }
5959): { links: ModuleLinkTotal[]; pairs: ModulePairTotal[] } {
5960 // A module id is a path and may contain anything printable, so the key
5961 // separator has to be something a path cannot hold.
5962 const SEP = '\u0000';
5963 const links = new Map<string, ModuleLinkTotal>();
5964 const pairKinds = new Set(options.pairKinds);
5965 const wantPairs = options.topPairsPerLink > 0 && pairKinds.size > 0;
5966 const pairTotals = new Map<string, ModulePairTotal>();
5967
5968 for (const row of rows) {
5969 const linkKey = `${row.source}${SEP}${row.target}${SEP}${row.kind}`;
5970 const link = links.get(linkKey);
5971 if (link) {
5972 link.count += row.count;
5973 link.declared += row.declared;
5974 link.uncertain += row.uncertain;
5975 } else {
5976 links.set(linkKey, {
5977 source: row.source,
5978 target: row.target,
5979 kind: row.kind,
5980 count: row.count,
5981 declared: row.declared,
5982 uncertain: row.uncertain,
5983 });
5984 }
5985
5986 // Only the confident half of a row can be named: an uncertain edge is a
5987 // guess, and printing "a to b, 12" for twelve guesses is the map claiming
5988 // something it does not know.
5989 if (!wantPairs || row.count === 0 || !pairKinds.has(row.kind)) continue;
5990 const pairKey = `${row.source}${SEP}${row.target}${SEP}${row.from}${SEP}${row.to}`;
5991 const pair = pairTotals.get(pairKey);
5992 if (pair) {
5993 pair.count += row.count;
5994 pair.declared += row.declared;
5995 } else {
5996 pairTotals.set(pairKey, {
5997 source: row.source,
5998 target: row.target,
5999 from: row.from,
6000 to: row.to,
6001 count: row.count,
6002 declared: row.declared,
6003 });
6004 }
6005 }
6006
6007 const byLink = new Map<string, ModulePairTotal[]>();
6008 for (const pair of pairTotals.values()) {
6009 const key = `${pair.source}${SEP}${pair.target}`;
6010 let list = byLink.get(key);
6011 if (!list) byLink.set(key, (list = []));
6012 list.push(pair);
6013 }

Callers 1

aggregateModuleGraphMethod · 0.85

Calls 4

hasMethod · 0.80
pushMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected