MCPcopy
hub / github.com/colbymchenry/codegraph / tGraph

Function tGraph

__tests__/graph.test.ts:517–535  ·  view source on GitHub ↗

Build a GraphTraverser over a fixed node/edge set, honoring the `kinds` filter.

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

Source from the content-addressed store, hash-verified

515
516/** Build a GraphTraverser over a fixed node/edge set, honoring the `kinds` filter. */
517function tGraph(nodes: Node[], edges: Edge[]): GraphTraverser {
518 const byId = new Map(nodes.map((n) => [n.id, n]));
519 const q = {
520 getNodeById: (id: string) => byId.get(id) ?? null,
521 getNodesByIds: (ids: readonly string[]) => {
522 const m = new Map<string, Node>();
523 for (const id of ids) {
524 const n = byId.get(id);
525 if (n) m.set(id, n);
526 }
527 return m;
528 },
529 getOutgoingEdges: (source: string, kinds?: string[]) =>
530 edges.filter((e) => e.source === source && (!kinds || kinds.includes(e.kind))),
531 getIncomingEdges: (target: string, kinds?: string[]) =>
532 edges.filter((e) => e.target === target && (!kinds || kinds.includes(e.kind))),
533 };
534 return new GraphTraverser(q as never);
535}
536
537describe('Traversal edge-completeness & limits (#1086–#1090)', () => {
538 it('traverseBFS keeps every parallel edge to the same target (#1090)', () => {

Callers 1

graph.test.tsFile · 0.85

Calls 2

setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected