rustc_data_structures::graph::iterate

Struct TriColorDepthFirstSearch

Source
pub struct TriColorDepthFirstSearch<'graph, G>{
    graph: &'graph G,
    stack: Vec<Event<G::Node>>,
    visited: BitSet<G::Node>,
    settled: BitSet<G::Node>,
}
Expand description

A depth-first search that also tracks when all successors of a node have been examined.

This is based on the DFS described in Introduction to Algorithms (1st ed.), hereby referred to as CLR. However, we use the terminology in NodeStatus above instead of “discovered”/“finished” or “white”/“grey”/“black”. Each node begins the search with no status, becomes Visited when it is first examined by the DFS and is Settled when all nodes reachable from it have been examined. This allows us to differentiate between “tree”, “back” and “forward” edges (see TriColorVisitor::node_examined).

Unlike the pseudocode in CLR, this implementation is iterative and does not use timestamps. We accomplish this by storing Events on the stack that result in a (possible) state change for each node. A Visited event signifies that we should examine this node if it has not yet been Visited or Settled. When a node is examined for the first time, we mark it as Visited and push a Settled event for it on stack followed by Visited events for all of its predecessors, scheduling them for examination. Multiple Visited events for a single node may exist on the stack simultaneously if a node has multiple predecessors, but only one Settled event will ever be created for each node. After all Visited events for a node’s successors have been popped off the stack (as well as any new events triggered by visiting those successors), we will pop off that node’s Settled event.

Fields§

§graph: &'graph G§stack: Vec<Event<G::Node>>§visited: BitSet<G::Node>§settled: BitSet<G::Node>

Implementations§

Source§

impl<'graph, G> TriColorDepthFirstSearch<'graph, G>

Source

pub fn new(graph: &'graph G) -> Self

Source

pub fn run_from<V>(self, root: G::Node, visitor: &mut V) -> Option<V::BreakVal>
where V: TriColorVisitor<G>,

Performs a depth-first search, starting from the given root.

This won’t visit nodes that are not reachable from root.

Source§

impl<G> TriColorDepthFirstSearch<'_, G>

Source

pub fn run_from_start<V>(self, visitor: &mut V) -> Option<V::BreakVal>
where V: TriColorVisitor<G>,

Performs a depth-first search, starting from G::start_node().

This won’t visit nodes that are not reachable from the start node.

Auto Trait Implementations§

§

impl<'graph, G> DynSend for TriColorDepthFirstSearch<'graph, G>
where G: DynSync + ?Sized, <G as DirectedGraph>::Node: DynSend,

§

impl<'graph, G> DynSync for TriColorDepthFirstSearch<'graph, G>
where G: DynSync + ?Sized, <G as DirectedGraph>::Node: DynSync,

§

impl<'graph, G> Freeze for TriColorDepthFirstSearch<'graph, G>
where G: ?Sized,

§

impl<'graph, G> RefUnwindSafe for TriColorDepthFirstSearch<'graph, G>

§

impl<'graph, G> Send for TriColorDepthFirstSearch<'graph, G>
where G: Sync + ?Sized, <G as DirectedGraph>::Node: Send,

§

impl<'graph, G> Sync for TriColorDepthFirstSearch<'graph, G>
where G: Sync + ?Sized, <G as DirectedGraph>::Node: Sync,

§

impl<'graph, G> Unpin for TriColorDepthFirstSearch<'graph, G>
where <G as DirectedGraph>::Node: Unpin, G: ?Sized,

§

impl<'graph, G> UnwindSafe for TriColorDepthFirstSearch<'graph, G>

Blanket Implementations§

Source§

impl<T> Aligned for T

Source§

const ALIGN: Alignment = const ALIGN: Alignment = Alignment::of::<Self>();

Alignment of Self.
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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.