( mutable: MutableGraph<N, E, T> )
| 1967 | * @since 3.18.0 |
| 1968 | */ |
| 1969 | export const reverse = <N, E, T extends Kind = "directed">( |
| 1970 | mutable: MutableGraph<N, E, T> |
| 1971 | ): void => { |
| 1972 | assertMutable(mutable) |
| 1973 | const impl = graphImpl(mutable) |
| 1974 | |
| 1975 | if (impl.type === "undirected") { |
| 1976 | return |
| 1977 | } |
| 1978 | |
| 1979 | // Reverse all edges by swapping source and target |
| 1980 | for (const [index, edgeData] of impl.edges) { |
| 1981 | impl.edges.set( |
| 1982 | index, |
| 1983 | new Edge({ |
| 1984 | source: edgeData.target, |
| 1985 | target: edgeData.source, |
| 1986 | data: edgeData.data |
| 1987 | }) |
| 1988 | ) |
| 1989 | } |
| 1990 | |
| 1991 | rebuildAdjacency(impl) |
| 1992 | |
| 1993 | // Invalidate cycle flag since edge directions changed |
| 1994 | impl.acyclic = Option.none() |
| 1995 | } |
| 1996 | |
| 1997 | /** |
| 1998 | * Filters and optionally transforms nodes in a mutable graph using a predicate function. |
no test coverage detected