pub fn remove_node(&mut self, id: NodeID) -> Result<(), &'static str> {
        // get edge data for this node
        let (pointing_to, pointed_to) = if let Some(node) = self.nodes.get_mut(&id) {
            Ok((node.pointing_to().clone(), node.pointed_to().clone()))
        } else {
            Err("Invalid Node ID")
        }?;

        // remove all edges for this node
        for other_id in pointed_to.iter() {
            if let Some(node) = self.nodes.get_mut(&other_id) {
                (*node).pointing_to().retain(|elem| elem != &id)
            }
        }

        for other_id in pointing_to.iter() {
            if let Some(node) = self.nodes.get_mut(&other_id) {
                (*node).pointed_to().retain(|elem| elem != &id)
            }
        }

        // remove the node
        self.nodes.remove(&id);

        Ok(())
    }
/// Remove a node by ID. Fails if the node ID is not found.
Remove a node by ID. Fails if the node ID is not found.
Remove a node by ID . Fails if the node ID is not found .
pub fn remove_node(&mut self, id: NodeID) -> Result<(), &'static str> {
        // get edge data for this node
        let (pointing_to, pointed_to) = if let Some(node) = self.nodes.get_mut(&id) {
            Ok((node.pointing_to().clone(), node.pointed_to().clone()))
        } else {
            Err("Invalid Node ID")
        }?;
        // remove all edges for this node
        for other_id in pointed_to.iter() {
            if let Some(node) = self.nodes.get_mut(&other_id) {
                (*node).pointing_to().retain(|elem| elem != &id)
            }
        }
        for other_id in pointing_to.iter() {
            if let Some(node) = self.nodes.get_mut(&other_id) {
                (*node).pointed_to().retain(|elem| elem != &id)
            }
        }
        // remove the node
        self.nodes.remove(&id);
        Ok(())
    }
pub fn remove_node ( & mut self , id : NodeID ) -> Result < ( ) , & ' static str > { // get edge data for this node let ( pointing_to , pointed_to ) = if let Some ( node ) = self . nodes . get_mut ( & id ) { Ok ( ( node . pointing_to ( ) . clone ( ) , node . pointed_to ( ) . clone ( ) ) ) } else { Err ( " " ) } ? ; // remove all edges for this node for other_id in pointed_to . iter ( ) { if let Some ( node ) = self . nodes . get_mut ( & other_id ) { ( * node ) . pointing_to ( ) . retain ( | elem | elem != & id ) } } for other_id in pointing_to . iter ( ) { if let Some ( node ) = self . nodes . get_mut ( & other_id ) { ( * node ) . pointed_to ( ) . retain ( | elem | elem != & id ) } } // remove the node self . nodes . remove ( & id ) ; Ok ( ( ) ) }
Remove a node by ID.
Remove a node by ID .
&mut self
id
NodeID
&mut self
id
NodeID