Data.Graph.Weighted.DAG
- Package
- purescript-hylograph-graph
- Repository
- afcondon/purescript-hylograph-graph
Data.Graph.Weighted.DAG
Directed Acyclic Graph (DAG) as a newtype over WeightedDigraph. Provides a smart constructor that validates acyclicity and DAG-specific algorithms like topological sort and layer computation.
#DAG Source
newtype DAG node weightA Directed Acyclic Graph (DAG) wrapping a WeightedDigraph.
The smart constructor fromWeightedDigraph guarantees acyclicity.
Use unsafeFromWeightedDigraph only when you know the input is acyclic.
#fromWeightedDigraph Source
fromWeightedDigraph :: forall node weight. Ord node => WeightedDigraph node weight -> Either (DAGError node) (DAG node weight)Create a DAG from a WeightedDigraph, validating that it's acyclic.
Returns Left (CycleDetected nodes) if a cycle is found.
#unsafeFromWeightedDigraph Source
unsafeFromWeightedDigraph :: forall node weight. WeightedDigraph node weight -> DAG node weightCreate a DAG without validation.
Warning: Only use this when you know the input is acyclic.
Using this with a cyclic graph will cause infinite loops in
algorithms like topologicalSort and depths.
#unsafeAddEdge Source
unsafeAddEdge :: forall node weight. Ord node => node -> node -> weight -> DAG node weight -> DAG node weightAdd an edge to the DAG without cycle validation.
Warning: Only use this when you know the edge won't create a cycle. This is useful for incremental building when you trust the input is acyclic.
#toWeightedDigraph Source
toWeightedDigraph :: forall node weight. DAG node weight -> WeightedDigraph node weightExtract the underlying WeightedDigraph
#topologicalSort Source
topologicalSort :: forall node weight. Ord node => DAG node weight -> Array nodeCompute topological sort using Kahn's algorithm.
Returns nodes in dependency order (sources first, sinks last). Since we've validated acyclicity, this always succeeds.
#edges Source
edges :: forall node weight. DAG node weight -> Array (WeightedEdge node weight)Get all edges