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

Function beginMutation

packages/effect/src/Graph.ts:596–615  ·  view source on GitHub ↗
(
  graph: Graph<N, E, T>
)

Source from the content-addressed store, hash-verified

594 * @since 3.18.0
595 */
596export const beginMutation = <N, E, T extends Kind = "directed">(
597 graph: Graph<N, E, T>
598): MutableGraph<N, E, T> => {
599 const source = graphImpl(graph)
600 const adjacency = cloneAdjacency(source.adjacency)
601 const reverseAdjacency = cloneAdjacency(source.reverseAdjacency)
602
603 const mutable: Mutable<GraphImpl<N, E, T>> = Object.create(ProtoGraph)
604 mutable.type = source.type
605 mutable.nodes = new Map(source.nodes)
606 mutable.edges = new Map(source.edges)
607 mutable.adjacency = adjacency
608 mutable.reverseAdjacency = reverseAdjacency
609 mutable.nextNodeIndex = source.nextNodeIndex
610 mutable.nextEdgeIndex = source.nextEdgeIndex
611 mutable.acyclic = source.acyclic
612 mutable.mutable = true
613
614 return Equal.byReferenceUnsafe(mutable as unknown as MutableGraph<N, E, T>)
615}
616
617/**
618 * Converts a mutable graph back to an immutable graph, ending the mutation scope.

Callers 1

Graph.tsFile · 0.70

Calls 2

graphImplFunction · 0.85
cloneAdjacencyFunction · 0.85

Tested by

no test coverage detected