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

Function reverse

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

Source from the content-addressed store, hash-verified

2289 * @since 3.18.0
2290 */
2291export 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.

Callers 1

reverseChunkFunction · 0.70

Calls 2

setMethod · 0.65

Tested by

no test coverage detected