Build a GraphTraverser over a fixed node/edge set, honoring the `kinds` filter.
(nodes: Node[], edges: Edge[])
| 515 | |
| 516 | /** Build a GraphTraverser over a fixed node/edge set, honoring the `kinds` filter. */ |
| 517 | function 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 | |
| 537 | describe('Traversal edge-completeness & limits (#1086–#1090)', () => { |
| 538 | it('traverseBFS keeps every parallel edge to the same target (#1090)', () => { |
no test coverage detected