AddEdge

Trait AddEdge 

Source
pub trait AddEdge<V, E> {
    type Error;

    // Required method
    fn add_edge(
        &mut self,
        x: V,
        y: V,
        e: E,
    ) -> Result<Option<(V, V)>, Self::Error>;
}
Expand description

AddEdge add an edge from the vertex x to the vertex y, if it is not there.

§Example

use btree_graph::{BTreeGraph, AddVertex, AddEdge, Edges};
let mut graph: BTreeGraph<String, usize> = BTreeGraph::new();
graph.add_vertex(String::from("origin"));
graph.add_vertex(String::from("destination"));
let old_edge_value: Option<(String, String)> = graph.add_edge(String::from("origin"), String::from("destination"), 10).unwrap();

assert!(old_edge_value.is_none());
assert_eq!(graph.edges().len(), 1)

Required Associated Types§

Required Methods§

Source

fn add_edge(&mut self, x: V, y: V, e: E) -> Result<Option<(V, V)>, Self::Error>

Implementors§

Source§

impl<V, E> AddEdge<V, E> for BTreeGraph<V, E>
where V: Ord + Clone, E: Ord + Clone,

When you add an edge, you should make sure that the x, and y vertices exist.