Function mz_ore::graph::try_nonrecursive_dft

source ยท
pub fn try_nonrecursive_dft<Graph, NodeId, AtEnter, AtExit, E>(
    graph: &Graph,
    root: NodeId,
    at_enter: &mut AtEnter,
    at_exit: &mut AtExit,
) -> Result<(), E>
where NodeId: Ord, AtEnter: FnMut(&Graph, &NodeId) -> Result<Vec<NodeId>, E>, AtExit: FnMut(&Graph, &NodeId) -> Result<(), E>,
Expand description

A non-recursive implementation of a fallible depth-first traversal starting from root.

Assumes that nodes in the graph all have unique node ids.

at_enter runs when entering a node. It is expected to return an in-order list of the children of the node. You can omit children from the list returned if you want to skip traversing the subgraphs corresponding to those children. If no children are omitted, at_enter can be thought of as a function that processes the nodes of the graph in pre-order.

at_exit runs when exiting a node. It can be thought of as a function that processes the nodes of the graph in post-order.

This function only enters and exits a node at most once and thus is safe to run even if the graph contains a cycle.