cairo_lang_sierra::algorithm::topological_order

Function get_topological_ordering

source
pub fn get_topological_ordering<E>(
    detect_cycles: bool,
    roots: impl Iterator<Item = StatementIdx>,
    node_count: usize,
    get_children: impl Fn(StatementIdx) -> Result<Vec<StatementIdx>, E>,
    out_of_bounds_err: impl Fn(StatementIdx) -> E,
    cycle_err: impl Fn(StatementIdx) -> E,
) -> Result<Vec<StatementIdx>, E>
Expand description

Returns the topological ordering.

detect_cycles - if true, the function will return an error if a cycle is detected, else will not detect the cycle, and ordering within cycles won’t be topological. roots - the roots of the graph. node_count - the number of nodes in the graph. get_children - a function that returns the children of a node. out_of_bounds_err - a function that returns an error for a node is out of bounds. cycle_err - a function that returns an error for a node that is part of a cycle. Note: Will only work properly if the nodes are in the range [0, node_count).