pub struct Dag<N: GraphNodeId, S: BuildHasher = FixedHasher> { /* private fields */ }Expand description
A directed acyclic graph structure.
Implementations§
Source§impl<N: GraphNodeId, S: BuildHasher> Dag<N, S>
impl<N: GraphNodeId, S: BuildHasher> Dag<N, S>
Sourcepub fn graph_mut(&mut self) -> &mut DiGraph<N, S>
pub fn graph_mut(&mut self) -> &mut DiGraph<N, S>
Mutable access to the underlying directed graph. Marks the graph as dirty.
Sourcepub fn is_dirty(&self) -> bool
pub fn is_dirty(&self) -> bool
Returns whether the graph is dirty (i.e., has been modified since the last topological sort).
Sourcepub fn is_toposorted(&self) -> bool
pub fn is_toposorted(&self) -> bool
Returns whether the graph is topologically sorted (i.e., not dirty).
Sourcepub fn ensure_toposorted(&mut self) -> Result<(), DiGraphToposortError<N>>
pub fn ensure_toposorted(&mut self) -> Result<(), DiGraphToposortError<N>>
Ensures the graph is topologically sorted, recomputing the toposort if the graph is dirty.
§Errors
Returns DiGraphToposortError if the DAG is dirty and cannot be
topologically sorted.
Sourcepub fn get_toposort(&self) -> Option<&[N]>
pub fn get_toposort(&self) -> Option<&[N]>
Returns the cached toposort if the graph is not dirty, otherwise returns
None.
Sourcepub fn toposort(&mut self) -> Result<&[N], DiGraphToposortError<N>>
pub fn toposort(&mut self) -> Result<&[N], DiGraphToposortError<N>>
Returns a topological ordering of the graph, computing it if the graph is dirty.
§Errors
Returns DiGraphToposortError if the DAG is dirty and cannot be
topologically sorted.
Sourcepub fn toposort_and_graph(
&mut self,
) -> Result<(&[N], &DiGraph<N, S>), DiGraphToposortError<N>>
pub fn toposort_and_graph( &mut self, ) -> Result<(&[N], &DiGraph<N, S>), DiGraphToposortError<N>>
Returns both the topological ordering and the underlying graph, computing the toposort if the graph is dirty.
This function is useful to avoid multiple borrow issues when both the graph and the toposort are needed.
§Errors
Returns DiGraphToposortError if the DAG is dirty and cannot be
topologically sorted.
Sourcepub fn analyze(&mut self) -> Result<DagAnalysis<N, S>, DiGraphToposortError<N>>where
S: Default,
pub fn analyze(&mut self) -> Result<DagAnalysis<N, S>, DiGraphToposortError<N>>where
S: Default,
Processes a DAG and computes various properties about it.
See DagAnalysis::new for details on what is computed.
§Note
If the DAG is dirty, this method will first attempt to topologically sort it.
§Errors
Returns DiGraphToposortError if the DAG is dirty and cannot be
topologically sorted.
Sourcepub fn remove_redundant_edges(&mut self, analysis: &DagAnalysis<N, S>)where
S: Clone,
pub fn remove_redundant_edges(&mut self, analysis: &DagAnalysis<N, S>)where
S: Clone,
Replaces the current graph with its transitive reduction based on the provided analysis.
§Note
The given DagAnalysis must have been generated from this DAG.
Sourcepub fn group_by_key<K, V>(
&mut self,
num_groups: usize,
) -> Result<DagGroups<K, V, S>, DiGraphToposortError<N>>
pub fn group_by_key<K, V>( &mut self, num_groups: usize, ) -> Result<DagGroups<K, V, S>, DiGraphToposortError<N>>
Groups nodes in this DAG by a key type K, collecting value nodes V
under all of their ancestor key nodes. num_groups hints at the
expected number of groups, for memory allocation optimization.
The node type N must be convertible into either a key type K or
a value type V via the TryInto trait.
§Errors
Returns DiGraphToposortError if the DAG is dirty and cannot be
topologically sorted.
Sourcepub fn try_convert<T>(self) -> Result<Dag<T, S>, N::Error>
pub fn try_convert<T>(self) -> Result<Dag<T, S>, N::Error>
Converts from one GraphNodeId type to another. If the conversion fails,
it returns the error from the target type’s TryFrom implementation.
Nodes must uniquely convert from N to T (i.e. no two N can convert
to the same T). The resulting DAG must be re-topologically sorted.
§Errors
If the conversion fails, it returns an error of type N::Error.
Trait Implementations§
Source§impl<N: Clone + GraphNodeId, S: Clone + BuildHasher> Clone for Dag<N, S>
impl<N: Clone + GraphNodeId, S: Clone + BuildHasher> Clone for Dag<N, S>
Source§impl<N: GraphNodeId, S: BuildHasher> Debug for Dag<N, S>
impl<N: GraphNodeId, S: BuildHasher> Debug for Dag<N, S>
Source§impl<N: GraphNodeId, S: BuildHasher + Default> Default for Dag<N, S>
impl<N: GraphNodeId, S: BuildHasher + Default> Default for Dag<N, S>
Source§impl<N: GraphNodeId, S: BuildHasher> Deref for Dag<N, S>
impl<N: GraphNodeId, S: BuildHasher> Deref for Dag<N, S>
Source§impl<N: GraphNodeId, S: BuildHasher> DerefMut for Dag<N, S>
impl<N: GraphNodeId, S: BuildHasher> DerefMut for Dag<N, S>
Auto Trait Implementations§
impl<N, S> Freeze for Dag<N, S>where
S: Freeze,
impl<N, S> RefUnwindSafe for Dag<N, S>where
S: RefUnwindSafe,
N: RefUnwindSafe,
<N as GraphNodeId>::Edge: RefUnwindSafe,
<N as GraphNodeId>::Adjacent: RefUnwindSafe,
impl<N, S> Send for Dag<N, S>
impl<N, S> Sync for Dag<N, S>
impl<N, S> Unpin for Dag<N, S>
impl<N, S> UnwindSafe for Dag<N, S>where
S: UnwindSafe,
N: UnwindSafe,
<N as GraphNodeId>::Edge: UnwindSafe,
<N as GraphNodeId>::Adjacent: UnwindSafe,
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().