pub struct Dag<N> { /* private fields */ }
Expand description
An incremental directed acyclic graph, however the word ‘acyclic’ is used, this structure allows the existence of cycles in the hope that they will eventually be resolved and provides APIs to report the cycles to the user of the structure.
Implementations§
Source§impl<N> Dag<N>
impl<N> Dag<N>
Sourcepub fn insert(&mut self, node: N) -> bool
pub fn insert(&mut self, node: N) -> bool
Insert a new node to the graph. Returns false
if the node already existed in the graph.
Sourcepub fn remove<Q>(&mut self, node: &Q) -> Option<N>
pub fn remove<Q>(&mut self, node: &Q) -> Option<N>
Remove a node from the graph. Returns the node which got removed in an Option
, if the node
did not exist in the first place None
is returned.
Sourcepub fn connect<Q>(&mut self, v: &Q, u: &Q) -> Result<bool, Error>
pub fn connect<Q>(&mut self, v: &Q, u: &Q) -> Result<bool, Error>
in the graph, Ok(false)
is returned if the connection already existed in the graph.
If the same node is passed for both the values of v
and u
then Err(Error::SelfLoop)
is returned.
use interactive_dag::{Dag, Error};
let mut g = Dag::<u32>::new();
assert_eq!(g.connect(&0, &0), Err(Error::NotFound));
g.insert(0);
assert_eq!(g.connect(&0, &0), Err(Error::SelfLoop));
g.insert(1);
assert_eq!(g.connect(&0, &1), Ok(true));
assert_eq!(g.connect(&0, &1), Ok(false));
Sourcepub fn disconnect<Q>(&mut self, v: &Q, u: &Q) -> Result<bool, Error>
pub fn disconnect<Q>(&mut self, v: &Q, u: &Q) -> Result<bool, Error>
Removes an edge from the graph.
Sourcepub fn is_connected<Q>(&self, v: &Q, u: &Q) -> bool
pub fn is_connected<Q>(&self, v: &Q, u: &Q) -> bool
Returns true
if there is a direct edge connection v
to u
.
Trait Implementations§
Auto Trait Implementations§
impl<N> Freeze for Dag<N>
impl<N> RefUnwindSafe for Dag<N>where
N: RefUnwindSafe,
impl<N> Send for Dag<N>where
N: Send,
impl<N> Sync for Dag<N>where
N: Sync,
impl<N> Unpin for Dag<N>where
N: Unpin,
impl<N> UnwindSafe for Dag<N>where
N: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more