[−][src]Struct gamma::graph::HashGraph
Implements an undirected, labeled, graph. Node, neighbor, and edge iteration order are stable and set by build order.
use gamma::graph::Graph; use gamma::graph::HashGraph; let mut graph = HashGraph::build(vec![ 0, 1, 2 ], vec![ (&0, &1, "a"), (&1, &2, "b") ] ).unwrap(); 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).unwrap().collect::<Vec<_>>(), vec![ &0, &2 ]); assert_eq!(graph.degree(&1).unwrap(), 2); assert_eq!(graph.edges().collect::<Vec<_>>(), vec![ (&0, &1), (&1, &2) ]); assert_eq!(graph.has_edge(&0, &1).unwrap(), true); assert_eq!(graph.has_edge(&1, &0).unwrap(), true); assert_eq!(graph.has_edge(&0, &2).unwrap(), false);
Methods
impl<'a, N: Eq + Hash, E> HashGraph<'a, N, E>
[src]
pub fn new() -> Self
[src]
pub fn build(
nodes: Vec<N>,
edges: Vec<(&'a N, &'a N, E)>
) -> Result<Self, Error>
[src]
nodes: Vec<N>,
edges: Vec<(&'a N, &'a N, E)>
) -> Result<Self, Error>
pub fn add_node(&mut self, node: N) -> Result<(), Error>
[src]
pub fn add_edge(&mut self, source: &'a N, target: &'a N) -> Result<(), Error>
[src]
Trait Implementations
impl<'a, N: Eq + Hash, E> Graph<'a, N> for HashGraph<'a, N, E>
[src]
type NodeIterator = Keys<'a, N, Vec<&'a N>>
type NeighborIterator = Cloned<Iter<'a, &'a N>>
type EdgeIterator = Cloned<Iter<'a, (&'a N, &'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 edges(&'a self) -> Self::EdgeIterator
[src]
fn has_edge(&self, source: &N, target: &N) -> Result<bool, Error>
[src]
impl<'a, N: Eq + Hash, E> WeightedGraph<'a, N, E> for HashGraph<'a, N, E>
[src]
Auto Trait Implementations
impl<'a, N, E> RefUnwindSafe for HashGraph<'a, N, E> where
E: RefUnwindSafe,
N: RefUnwindSafe,
E: RefUnwindSafe,
N: RefUnwindSafe,
impl<'a, N, E> Send for HashGraph<'a, N, E> where
E: Send,
N: Send + Sync,
E: Send,
N: Send + Sync,
impl<'a, N, E> Sync for HashGraph<'a, N, E> where
E: Sync,
N: Sync,
E: Sync,
N: Sync,
impl<'a, N, E> Unpin for HashGraph<'a, N, E> where
E: Unpin,
N: Unpin,
E: Unpin,
N: Unpin,
impl<'a, N, E> UnwindSafe for HashGraph<'a, N, E> where
E: UnwindSafe,
N: RefUnwindSafe + UnwindSafe,
E: UnwindSafe,
N: RefUnwindSafe + 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>,