DirectedAcyclicGraph

Struct DirectedAcyclicGraph 

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

A mutable, single-threaded directed acyclic graph.

Implementations§

Source§

impl DirectedAcyclicGraph

Source

pub fn new(vertex_count: Vertex) -> Self

Constructs a new graph without any edges having at most vertex_count vertices.

Source

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

Constructs a DAG from a 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: Vertex, 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 a pre-computed adjacency matrix.

Source

pub fn fully_connected(vertex_count: Vertex) -> Self

Construct a fully connected DAG with given amount of vertices.

Source

pub fn get_vertex_count(&self) -> Vertex

Source

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

Requires u < v. Panics otherwise.

Source

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

Requires u < v. Panics otherwise.

Source

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

Requires u < v. Panics otherwise.

Source

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

Each emitted pair (u, v) is guaranteed to satisfy u < v.

Source

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

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

Source

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

Source

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

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: Vertex, ) -> Box<dyn Iterator<Item = Vertex> + '_>

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

Source

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

Source

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

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 = Vertex> + '_>

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

Source

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

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

Source

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

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

Combines Self::iter_vertices_dfs_post_order with 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<Vertex>

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: Vertex) -> 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 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 Debug for DirectedAcyclicGraph

Source§

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

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

impl PartialEq for DirectedAcyclicGraph

Source§

fn eq(&self, other: &DirectedAcyclicGraph) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for DirectedAcyclicGraph

Source§

impl StructuralPartialEq for DirectedAcyclicGraph

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V