Dag

Struct Dag 

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

Source

pub fn new() -> Self
where S: Default,

Creates a new directed acyclic graph.

Source

pub fn graph(&self) -> &DiGraph<N, S>

Read-only access to the underlying directed graph.

Source

pub fn graph_mut(&mut self) -> &mut DiGraph<N, S>

Mutable access to the underlying directed graph. Marks the graph as dirty.

Source

pub fn is_dirty(&self) -> bool

Returns whether the graph is dirty (i.e., has been modified since the last topological sort).

Source

pub fn is_toposorted(&self) -> bool

Returns whether the graph is topologically sorted (i.e., not dirty).

Source

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.

Source

pub fn get_toposort(&self) -> Option<&[N]>

Returns the cached toposort if the graph is not dirty, otherwise returns None.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn group_by_key<K, V>( &mut self, num_groups: usize, ) -> Result<DagGroups<K, V, S>, DiGraphToposortError<N>>
where N: TryInto<K, Error = V>, K: Eq + Hash, V: Clone + Eq + Hash, S: BuildHasher + Default,

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.

Source

pub fn try_convert<T>(self) -> Result<Dag<T, S>, N::Error>
where N: TryInto<T>, T: GraphNodeId, S: Default,

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>

Source§

fn clone(&self) -> Dag<N, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<N: GraphNodeId, S: BuildHasher> Debug for Dag<N, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<N: GraphNodeId, S: BuildHasher + Default> Default for Dag<N, S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<N: GraphNodeId, S: BuildHasher> Deref for Dag<N, S>

Source§

type Target = Graph<true, N, S>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<N: GraphNodeId, S: BuildHasher> DerefMut for Dag<N, S>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<N, S> Freeze for Dag<N, S>
where S: Freeze,

§

impl<N, S> RefUnwindSafe for Dag<N, S>

§

impl<N, S> Send for Dag<N, S>
where S: Send, N: Send, <N as GraphNodeId>::Edge: Send, <N as GraphNodeId>::Adjacent: Send,

§

impl<N, S> Sync for Dag<N, S>
where S: Sync, N: Sync, <N as GraphNodeId>::Edge: Sync, <N as GraphNodeId>::Adjacent: Sync,

§

impl<N, S> Unpin for Dag<N, S>
where S: Unpin, N: Unpin, <N as GraphNodeId>::Edge: Unpin, <N as GraphNodeId>::Adjacent: Unpin,

§

impl<N, S> UnwindSafe for Dag<N, S>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

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

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
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<T> ConditionalSend for T
where T: Send,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,