MCPcopy Create free account
hub / github.com/Effect-TS/effect / reverse

Function reverse

packages/effect/src/Graph.ts:1969–1995  ·  view source on GitHub ↗
(
  mutable: MutableGraph<N, E, T>
)

Source from the content-addressed store, hash-verified

1967 * @since 3.18.0
1968 */
1969export 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.

Callers 1

reverseChunkFunction · 0.70

Calls 4

assertMutableFunction · 0.85
graphImplFunction · 0.85
rebuildAdjacencyFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected