( mutable: MutableGraph<N, E, T> )
| 890 | * @category transformations |
| 891 | */ |
| 892 | export const reverse = <N, E, T extends Kind = "directed">( |
| 893 | mutable: MutableGraph<N, E, T> |
| 894 | ): void => { |
| 895 | if (mutable.type === "undirected") { |
| 896 | return |
| 897 | } |
| 898 | |
| 899 | // Reverse all edges by swapping source and target |
| 900 | for (const [index, edgeData] of mutable.edges) { |
| 901 | mutable.edges.set(index, { |
| 902 | source: edgeData.target, |
| 903 | target: edgeData.source, |
| 904 | data: edgeData.data |
| 905 | }) |
| 906 | } |
| 907 | |
| 908 | rebuildAdjacency(mutable) |
| 909 | |
| 910 | // Invalidate cycle flag since edge directions changed |
| 911 | mutable.isAcyclic = Option.none() |
| 912 | } |
| 913 | |
| 914 | /** |
| 915 | * Filters and optionally transforms nodes in a mutable graph using a predicate function. |
nothing calls this directly
no test coverage detected