pub struct FrontierControl<'a> { /* private fields */ }Expand description
What a hook may ask or do during a run of a FrontierTraverser: put nodes into the frontier,
ask whether a node is visited and which level is being visited, keep nodes out of the search, and
stop the run - the protected members of Java’s FrontierTraverser.
Implementations§
Source§impl FrontierControl<'_>
impl FrontierControl<'_>
Sourcepub fn graph(&self) -> &Graph
pub fn graph(&self) -> &Graph
Returns the graph that the search runs on - Java’s protected field graph.
Time: O(1).
Sourcepub fn enqueue_children(&mut self, node: u32)
pub fn enqueue_children(&mut self, node: u32)
Puts the out-nodes of node that are not visited yet into the frontier, in ascending order, and
marks them visited.
Called from visit_node(node), it makes the traversal a breadth-first
search. Outside a run, FrontierTraverser::enqueue_children adds the nodes to the next run, as
FrontierTraverser::enqueue does.
Time: O(out_degree(node)).
§Panics
With an index out of bounds message if node is not in 0..node_count.
Sourcepub fn enqueue(&mut self, node: u32) -> bool
pub fn enqueue(&mut self, node: u32) -> bool
Puts node into the frontier and marks it visited, unless it is visited already. Returns true if
node was not visited and is now in the frontier.
Called from a hook, it adds node to the next level. Outside a run, FrontierTraverser::enqueue
adds node to the next run: the nodes enqueued then come first in its level 0, ahead of its start
nodes, and FrontierTraverser::run visits them before it starts from a node of its own.
Time: O(1).
§Panics
With an index out of bounds message if node is not in 0..node_count.
Sourcepub fn is_visited(&self, node: u32) -> bool
pub fn is_visited(&self, node: u32) -> bool
Returns whether node is visited: it has entered the frontier, or it was marked with
mark_visited.
node is a node ID in 0..node_count; for any other value the method returns false or panics
with an index out of bounds message.
Time: O(1).
Sourcepub fn mark_visited(&mut self, node: u32)
pub fn mark_visited(&mut self, node: u32)
Marks node visited without putting it into the frontier, to keep it out of the search - what a
Java subclass does with the protected bit set visited.
A marked node counts as visited and no longer enters the frontier, neither from a run method nor
from enqueue or enqueue_children. A node already in
the frontier is visited all the same. Java’s subclass must not clear a bit of visited; Rust
offers no way to.
Time: O(1).
§Panics
With an index out of bounds message if node is not in 0..node_count.
Sourcepub fn current_level(&self) -> u32
pub fn current_level(&self) -> u32
Returns the level of the node being visited: 0 for the start nodes, k + 1 for the nodes that
entered the frontier while level k was visited.
In leave_level, it is the level just completed.
Time: O(1).
Sourcepub fn stop(&mut self)
pub fn stop(&mut self)
Stops the run in progress: the run returns as soon as the hook that calls this method returns, without calling another hook.
The nodes still waiting in the frontier are dropped from it, but stay marked visited, so no later run visits them. A later run skips every node visited so far. To cancel a run from another thread, let a hook check a flag of your own and call this method.
Time: O(1).