/// Merge the given locations together, as much as possible. Each location will be taken in sequence
/// and will be merged with the previous ones. If that's not possible, it will start a new group of
/// its own. The following locations will try to merge with the first group. When not possible, it
/// will try with the second, and so on until no group accepts it. In this case, a new group will
/// created again.
Merge the given locations together, as much as possible. Each location will be taken in sequence
and will be merged with the previous ones. If that's not possible, it will start a new group of
its own. The following locations will try to merge with the first group. When not possible, it
will try with the second, and so on until no group accepts it. In this case, a new group will
created again.
Merge the given locations together as much as possible . Each location will be taken in sequence and will be merged with the previous ones . If that ' s not possible it will start a new group of its own . The following locations will try to merge with the first group . When not possible it will try with the second and so on until no group accepts it . In this case a new group will created again .
fn merge_locations(graph: &mut TokenGraph, locations: &[PhrasedWordId]) {
    let mut group_roots = Vec::new();
    let mut visited_tokens = BTreeSet::new();
    let mut num_merges = 0;
    for &location in locations {
        let token = graph.find_token(location);
        if !visited_tokens.insert(token) {
            continue;
        }
        let mut merged = false;
        for &root in &group_roots {
            if graph.merge_tokens(root, token).is_ok() {
                merged = true;
                num_merges += 1;
                break;
            }
        }
        if !merged {
            group_roots.push(token);
        }
    }
    log::debug!(
        "Merged {} locations, {} unique tokens: {} merges into {} groups",
        locations.len(),
        visited_tokens.len(),
        num_merges,
        group_roots.len(),
    );
}
fn merge_locations ( graph : & mut TokenGraph , locations : & [ PhrasedWordId ] ) { let mut group_roots = Vec :: new ( ) ; let mut visited_tokens = BTreeSet :: new ( ) ; let mut num_merges = 0 ; for & location in locations { let token = graph . find_token ( location ) ; if ! visited_tokens . insert ( token ) { continue ; } let mut merged = false ; for & root in & group_roots { if graph . merge_tokens ( root , token ) . is_ok ( ) { merged = true ; num_merges += 1 ; break ; } } if ! merged { group_roots . push ( token ) ; } } log :: debug ! ( " " locations len ( ) visited_tokens len ( ) num_merges group_roots len ( ) ) ; }
Merge the given locations together, as much as possible.
Merge the given locations together as much as possible .
graph
&mut TokenGraph
locations
&[PhrasedWordId]