# Function mz_ore::graph::nonrecursive_dft

source · [−]`pub fn nonrecursive_dft<Graph, NodeId, AtEnter, AtExit>(`

graph: &Graph,

root: NodeId,

at_enter: &mut AtEnter,

at_exit: &mut AtExit

) where

NodeId: Eq + Hash,

AtEnter: FnMut(&Graph, &NodeId) -> Vec<NodeId>,

AtExit: FnMut(&Graph, &NodeId),

## Expand description

A non-recursive implementation of an infallible 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 the traversing 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.