( mutable: MutableGraph<N, E, T> )
| 2289 | * @since 3.18.0 |
| 2290 | */ |
| 2291 | export const reverse = <N, E, T extends Kind = "directed">( |
| 2292 | mutable: MutableGraph<N, E, T> |
| 2293 | ): void => { |
| 2294 | const impl = getMutableImplForMutation(mutable) |
| 2295 | if (impl.type === "undirected") { |
| 2296 | return |
| 2297 | } |
| 2298 | |
| 2299 | // Reverse all edges by swapping source and target |
| 2300 | for (const [index, edgeData] of impl.edges) { |
| 2301 | impl.edges.set(index, { |
| 2302 | source: edgeData.target, |
| 2303 | target: edgeData.source, |
| 2304 | data: edgeData.data |
| 2305 | }) |
| 2306 | } |
| 2307 | |
| 2308 | const adjacency = impl.adjacency |
| 2309 | impl.adjacency = impl.reverseAdjacency |
| 2310 | impl.reverseAdjacency = adjacency |
| 2311 | |
| 2312 | // Invalidate cycle flag since edge directions changed |
| 2313 | impl.acyclic = Option.none() |
| 2314 | } |
| 2315 | |
| 2316 | /** |
| 2317 | * Filters and optionally transforms nodes in a mutable graph using a predicate function. |
no test coverage detected