/// Merge the two given tokens, if possible.
///
/// The node `a` will receive all words and connections from `b`, then `b` will be removed.
Merge the two given tokens, if possible.
Merge the two given tokens if possible .
pub fn merge_tokens(&mut self, a: TokenSpecId, b: TokenSpecId) -> Result<(), ()> {
        if !self.can_merge_tokens(a, b) {
            return Err(());
        }
        // Update mapping of words, from `b` to `a`
        for targeted_token in self.word_locations.values_mut() {
            if *targeted_token == b {
                *targeted_token = a;
            }
        }
        // Copy all edges from `b` to `a`: incoming and outgoing
        let mut neighbors = self
            .graph
            .neighbors_directed(b, Direction::Incoming)
            .detach();
        while let Some(neighbor) = neighbors.next_node(&self.graph) {
            self.graph.update_edge(neighbor, a, ());
        }
        let mut neighbors = self
            .graph
            .neighbors_directed(b, Direction::Outgoing)
            .detach();
        while let Some(neighbor) = neighbors.next_node(&self.graph) {
            self.graph.update_edge(a, neighbor, ());
        }
        self.graph.remove_node(b);
        Ok(())
    }
pub fn merge_tokens ( & mut self , a : TokenSpecId , b : TokenSpecId ) -> Result < ( ) , ( ) > { if ! self . can_merge_tokens ( a , b ) { return Err ( ( ) ) ; } // Update mapping of words, from `b` to `a` for targeted_token in self . word_locations . values_mut ( ) { if * targeted_token == b { * targeted_token = a ; } } // Copy all edges from `b` to `a`: incoming and outgoing let mut neighbors = self . graph . neighbors_directed ( b , Direction :: Incoming ) . detach ( ) ; while let Some ( neighbor ) = neighbors . next_node ( & self . graph ) { self . graph . update_edge ( neighbor , a , ( ) ) ; } let mut neighbors = self . graph . neighbors_directed ( b , Direction :: Outgoing ) . detach ( ) ; while let Some ( neighbor ) = neighbors . next_node ( & self . graph ) { self . graph . update_edge ( a , neighbor , ( ) ) ; } self . graph . remove_node ( b ) ; Ok ( ( ) ) }
Merge the two given tokens, if possible.
Merge the two given tokens if possible .
&mut self
a
TokenSpecId
b
TokenSpecId