tsort

Topological Sort

Functions

FunctionDescription
tsort_newCreate a graph with n nodes (labeled 0..n-1).
tsort_add_edgeAdd a directed edge from → to.
tsort_sortTopological sort using Kahn’s algorithm. Returns vec of node IDs in topologic…
tsort_has_cycleCheck if graph has a cycle.
tsort_node_countNumber of nodes.
tsort_edge_countNumber of edges.

Details

tsort_new

fn tsort_new(n: i64) -> &i64

Create a graph with n nodes (labeled 0..n-1).

tsort_add_edge

fn tsort_add_edge(g: &i64, from: i64, to: i64)

Add a directed edge from → to.

tsort_sort

fn tsort_sort(g: &i64) -> &i64

Topological sort using Kahn’s algorithm. Returns vec of node IDs in topological order. If graph has a cycle, returns a vec shorter than node_count.

tsort_has_cycle

fn tsort_has_cycle(g: &i64) -> i64

Check if graph has a cycle.

tsort_node_count

fn tsort_node_count(g: &i64) -> i64

Number of nodes.

tsort_edge_count

fn tsort_edge_count(g: &i64) -> i64

Number of edges.