pub struct DirectedAcyclicGraph { /* private fields */ }
Expand description

A mutable, single-threaded directed acyclic graph.

Implementations§

source§

impl DirectedAcyclicGraph

source

pub fn empty(vertex_count: u32) -> Self

source

pub fn from_edges_iter<I: Iterator<Item = (u32, u32)>>( vertex_count: u32, edges: I ) -> Self

Constructs a DAG from an iterator of edges.

Requires u < vertex_count && v < vertex_count && u < v for every edge (u, v) in edges. Panics otherwise.

source

pub fn from_raw_edges(vertex_count: u32, edges: &[bool]) -> Self

Assumes edges is a packed representation of the adjacency matrix representing a strictly upper triangular matrix. Such representation has a useful property: (1) Every bit sequence in such a representation corresponds to some valid DAG and (2) Every DAG corresponds to some valid bit sequence in such a representation. Thanks to (1) and (2) taken together, we can be sure proptest will cover the entire search space of random DAGs.

source

pub fn from_adjacency_matrix( adjacency_matrix: StrictlyUpperTriangularLogicalMatrix ) -> Self

Construct a DAG from an pre-computed adjacency matrix.

source

pub fn get_vertex_count(&self) -> u32

source

pub fn get_edge(&self, u: u32, v: u32) -> bool

Requires u < v. Panics otherwise.

source

pub fn set_edge(&mut self, u: u32, v: u32)

Requires u < v. Panics otherwise.

source

pub fn clear_edge(&mut self, u: u32, v: u32)

Requires u < v. Panics otherwise.

source

pub fn set_edge_to(&mut self, u: u32, v: u32, exists: bool)

Requires u < v. Panics otherwise.

source

pub fn iter_edges(&self) -> impl Iterator<Item = (u32, u32)> + '_

source

pub fn iter_children(&self, u: u32) -> impl Iterator<Item = u32> + '_

Iterates over vertices v such that there’s an edge (u, v) in the DAG.

source

pub fn extend_with_children(&self, children: &mut Vec<u32>, u: u32)

source

pub fn extend_with_parents(&self, parents: &mut Vec<u32>, v: u32)

source

pub fn into_adjacency_matrix(self) -> StrictlyUpperTriangularLogicalMatrix

Consume self and return the underlying adjacency matrix.

source

pub fn iter_descendants_dfs( &self, start_vertex: u32 ) -> Box<dyn Iterator<Item = u32> + '_>

Visit all vertices reachable from vertex in a depth-first-search (DFS) order.

source

pub fn iter_ancestors_dfs( &self, start_vertex: u32 ) -> Box<dyn Iterator<Item = u32> + '_>

source

pub fn iter_vertices_dfs(&self) -> Box<dyn Iterator<Item = u32> + '_>

Visit all vertices of a DAG in a depth-first-search (DFS) order.

source

pub fn iter_vertices_dfs_post_order(&self) -> Box<dyn Iterator<Item = u32> + '_>

Visit all vertices of a DAG in a depth-first-search postorder, i.e. emitting vertices only after all their descendants have been emitted first.

source

pub fn iter_edges_dfs_post_order( &self ) -> Box<dyn Iterator<Item = (u32, u32)> + '_>

Visit nodes in a depth-first-search (DFS) emitting edges in postorder, i.e. each node is visited after all its descendants have been already visited.

Note that when a DAG represents a partially ordered set, this function iterates over pairs of that poset. It may be necessary to first compute either a Self::transitive_reduction of a DAG, to only get the minimal set of pairs spanning the entire poset, or a Self::transitive_closure to get all the pairs of that poset.

source

pub fn iter_descendants_dfs_post_order( &self, vertex: u32 ) -> Box<dyn Iterator<Item = u32> + '_>

Visit all vertices reachable from vertex in a depth-first-search postorder, i.e. emitting vertices only after all their descendants have been emitted first.

source

pub fn get_topologically_ordered_vertices(&self) -> Vec<u32>

Combines Self::iter_vertices_dfs_post_order, Iterator::collect() and slice::reverse() to get a topologically ordered sequence of vertices of a DAG.

source

pub fn get_descendants(&self) -> Vec<RoaringBitmap>

Computes a mapping: vertex -> set of vertices that are descendants of vertex.

source

pub fn transitive_reduction(&self) -> DirectedAcyclicGraph

Returns a new DAG that is a transitive reduction of a DAG.

source

pub fn transitive_closure(&self) -> DirectedAcyclicGraph

Returns a new DAG that is a transitive closure of a DAG.

source

pub fn get_vertices_without_incoming_edges(&self) -> Vec<u32>

Returns a set “seed” vertices of a DAG from which a traversal may start so that the process covers all vertices in the graph.

source

pub fn iter_descendants_bfs(&self, vertex: u32) -> BfsVerticesIterator<'_>

Visit all vertices reachable from vertex in a breadth-first-search (BFS) order.

source

pub fn iter_vertices_bfs(&self) -> BfsVerticesIterator<'_>

Visit all vertices of a DAG in a breadth-first-search (BFS) order.

source

pub fn to_dot<W: Write>(&self, output: &mut W) -> Result<(), Error>

Outputs the DAG in the Graphviz DOT format.

source

pub fn to_dot_file<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>

Trait Implementations§

source§

impl Clone for DirectedAcyclicGraph

source§

fn clone(&self) -> DirectedAcyclicGraph

Returns a copy 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 Debug for DirectedAcyclicGraph

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V