Skip to main content

DfsEdgeHooks

Trait DfsEdgeHooks 

Source
pub trait DfsEdgeHooks {
    // Provided methods
    fn enter_node(&mut self, node: u32, control: &mut DfsControl<'_>) -> bool { ... }
    fn leave_node(&mut self, node: u32, control: &mut DfsControl<'_>) { ... }
    fn visit_edge(
        &mut self,
        source: u32,
        target: u32,
        edge_index: u32,
        state: TargetState,
        control: &mut DfsControl<'_>,
    ) -> EdgeAction { ... }
}
Expand description

The hooks of a depth-first search of your own that looks at edges, which a DfsEdgeTraverser runs: a type of yours implements the hooks it needs - all three have defaults.

Java’s DfsEdgeTraverser is an abstract class whose subclass overrides enterNode, leaveNode and visitEdge; in Rust, the state of the search stays in the DfsEdgeTraverser, the hooks are this trait, and the protected methods isVisited, isOnStack and stop are on the DfsControl each hook receives.

Provided Methods§

Source

fn enter_node(&mut self, node: u32, control: &mut DfsControl<'_>) -> bool

Called when the search reaches node, before its out-edges: the preorder hook. Returns true unless implemented.

The search calls it once per node: for a start node, or for the target of an edge for which visit_edge returned EdgeAction::Descend while the target was unvisited. From this call on, node counts as visited and is on the current path. Returning false skips the out-edges of node: none of them is reported, and leave_node follows right away.

Source

fn leave_node(&mut self, node: u32, control: &mut DfsControl<'_>)

Called when the search leaves node, after all its out-edges have been reported and searched: 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 the run is stopped, it is not called for the nodes still on the path.

Source

fn visit_edge( &mut self, source: u32, target: u32, edge_index: u32, state: TargetState, control: &mut DfsControl<'_>, ) -> EdgeAction

Called for each out-edge of a node that the search has entered, with the state of its target; returns what the search does with the edge.

The search reports the out-edges of source in edge index order, between enter_node(source) and leave_node(source). It reports no out-edge of a node whose enter_node returned false. source is on the current path, and edge_index is the edge index of the edge source -> target. The state is that of the target when the edge is reported: an unvisited target that one edge skips is reported as unvisited again by the next edge to it. Unless implemented, returns EdgeAction::Descend for an unvisited target and EdgeAction::Skip for any other. EdgeAction::default_for(state) returns the same - Java’s super.visitEdge.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§