[−][src]Struct gamma::graph::HashGraph
An undirected, node-labeled Graph. Node, and edge order are undefined. Neighbor order remains stable. As such, HashGraph can be tought of as the hashed node counterpart to IndexGraph.
Note that not only is the order of edges obtained from #edges undefined, but the order in which nodes appear within each tuple is also undefined.
use std::collections::HashMap; use gamma::graph::{ Graph, HashGraph, Error }; fn main() -> Result<(), Error> { let mut adjacency = HashMap::new(); adjacency.insert('A', vec![ 'B' ]); adjacency.insert('B', vec![ 'A', 'C' ]); adjacency.insert('C', vec![ 'B' ]); let mut graph = HashGraph::build(adjacency)?; assert_eq!(graph.degree(&'B'), Ok(2)); Ok(()) }
Implementations
impl<'a, N: 'a + Hash + Eq + Clone> HashGraph<N>
[src]
pub fn build(adjacency: HashMap<N, Vec<N>>) -> Result<Self, Error>
[src]
The elements of adjacency will be validated to ensure:
- If there is a forward edge, there is a matching back edge.
- There are no duplicate edges.
- All targets are present as keys.
- No loops (self-edges) are present.
If any test fails, an error is returned.
Trait Implementations
impl<'a, N: 'a + Hash + Eq + Clone> Graph<'a, N> for HashGraph<N>
[src]
type NodeIterator = Keys<'a, N, Vec<N>>
type NeighborIterator = Iter<'a, N>
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 edges(&'a self) -> Self::EdgeIterator
[src]
fn has_edge(&self, source: &N, target: &N) -> Result<bool, Error>
[src]
Auto Trait Implementations
impl<N> RefUnwindSafe for HashGraph<N> where
N: RefUnwindSafe,
N: RefUnwindSafe,
impl<N> Send for HashGraph<N> where
N: Send,
N: Send,
impl<N> Sync for HashGraph<N> where
N: Sync,
N: Sync,
impl<N> Unpin for HashGraph<N> where
N: Unpin,
N: Unpin,
impl<N> UnwindSafe for HashGraph<N> where
N: 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>,