* 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 = {})
| 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 |
no test coverage detected