Skip to main content

FrontierControl

Struct FrontierControl 

Source
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<'_>

Source

pub fn graph(&self) -> &Graph

Returns the graph that the search runs on - Java’s protected field graph.

Time: O(1).

Source

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.

Source

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.

Source

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).

Source

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.

Source

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).

Source

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).

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for FrontierControl<'a>

§

impl<'a> Freeze for FrontierControl<'a>

§

impl<'a> RefUnwindSafe for FrontierControl<'a>

§

impl<'a> Send for FrontierControl<'a>

§

impl<'a> Sync for FrontierControl<'a>

§

impl<'a> Unpin for FrontierControl<'a>

§

impl<'a> UnsafeUnpin for FrontierControl<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.