pub fn insert_edge(&mut self, edge: E) -> Result<()> {
        if self.edges.contains_key(&(edge.head(), edge.tail())) {
            return Err("duplicate edge".into());
        }
        if !self.vertices.contains_key(&edge.head()) {
            return Err(ErrorKind::GraphVertexNotFound(edge.head()).into());
        }
        if !self.vertices.contains_key(&edge.tail()) {
            return Err(ErrorKind::GraphVertexNotFound(edge.tail()).into());
        }

        self.edges.insert((edge.head(), edge.tail()), edge.clone());
        self.successors
            .get_mut(&edge.head())
            .unwrap()
            .insert(edge.tail());
        self.predecessors
            .get_mut(&edge.tail())
            .unwrap()
            .insert(edge.head());

        Ok(())
    }
/// Inserts an edge into the graph.
/// # Errors
/// Error if the edge already exists by indices.
Inserts an edge into the graph.
Inserts an edge into the graph .
pub fn insert_edge(&mut self, edge: E) -> Result<()> {
        if self.edges.contains_key(&(edge.head(), edge.tail())) {
            return Err("duplicate edge".into());
        }
        if !self.vertices.contains_key(&edge.head()) {
            return Err(ErrorKind::GraphVertexNotFound(edge.head()).into());
        }
        if !self.vertices.contains_key(&edge.tail()) {
            return Err(ErrorKind::GraphVertexNotFound(edge.tail()).into());
        }
        self.edges.insert((edge.head(), edge.tail()), edge.clone());
        self.successors
            .get_mut(&edge.head())
            .unwrap()
            .insert(edge.tail());
        self.predecessors
            .get_mut(&edge.tail())
            .unwrap()
            .insert(edge.head());
        Ok(())
    }
pub fn insert_edge ( & mut self , edge : E ) -> Result < ( ) > { if self . edges . contains_key ( & ( edge . head ( ) , edge . tail ( ) ) ) { return Err ( " " . into ( ) ) ; } if ! self . vertices . contains_key ( & edge . head ( ) ) { return Err ( ErrorKind :: GraphVertexNotFound ( edge . head ( ) ) . into ( ) ) ; } if ! self . vertices . contains_key ( & edge . tail ( ) ) { return Err ( ErrorKind :: GraphVertexNotFound ( edge . tail ( ) ) . into ( ) ) ; } self . edges . insert ( ( edge . head ( ) , edge . tail ( ) ) , edge . clone ( ) ) ; self . successors . get_mut ( & edge . head ( ) ) . unwrap ( ) . insert ( edge . tail ( ) ) ; self . predecessors . get_mut ( & edge . tail ( ) ) . unwrap ( ) . insert ( edge . head ( ) ) ; Ok ( ( ) ) }
Inserts an edge into the graph.
Inserts an edge into the graph .
&mut self
edge
E
&mut self
edge
E
errors
Error if the edge already exists by indices.
Error if the edge already exists by indices .