pub struct DFS<V, D, C>{ /* private fields */ }Expand description
Depth-first search over a finite graph.
Constructed via DFS::new with a builder-style API. The discovered set
is persisted internally, allowing multiple calls to traverse with
different start vertices while sharing visited-vertex state.
The type parameters D and C are the callback types for on_discover and
on_complete, respectively.
Implementations§
Source§impl<V, D, C> DFS<V, D, C>
impl<V, D, C> DFS<V, D, C>
Sourcepub fn traversal_direction(self, dir: TraversalDirection) -> Self
pub fn traversal_direction(self, dir: TraversalDirection) -> Self
Sets the traversal direction (outward or inward along edges).
Defaults to TraversalDirection::Outward.
Sourcepub fn on_discover<D2: FnMut(V)>(self, on_discover: D2) -> DFS<V, D2, C>
pub fn on_discover<D2: FnMut(V)>(self, on_discover: D2) -> DFS<V, D2, C>
Sets a callback invoked when a vertex is first discovered.
Sourcepub fn on_complete<C2: FnMut(V)>(self, on_complete: C2) -> DFS<V, D, C2>
pub fn on_complete<C2: FnMut(V)>(self, on_complete: C2) -> DFS<V, D, C2>
Sets a callback invoked when backtracking from a vertex after all its neighbors have been processed.
Sourcepub fn discovered(self, discovered: HashSet<V>) -> Self
pub fn discovered(self, discovered: HashSet<V>) -> Self
Provides a pre-populated discovered set, useful for resuming a traversal or excluding specific vertices.
Sourcepub fn traverse<G>(&mut self, graph: &G, start_vertex: V)
pub fn traverse<G>(&mut self, graph: &G, start_vertex: V)
Traverses the graph depth-first starting from the given vertex.
Vertices already in the discovered set are skipped, and newly visited
vertices are added to it. This allows multiple calls with different start
vertices to share state.
§Example
let mut discover_order = Vec::new();
let mut complete_order = Vec::new();
let mut dfs = DFS::new()
.traversal_direction(TraversalDirection::Outward)
.on_discover(|v| discover_order.push(v))
.on_complete(|v| complete_order.push(v));
dfs.traverse(&graph, start_vertex);Trait Implementations§
Auto Trait Implementations§
impl<V, D, C> Freeze for DFS<V, D, C>
impl<V, D, C> RefUnwindSafe for DFS<V, D, C>
impl<V, D, C> Send for DFS<V, D, C>
impl<V, D, C> Sync for DFS<V, D, C>
impl<V, D, C> Unpin for DFS<V, D, C>
impl<V, D, C> UnwindSafe for DFS<V, D, C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.