yog/dag/models

Types

Opaque wrapper. Users can see the type, but not construct it directly.

pub opaque type Dag(node_data, edge_data)
pub type DagError {
  CycleDetected
}

Constructors

  • CycleDetected

Values

pub fn add_edge(
  dag: Dag(n, e),
  from src: Int,
  to dst: Int,
  with weight: e,
) -> Result(Dag(n, e), DagError)

Adds an edge to the DAG. Because adding an edge can potentially create a cycle, this operation must validate the resulting graph and returns a Result(Dag, DagError).

Time Complexity: O(V+E) (due to required cycle check on insertion).

pub fn add_node(dag: Dag(n, e), id: Int, data: n) -> Dag(n, e)

Adds a node to the DAG. This cannot create a cycle, so it is safe and guaranteed to return a Dag.

pub fn from_graph(
  graph: model.Graph(n, e),
) -> Result(Dag(n, e), DagError)

The Guard: Uses is_acyclic to validate the graph.

pub fn remove_edge(
  dag: Dag(n, e),
  from src: Int,
  to dst: Int,
) -> Dag(n, e)

Removes an edge from the DAG. This cannot create a cycle, so it is safe and guaranteed to return a Dag.

pub fn remove_node(dag: Dag(n, e), id: Int) -> Dag(n, e)

Removes a node from the DAG. This cannot create a cycle, so it is safe and guaranteed to return a Dag.

pub fn to_graph(dag: Dag(n, e)) -> model.Graph(n, e)

The Exit: Unwraps the Dag back into a standard Graph for general use.

Search Document