pub struct Graph<N> { /* private fields */ }Expand description
A directed graph over nodes of type N.
Implementations§
Source§impl<N> Graph<N>
impl<N> Graph<N>
Sourcepub fn add_edge(&mut self, from: N, to: N)
pub fn add_edge(&mut self, from: N, to: N)
Add an edge from -> to, meaning from depends on to.
Both endpoints are added as nodes if not already present.
The edge carries no explicit provenance; dep_edges() will report it as
DepSource::Structural by default. Use add_dep_edge on
Graph<NodeId> to record explicit provenance for v0.2 edges.
Sourcepub fn remove_edge(&mut self, from: &N, to: &N)
pub fn remove_edge(&mut self, from: &N, to: &N)
Remove an edge from -> to. No-op if absent.
Does not touch edge_sources. If the edge was inserted via
Graph::add_dep_edge on a Graph<NodeId>, the stale provenance entry
will survive and be returned by Graph::dep_edges if the edge is
re-added later. Use Graph::remove_dep_edge instead when provenance
correctness matters.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes in the graph.
Sourcepub fn dependencies_of<'a>(
&'a self,
n: &N,
) -> impl Iterator<Item = &'a N> + 'a + use<'a, N>
pub fn dependencies_of<'a>( &'a self, n: &N, ) -> impl Iterator<Item = &'a N> + 'a + use<'a, N>
Iterate the dependencies of n (the set edges[n]).
Sourcepub fn topological_sort(&self) -> Result<Vec<N>, Cycle<N>>
pub fn topological_sort(&self) -> Result<Vec<N>, Cycle<N>>
Topological sort using Kahn’s algorithm.
Returns nodes with no remaining dependencies first. Ties are broken by
the smallest node per Ord, so the result is deterministic.
Sourcepub fn reverse_topological_sort(&self) -> Result<Vec<N>, Cycle<N>>
pub fn reverse_topological_sort(&self) -> Result<Vec<N>, Cycle<N>>
Reverse topological sort: dependents first, dependencies last. Used for drop ordering (drop the index before the table it indexes).
Source§impl Graph<NodeId>
impl Graph<NodeId>
Sourcepub fn add_dep_edge(&mut self, from: NodeId, to: NodeId, source: DepSource)
pub fn add_dep_edge(&mut self, from: NodeId, to: NodeId, source: DepSource)
Add an edge from -> to and record its DepSource.
If an edge between these two nodes already exists (inserted via
Graph::add_edge or a prior call to this method), the source is
overwritten with the new value. Both endpoints are added as nodes if
not already present.
Use this instead of Graph::add_edge when populating v0.2 edges from
AST walks (AstExtracted) or -- @pgevolve dep: directives (AstDeclared).
Sourcepub fn remove_dep_edge(&mut self, from: &NodeId, to: &NodeId)
pub fn remove_dep_edge(&mut self, from: &NodeId, to: &NodeId)
Remove an edge from -> to and its DepSource from the source map.
No-op if the adjacency (or source entry) is absent.
Prefer this over Graph::remove_edge whenever the edge may have been
inserted via Self::add_dep_edge; it prevents stale provenance from
surviving a remove-then-re-add cycle.
Sourcepub fn dep_edges(&self) -> impl Iterator<Item = DepEdge> + '_
pub fn dep_edges(&self) -> impl Iterator<Item = DepEdge> + '_
Iterate edges as DepEdge records with per-edge provenance.
Edges inserted via Self::add_dep_edge carry their recorded
DepSource. Edges inserted via Graph::add_edge default to
DepSource::Structural, preserving v0.1 behaviour.
Trait Implementations§
Auto Trait Implementations§
impl<N> Freeze for Graph<N>
impl<N> RefUnwindSafe for Graph<N>where
N: RefUnwindSafe,
impl<N> Send for Graph<N>where
N: Send,
impl<N> Sync for Graph<N>where
N: Sync,
impl<N> Unpin for Graph<N>
impl<N> UnsafeUnpin for Graph<N>
impl<N> UnwindSafe for Graph<N>where
N: RefUnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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