[][src]Struct gamma::graph::StableGraph

pub struct StableGraph<N, E> { /* fields omitted */ }

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]

pub fn build(
    node_list: Vec<N>,
    edge_list: Vec<(N, N, E)>
) -> Result<Self, Error>
[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>

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

impl<N, E> Send for StableGraph<N, E> where
    E: Send,
    N: Send

impl<N, E> Sync for StableGraph<N, E> where
    E: Sync,
    N: Sync

impl<N, E> Unpin for StableGraph<N, E> where
    E: Unpin,
    N: Unpin

impl<N, E> UnwindSafe for StableGraph<N, E> where
    E: UnwindSafe,
    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.