Struct dograph::DirectedAcyclicGraph
source · [−]pub struct DirectedAcyclicGraph { /* private fields */ }
Expand description
A mutable, single-threaded directed acyclic graph.
Implementations
sourceimpl DirectedAcyclicGraph
impl DirectedAcyclicGraph
pub fn empty(vertex_count: usize) -> Self
sourcepub fn from_edges_iter<I: Iterator<Item = (usize, usize)>>(
vertex_count: usize,
edges: I
) -> Self
pub fn from_edges_iter<I: Iterator<Item = (usize, usize)>>(
vertex_count: usize,
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 random<R: Rng, D: Distribution<bool> + Copy>(
vertex_count: usize,
rng: &mut R,
edges_distribution: D
) -> Self
pub fn random<R: Rng, D: Distribution<bool> + Copy>(
vertex_count: usize,
rng: &mut R,
edges_distribution: D
) -> Self
Generate a random DAG sampling edges from edges_distribution
.
For example, to generate a random DAG with a probability 1/2
of having
an edge between any two of 321
vertices, do:
use crate::DirectedAcyclicGraph;
use rand::rngs::StdRng;
use rand::SeedableRng;
use rand::distributions::Bernoulli;
let mut rng = StdRng::seed_from_u64(123);
let dag = DirectedAcyclicGraph::random(321, &mut rng, Bernoulli::new(0.5).unwrap());
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) -> usize
sourcepub fn iter_edges(&self) -> impl Iterator<Item = (usize, usize)> + '_
pub fn iter_edges(&self) -> impl Iterator<Item = (usize, usize)> + '_
Iterates over the edges in an order that favors CPU cache locality.
sourcepub fn iter_children(&self, u: usize) -> impl Iterator<Item = usize> + '_
pub fn iter_children(&self, u: usize) -> impl Iterator<Item = usize> + '_
Iterates over vertices v
such that there’s an edge (u, v)
in the
DAG.
sourcepub fn into_adjacency_matrix(self) -> StrictlyUpperTriangularLogicalMatrix
pub fn into_adjacency_matrix(self) -> StrictlyUpperTriangularLogicalMatrix
Consume self and return the underlying adjacency matrix.
Trait Implementations
sourceimpl Arbitrary for DirectedAcyclicGraph
impl Arbitrary for DirectedAcyclicGraph
sourceimpl Clone for DirectedAcyclicGraph
impl Clone for DirectedAcyclicGraph
sourcefn clone(&self) -> DirectedAcyclicGraph
fn clone(&self) -> DirectedAcyclicGraph
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl RefUnwindSafe for DirectedAcyclicGraph
impl Send for DirectedAcyclicGraph
impl Sync for DirectedAcyclicGraph
impl Unpin for DirectedAcyclicGraph
impl UnwindSafe for DirectedAcyclicGraph
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more