Hyperlinkv0.8.0-beta.28

Graph

Graph.undirectedconsteffect/Graph.ts:438
<N, E>(
  mutate?: (mutable: MutableUndirectedGraph<N, E>) => void
): UndirectedGraph<N, E>

Creates an undirected graph, optionally with initial mutations.

Example (Creating an undirected graph)

import { Graph } from "effect"

// Undirected graph with initial nodes and edges
const graph = Graph.undirected<string, string>((mutable) => {
  const a = Graph.addNode(mutable, "A")
  const b = Graph.addNode(mutable, "B")
  const c = Graph.addNode(mutable, "C")
  Graph.addEdge(mutable, a, b, "A-B")
  Graph.addEdge(mutable, b, c, "B-C")
})
constructors
Source effect/Graph.ts:43820 lines
export const undirected = <N, E>(mutate?: (mutable: MutableUndirectedGraph<N, E>) => void): UndirectedGraph<N, E> => {
  const graph: Mutable<UndirectedGraph<N, E>> = Object.create(ProtoGraph)
  graph.type = "undirected"
  graph.nodes = new Map()
  graph.edges = new Map()
  graph.adjacency = new Map()
  graph.reverseAdjacency = new Map()
  graph.nextNodeIndex = 0
  graph.nextEdgeIndex = 0
  graph.acyclic = Option.some(true)
  graph.mutable = false

  if (mutate) {
    const mutable = beginMutation(graph)
    mutate(mutable as MutableUndirectedGraph<N, E>)
    return endMutation(mutable)
  }

  return graph
}