RemoveEdge

Trait RemoveEdge 

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

    // Required method
    fn remove_edge(&mut self, x: E) -> Result<(), Self::Error>;
}
Expand description

RemoveEdge removes the edge from the vertex x to the vertex y, if it is there. If the edge does not exist, an error will be raised.

§Example

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

assert_eq!(graph.edges().len(), 1);

graph.remove_edge(10);

assert_eq!(graph.edges().len(), 0);

// Note: deletion of edges cascade i.e. the edge is also deleted from any incident
// vertices' adjacency lists.
assert_eq!(graph.get_vertex_value(String::from("origin")).unwrap().len(), 0);

Required Associated Types§

Required Methods§

Source

fn remove_edge(&mut self, x: E) -> Result<(), Self::Error>

Implementors§

Source§

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

When an edge is removed, you should find the incident vertex and ensure the edge is removed from the vertex’s adjacency list.