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

Function counted

__tests__/graph.test.ts:723–745  ·  view source on GitHub ↗

A graph traverser that records what was asked of `getNodesByIds`.

(nodes: Node[], edges: Edge[], honourKinds: boolean)

Source from the content-addressed store, hash-verified

721
722 /** A graph traverser that records what was asked of `getNodesByIds`. */
723 function counted(nodes: Node[], edges: Edge[], honourKinds: boolean) {
724 const byId = new Map(nodes.map((n) => [n.id, n]));
725 const asked: Array<{ ids: number; kinds: readonly string[] | undefined }> = [];
726 const q = {
727 getNodeById: (id: string) => byId.get(id) ?? null,
728 getNodesByIds: (ids: readonly string[], kinds?: readonly string[]) => {
729 asked.push({ ids: ids.length, kinds });
730 const m = new Map<string, Node>();
731 for (const id of ids) {
732 const n = byId.get(id);
733 if (n && (!honourKinds || !kinds || kinds.includes(n.kind))) m.set(id, n);
734 }
735 return m;
736 },
737 getOutgoingEdges: (source: string, kinds?: string[]) => edges.filter((e) => e.source === source && (!kinds || kinds.includes(e.kind))),
738 // With `honourKinds`, as the database answers it: no edge to a node of a kind not asked for.
739 getOutgoingEdgesToKinds: (source: string, kinds: string[] | undefined, nodeKinds: readonly string[]) =>
740 edges.filter((e) => e.source === source && (!kinds || kinds.includes(e.kind)) &&
741 (!honourKinds || !byId.has(e.target) || nodeKinds.includes(byId.get(e.target)!.kind))),
742 getIncomingEdges: (target: string, kinds?: string[]) => edges.filter((e) => e.target === target && (!kinds || kinds.includes(e.kind))),
743 };
744 return { traverser: new GraphTraverser(q as never), asked };
745 }
746
747 const site = (e: Edge) => `${e.source}|${e.target}|${e.kind}|${e.line ?? -1}|${e.column ?? -1}`;
748

Callers 1

graph.test.tsFile · 0.70

Calls 5

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

Tested by

no test coverage detected