Autonoma.Graph (Autonoma v0.2.8)

Copy Markdown View Source

Topological sorting via Kahn's algorithm and cycle detection via Tarjan's SCC.

Summary

Functions

Find a nullable FK edge in a cycle that can be deferred. Returns the edge or nil.

Tarjan's SCC algorithm to identify exact cycles among remaining nodes. Returns only SCCs with more than 1 node.

Topological sort of nodes by FK dependency edges. Returns %{sorted: [String.t()], cycles: [[String.t()]]}.

Types

fk_edge()

@type fk_edge() :: %{
  from: String.t(),
  to: String.t(),
  local_field: String.t(),
  foreign_field: String.t(),
  nullable: boolean()
}

Functions

find_deferrable_edge(cycle, edges)

Find a nullable FK edge in a cycle that can be deferred. Returns the edge or nil.

find_sccs(nodes, edges)

Tarjan's SCC algorithm to identify exact cycles among remaining nodes. Returns only SCCs with more than 1 node.

topo_sort(nodes, edges)

Topological sort of nodes by FK dependency edges. Returns %{sorted: [String.t()], cycles: [[String.t()]]}.

After detecting cycles, runs a second pass to sort nodes that depend on cycle members but aren't in cycles themselves.