Build a GraphTraverser over a fixed node/edge set, honoring the `kinds` filter.
(nodes: Node[], edges: Edge[])
| 534 | |
| 535 | /** Build a GraphTraverser over a fixed node/edge set, honoring the `kinds` filter. */ |
| 536 | function tGraph(nodes: Node[], edges: Edge[]): GraphTraverser { |
| 537 | const byId = new Map(nodes.map((n) => [n.id, n])); |
| 538 | const q = { |
| 539 | getNodeById: (id: string) => byId.get(id) ?? null, |
| 540 | getNodesByIds: (ids: readonly string[]) => { |
| 541 | const m = new Map<string, Node>(); |
| 542 | for (const id of ids) { |
| 543 | const n = byId.get(id); |
| 544 | if (n) m.set(id, n); |
| 545 | } |
| 546 | return m; |
| 547 | }, |
| 548 | getOutgoingEdges: (source: string, kinds?: string[]) => |
| 549 | edges.filter((e) => e.source === source && (!kinds || kinds.includes(e.kind))), |
| 550 | getIncomingEdges: (target: string, kinds?: string[]) => |
| 551 | edges.filter((e) => e.target === target && (!kinds || kinds.includes(e.kind))), |
| 552 | }; |
| 553 | return new GraphTraverser(q as never); |
| 554 | } |
| 555 | |
| 556 | describe('Traversal edge-completeness & limits (#1086–#1090)', () => { |
| 557 | it('findPath keeps shortest-path order without duplicate frontier entries', () => { |
no test coverage detected