[−][src]Struct gamma::graph::StableGraph
Reference implementation of Graph and WeightedGraph.Implements an undirected, edge-weighted, graph. Node, neighbor, and edge iteration order are set by the build function and will remain stable.
use gamma::graph::{ Graph, StableGraph, Error }; fn main() -> Result<(), Error> { let mut graph = StableGraph::build(vec![ 0, 1, 2 ], vec![ (0, 1, "a"), (1, 2, "b") ])?; assert_eq!(graph.is_empty(), false); assert_eq!(graph.order(), 3); assert_eq!(graph.size(), 2); assert_eq!(graph.nodes().collect::<Vec<_>>(), vec![ &0, &1, &2 ]); assert_eq!(graph.has_node(&0), true); assert_eq!(graph.neighbors(&1)?.collect::<Vec<_>>(), vec![ &0, &2 ]); assert_eq!(graph.degree(&1)?, 2); assert_eq!(graph.edges().collect::<Vec<_>>(), vec![ (&0, &1), (&1, &2) ]); assert_eq!(graph.has_edge(&0, &1)?, true); assert_eq!(graph.has_edge(&1, &0)?, true); assert_eq!(graph.has_edge(&0, &2)?, false); Ok(()) }
Although nodes and edges must implement Clone, the can be done in a lightweight manner using reference counting (std::rc::Rc). Likewise, references implement Clone (efficiently), so they can be used as nodes if the resulting StableGraph is not moved.
Implementations
impl<N: Eq + Hash + Clone, E: Clone> StableGraph<N, E>
[src]
Trait Implementations
impl<'a, N: 'a + Hash + Eq, E: 'a> Graph<'a, N> for StableGraph<N, E>
[src]
type NodeIterator = Iter<'a, N>
type NeighborIterator = NeighborIterator<'a, N, E>
type EdgeIterator = EdgeIterator<'a, N>
fn is_empty(&self) -> bool
[src]
fn order(&self) -> usize
[src]
fn size(&self) -> usize
[src]
fn nodes(&'a self) -> Self::NodeIterator
[src]
fn has_node(&self, node: &N) -> bool
[src]
fn neighbors(&'a self, node: &N) -> Result<Self::NeighborIterator, Error>
[src]
fn degree(&self, node: &N) -> Result<usize, Error>
[src]
fn has_edge(&self, source: &N, target: &N) -> Result<bool, Error>
[src]
fn edges(&'a self) -> Self::EdgeIterator
[src]
impl<'a, N: 'a + Eq + Hash, E: 'a> WeightedGraph<'a, N, E> for StableGraph<N, E>
[src]
Auto Trait Implementations
impl<N, E> RefUnwindSafe for StableGraph<N, E> where
E: RefUnwindSafe,
N: RefUnwindSafe,
E: RefUnwindSafe,
N: RefUnwindSafe,
impl<N, E> Send for StableGraph<N, E> where
E: Send,
N: Send,
E: Send,
N: Send,
impl<N, E> Sync for StableGraph<N, E> where
E: Sync,
N: Sync,
E: Sync,
N: Sync,
impl<N, E> Unpin for StableGraph<N, E> where
E: Unpin,
N: Unpin,
E: Unpin,
N: Unpin,
impl<N, E> UnwindSafe for StableGraph<N, E> where
E: UnwindSafe,
N: UnwindSafe,
E: UnwindSafe,
N: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,