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

pub struct HashGraph<'a, N, E> { /* fields omitted */ }

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]

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)>>

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

impl<'a, N, E> Send for HashGraph<'a, N, E> where
    E: Send,
    N: Send + Sync

impl<'a, N, E> Sync for HashGraph<'a, N, E> where
    E: Sync,
    N: Sync

impl<'a, N, E> Unpin for HashGraph<'a, N, E> where
    E: Unpin,
    N: Unpin

impl<'a, N, E> UnwindSafe for HashGraph<'a, N, E> where
    E: UnwindSafe,
    N: RefUnwindSafe + 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.