pub trait DfsHooks {
// Required method
fn enter_node(&mut self, node: u32, control: &mut DfsControl<'_>) -> bool;
// Provided method
fn leave_node(&mut self, node: u32, control: &mut DfsControl<'_>) { ... }
}Expand description
The hooks of a depth-first search of your own, which a DfsTraverser runs: a type of yours
implements enter_node and, if needed, leave_node.
Java’s DfsTraverser is an abstract class whose subclass overrides the hooks enterNode and
leaveNode and calls the protected methods isVisited, isOnStack and stop. In Rust, the
state of the search stays in the DfsTraverser, the hooks are this trait, and the protected
methods are on the DfsControl each hook receives. The hooks are called through a generic
parameter, so they are inlined into the loop of the search. A closure FnMut(u32) -> bool is a
set of hooks with only the preorder hook.
Required Methods§
Sourcefn enter_node(&mut self, node: u32, control: &mut DfsControl<'_>) -> bool
fn enter_node(&mut self, node: u32, control: &mut DfsControl<'_>) -> bool
Called when the search reaches node, before its out-nodes: the preorder hook.
The search calls it once per node: for a start node, or for an unvisited out-node of the node it
is searching. From this call on, node counts as visited and is on the current path. Returning
true lets the search go on with the out-nodes of node. Returning false skips them, and
leave_node follows right away; out-nodes skipped this way stay unvisited
unless the search reaches them from another node.
Provided Methods§
Sourcefn leave_node(&mut self, node: u32, control: &mut DfsControl<'_>)
fn leave_node(&mut self, node: u32, control: &mut DfsControl<'_>)
Called when the search leaves node, after it has searched from all its out-nodes: the postorder
hook. Does nothing unless implemented.
The search calls it once for every node it has visited, right after
enter_node if that returned false. From this call on, node is no longer
on the current path. After DfsControl::stop, it is not called for the nodes still on the path.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".