[][src]Struct gamma::graph::HashGraph

pub struct HashGraph<N> { /* fields omitted */ }

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:

  1. If there is a forward edge, there is a matching back edge.
  2. There are no duplicate edges.
  3. All targets are present as keys.
  4. 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>

Auto Trait Implementations

impl<N> RefUnwindSafe for HashGraph<N> where
    N: RefUnwindSafe

impl<N> Send for HashGraph<N> where
    N: Send

impl<N> Sync for HashGraph<N> where
    N: Sync

impl<N> Unpin for HashGraph<N> where
    N: Unpin

impl<N> UnwindSafe for HashGraph<N> where
    N: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.