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

Function foldModuleRows

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

Source from the content-addressed store, hash-verified

6073}
6074
6075function foldModuleRows(
6076 rows: ReadonlyArray<ModuleGroupRow>,
6077 options: { topPairsPerLink: number; pairKinds: readonly EdgeKind[] }
6078): { links: ModuleLinkTotal[]; pairs: ModulePairTotal[] } {
6079 // A module id is a path and may contain anything printable, so the key
6080 // separator has to be something a path cannot hold.
6081 const SEP = '\u0000';
6082 const links = new Map<string, ModuleLinkTotal>();
6083 const pairKinds = new Set(options.pairKinds);
6084 const wantPairs = options.topPairsPerLink > 0 && pairKinds.size > 0;
6085 const pairTotals = new Map<string, ModulePairTotal>();
6086
6087 for (const row of rows) {
6088 const linkKey = `${row.source}${SEP}${row.target}${SEP}${row.kind}`;
6089 const link = links.get(linkKey);
6090 if (link) {
6091 link.count += row.count;
6092 link.declared += row.declared;
6093 link.uncertain += row.uncertain;
6094 } else {
6095 links.set(linkKey, {
6096 source: row.source,
6097 target: row.target,
6098 kind: row.kind,
6099 count: row.count,
6100 declared: row.declared,
6101 uncertain: row.uncertain,
6102 });
6103 }
6104
6105 // Only the confident half of a row can be named: an uncertain edge is a
6106 // guess, and printing "a to b, 12" for twelve guesses is the map claiming
6107 // something it does not know.
6108 if (!wantPairs || row.count === 0 || !pairKinds.has(row.kind)) continue;
6109 const pairKey = `${row.source}${SEP}${row.target}${SEP}${row.from}${SEP}${row.to}`;
6110 const pair = pairTotals.get(pairKey);
6111 if (pair) {
6112 pair.count += row.count;
6113 pair.declared += row.declared;
6114 } else {
6115 pairTotals.set(pairKey, {
6116 source: row.source,
6117 target: row.target,
6118 from: row.from,
6119 to: row.to,
6120 count: row.count,
6121 declared: row.declared,
6122 });
6123 }
6124 }
6125
6126 const byLink = new Map<string, ModulePairTotal[]>();
6127 for (const pair of pairTotals.values()) {
6128 const key = `${pair.source}${SEP}${pair.target}`;
6129 let list = byLink.get(key);
6130 if (!list) byLink.set(key, (list = []));
6131 list.push(pair);
6132 }

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