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

Method traverseDFS

src/graph/traversal.ts:154–177  ·  view source on GitHub ↗

* Traverse the graph using depth-first search * * @param startId - Starting node ID * @param options - Traversal options * @returns Subgraph containing traversed nodes and edges

(startId: string, options: TraversalOptions = {})

Source from the content-addressed store, hash-verified

152 * @returns Subgraph containing traversed nodes and edges
153 */
154 traverseDFS(startId: string, options: TraversalOptions = {}): Subgraph {
155 const opts = { ...DEFAULT_OPTIONS, ...options };
156 const startNode = this.queries.getNodeById(startId);
157
158 if (!startNode) {
159 return { nodes: new Map(), edges: [], roots: [] };
160 }
161
162 const nodes = new Map<string, Node>();
163 const edges: Edge[] = [];
164 const visited = new Set<string>();
165
166 if (opts.includeStart) {
167 nodes.set(startNode.id, startNode);
168 }
169
170 this.dfsRecursive(startNode, 0, opts, nodes, edges, visited);
171
172 return {
173 nodes,
174 edges,
175 roots: [startId],
176 };
177 }
178
179 /**
180 * Recursive DFS helper

Callers 1

graph.test.tsFile · 0.80

Calls 3

dfsRecursiveMethod · 0.95
setMethod · 0.80
getNodeByIdMethod · 0.65

Tested by

no test coverage detected