(graph: Graph)
| 35 | * Verify that an object is a valid graph. |
| 36 | */ |
| 37 | export function verifyGraph(graph: Graph) { |
| 38 | const nodes = new Set(Object.keys(graph)); |
| 39 | for (const [node, edges] of Object.entries(graph)) { |
| 40 | for (const edge of edges) { |
| 41 | if (!nodes.has(edge)) { |
| 42 | throw new Error( |
| 43 | `Graph edge ${edge} of node ${node} not found in the graph`); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Transpose a directed graph i.e. reverse the direction of the edges. |
no test coverage detected
searching dependent graphs…