[][src]Trait generic_graph::VariableEdges

pub trait VariableEdges<T, E, K, V, W, C>: DirectedGraph<T, E, K, V, W, C> where
    K: Hash + Eq + Clone,
    C: Hash + Eq + Clone,
    W: Add + Sub + Eq + Ord + Copy,
    T: Vertex<K, V>,
    E: Edge<K, W, C>, 
{ fn add_edge(&mut self, edge: E) -> Result<Option<E>, EdgeSide>;
fn remove_edge(&mut self, pair: (&K, &K)) -> Option<E>; }

This trait adds to a Directed graph the methods to add and remove edges

Required methods

fn add_edge(&mut self, edge: E) -> Result<Option<E>, EdgeSide>

If an edge with an equal key is already present, the edge is updated (not the key) and the old edge is returned ad Ok(Some(old_edge)). If not present OK(None) is returned.

If one or both of the concerned vertexes are missing an error will be returned containing an enum specifying which side is missing

fn remove_edge(&mut self, pair: (&K, &K)) -> Option<E>

If the removed edge was present it's removed and returned as Some(edge). Otherwise None is returned

Loading content...

Implementors

impl<K: Hash + Eq + Clone, V, W: Add + Sub + Eq + Ord + Copy> VariableEdges<SimpleVertex<K, V>, DirectedEdge<K, W>, K, V, W, CompoundKey<K>> for AdjacencyGraph<K, V, W>[src]

AdjacencyGraph uses HashMaps to store edges, allowing fast insertion and removal of the latter

fn add_edge(
    &mut self,
    edge: DirectedEdge<K, W>
) -> Result<Option<DirectedEdge<K, W>>, EdgeSide>
[src]

The add_edge() method shall return Ok(None) if the element was not previously set. Otherwise the element shall be updated (but no the key) and the old element shall be returned as Ok(Some(old_element)). If one or both of the concerned vertexes are missing an error containing an enum specifying which side is missing (Err(EdgeSide))

Examples

use generic_graph::adjacency_list::AdjacencyGraph;
use generic_graph::{SimpleVertex, VariableVertexes, VariableEdges};
use generic_graph::adjacency_list::elements::DirectedEdge;
use generic_graph::EdgeSide::Right;
let mut graph = AdjacencyGraph::new();
graph.add_vertex(SimpleVertex::new(1, "a"));
graph.add_vertex(SimpleVertex::new(2, "b"));
graph.add_vertex(SimpleVertex::new(3, "c"));

assert_eq!(Ok(None), graph.add_edge(DirectedEdge::new(1, 2, 0)));
assert_eq!(Ok(None), graph.add_edge(DirectedEdge::new(2, 1, 0)));
assert_eq!(Ok(None), graph.add_edge(DirectedEdge::new(3, 2, 0)));
assert_eq!(
     Ok(Some(DirectedEdge::new(1, 2, 0))),
     graph.add_edge(DirectedEdge::new(1, 2, 3))
);
assert_eq!(Err(Right), graph.add_edge(DirectedEdge::new(1, 4, 0)));

fn remove_edge(&mut self, pair: (&K, &K)) -> Option<DirectedEdge<K, W>>[src]

The remove_edge() method shall return None if the element was not found, or Some(element) if it was found and removed.

Examples

use generic_graph::adjacency_list::AdjacencyGraph;
use generic_graph::{SimpleVertex, VariableVertexes, VariableEdges};
use generic_graph::adjacency_list::elements::DirectedEdge;
use generic_graph::EdgeSide::Right;
let mut graph = AdjacencyGraph::new();
graph.add_vertex(SimpleVertex::new(1, "a"));
graph.add_vertex(SimpleVertex::new(2, "b"));

graph.add_edge(DirectedEdge::new(1, 2, 3));

assert_eq!(
        Some(DirectedEdge::new(1, 2, 3)),
        graph.remove_edge((&1, &2))
);
assert_eq!(None, graph.remove_edge((&1, &2)));
Loading content...