Struct roaring_graphs::dag::DirectedAcyclicGraph
source · pub struct DirectedAcyclicGraph { /* private fields */ }Expand description
A mutable, single-threaded directed acyclic graph.
Implementations§
source§impl DirectedAcyclicGraph
impl DirectedAcyclicGraph
pub fn empty(vertex_count: Vertex) -> Self
sourcepub fn from_edges_iter<I: Iterator<Item = (Vertex, Vertex)>>(
vertex_count: Vertex,
edges: I
) -> Self
pub fn from_edges_iter<I: Iterator<Item = (Vertex, Vertex)>>( vertex_count: Vertex, 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.
sourcepub fn from_raw_edges(vertex_count: Vertex, edges: &[bool]) -> Self
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.
sourcepub fn from_adjacency_matrix(
adjacency_matrix: StrictlyUpperTriangularLogicalMatrix
) -> Self
pub fn from_adjacency_matrix( adjacency_matrix: StrictlyUpperTriangularLogicalMatrix ) -> Self
Construct a DAG from an pre-computed adjacency matrix.
pub fn get_vertex_count(&self) -> Vertex
sourcepub fn clear_edge(&mut self, u: Vertex, v: Vertex)
pub fn clear_edge(&mut self, u: Vertex, v: Vertex)
Requires u < v. Panics otherwise.
sourcepub fn set_edge_to(&mut self, u: Vertex, v: Vertex, exists: bool)
pub fn set_edge_to(&mut self, u: Vertex, v: Vertex, exists: bool)
Requires u < v. Panics otherwise.
pub fn iter_edges(&self) -> impl Iterator<Item = (Vertex, Vertex)> + '_
sourcepub fn iter_children(&self, u: Vertex) -> impl Iterator<Item = Vertex> + '_
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.
pub fn extend_with_children(&self, children: &mut Vec<Vertex>, u: Vertex)
pub fn extend_with_parents(&self, parents: &mut Vec<Vertex>, v: Vertex)
sourcepub fn into_adjacency_matrix(self) -> StrictlyUpperTriangularLogicalMatrix
pub fn into_adjacency_matrix(self) -> StrictlyUpperTriangularLogicalMatrix
Consume self and return the underlying adjacency matrix.
sourcepub fn iter_descendants_dfs(
&self,
start_vertex: Vertex
) -> Box<dyn Iterator<Item = Vertex> + '_>
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.
pub fn iter_ancestors_dfs( &self, start_vertex: Vertex ) -> Box<dyn Iterator<Item = Vertex> + '_>
sourcepub fn iter_vertices_dfs(&self) -> Box<dyn Iterator<Item = Vertex> + '_>
pub fn iter_vertices_dfs(&self) -> Box<dyn Iterator<Item = Vertex> + '_>
Visit all vertices of a DAG in a depth-first-search (DFS) order.
sourcepub fn iter_vertices_dfs_post_order(
&self
) -> Box<dyn Iterator<Item = Vertex> + '_>
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 have been emitted first.
sourcepub fn iter_edges_dfs_post_order(
&self
) -> Box<dyn Iterator<Item = (Vertex, Vertex)> + '_>
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 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.
sourcepub fn iter_descendants_dfs_post_order(
&self,
vertex: Vertex
) -> Box<dyn Iterator<Item = Vertex> + '_>
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.
sourcepub fn get_topologically_ordered_vertices(&self) -> Vec<Vertex>
pub fn get_topologically_ordered_vertices(&self) -> Vec<Vertex>
Combines Self::iter_vertices_dfs_post_order, Iterator::collect() and
slice::reverse() to get a topologically ordered sequence of vertices of a
DAG.
sourcepub fn get_descendants(&self) -> Vec<RoaringBitmap>
pub fn get_descendants(&self) -> Vec<RoaringBitmap>
Computes a mapping: vertex -> set of vertices that are descendants of vertex.
sourcepub fn transitive_reduction(&self) -> DirectedAcyclicGraph
pub fn transitive_reduction(&self) -> DirectedAcyclicGraph
Returns a new DAG that is a transitive reduction of a DAG.
sourcepub fn transitive_closure(&self) -> DirectedAcyclicGraph
pub fn transitive_closure(&self) -> DirectedAcyclicGraph
Returns a new DAG that is a transitive closure of a DAG.
sourcepub fn get_vertices_without_incoming_edges(&self) -> Vec<Vertex>
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.
sourcepub fn iter_descendants_bfs(&self, vertex: Vertex) -> BfsVerticesIterator<'_> ⓘ
pub fn iter_descendants_bfs(&self, vertex: Vertex) -> BfsVerticesIterator<'_> ⓘ
Visit all vertices reachable from vertex in a breadth-first-search (BFS)
order.
sourcepub fn iter_vertices_bfs(&self) -> BfsVerticesIterator<'_> ⓘ
pub fn iter_vertices_bfs(&self) -> BfsVerticesIterator<'_> ⓘ
Visit all vertices of a DAG in a breadth-first-search (BFS) order.
sourcepub fn to_dot<W: Write>(&self, output: &mut W) -> Result<(), Error>
pub fn to_dot<W: Write>(&self, output: &mut W) -> Result<(), Error>
Outputs the DAG in the Graphviz DOT format.
pub fn to_dot_file<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
Trait Implementations§
source§impl Clone for DirectedAcyclicGraph
impl Clone for DirectedAcyclicGraph
source§fn clone(&self) -> DirectedAcyclicGraph
fn clone(&self) -> DirectedAcyclicGraph
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more