pub fn group_similar<'a, 'b, V>(
    records: &'a [V],
    config: &'b Config<V>,
) -> BTreeMap<&'a V, Vec<&'a V>>
where
    V: std::hash::Hash + Eq + Sync + Ord,
{
    let mut results = BTreeMap::new();

    let mut condensed = similarity_matrix(records, &config.compare);
    let dend = linkage(&mut condensed, records.len(), config.method);
    let mut dendro: Dendro<f64, &V> = BTreeMap::default();

    for (idx, record) in records.iter().enumerate() {
        dendro.insert(idx, Dendrogram::Node(record));
    }

    let base = records.len();
    for (idx, step) in dend.steps().iter().enumerate() {
        dendro.insert(base + idx, Dendrogram::Group(step));
    }

    // We reverse this to start with the most dissimilar first, ultimately operating within the
    // threshold. The result is that the largest groups bubble up to the top, ensuring that we're
    // casting the widest net from closer matches when building the result set.
    for (idx, step) in dend.steps().iter().enumerate().rev() {
        if config.threshold.within(step.dissimilarity) {
            match extract_values(&mut dendro, base + idx).as_slice() {
                [first, rest @ ..] => {
                    results.entry(*first).or_insert(vec![]).extend(rest);
                }
                [] => {}
            }
        }
    }

    for node in get_remaining_nodes(&dendro) {
        results.insert(node, vec![]);
    }

    results
}
/// Group records based on a particular configuration
Group records based on a particular configuration
Group records based on a particular configuration
pub fn group_similar<'a, 'b, V>(
    records: &'a [V],
    config: &'b Config<V>,
) -> BTreeMap<&'a V, Vec<&'a V>>
where
    V: std::hash::Hash + Eq + Sync + Ord,
{
    let mut results = BTreeMap::new();
    let mut condensed = similarity_matrix(records, &config.compare);
    let dend = linkage(&mut condensed, records.len(), config.method);
    let mut dendro: Dendro<f64, &V> = BTreeMap::default();
    for (idx, record) in records.iter().enumerate() {
        dendro.insert(idx, Dendrogram::Node(record));
    }
    let base = records.len();
    for (idx, step) in dend.steps().iter().enumerate() {
        dendro.insert(base + idx, Dendrogram::Group(step));
    }
    // We reverse this to start with the most dissimilar first, ultimately operating within the
    // threshold. The result is that the largest groups bubble up to the top, ensuring that we're
    // casting the widest net from closer matches when building the result set.
    for (idx, step) in dend.steps().iter().enumerate().rev() {
        if config.threshold.within(step.dissimilarity) {
            match extract_values(&mut dendro, base + idx).as_slice() {
                [first, rest @ ..] => {
                    results.entry(*first).or_insert(vec![]).extend(rest);
                }
                [] => {}
            }
        }
    }
    for node in get_remaining_nodes(&dendro) {
        results.insert(node, vec![]);
    }
    results
}
pub fn group_similar < ' a , ' b , V > ( records : & ' a [ V ] , config : & ' b Config < V > , ) -> BTreeMap < & ' a V , Vec < & ' a V > > where V : std :: hash :: Hash + Eq + Sync + Ord , { let mut results = BTreeMap :: new ( ) ; let mut condensed = similarity_matrix ( records , & config . compare ) ; let dend = linkage ( & mut condensed , records . len ( ) , config . method ) ; let mut dendro : Dendro < f64 , & V > = BTreeMap :: default ( ) ; for ( idx , record ) in records . iter ( ) . enumerate ( ) { dendro . insert ( idx , Dendrogram :: Node ( record ) ) ; } let base = records . len ( ) ; for ( idx , step ) in dend . steps ( ) . iter ( ) . enumerate ( ) { dendro . insert ( base + idx , Dendrogram :: Group ( step ) ) ; } // We reverse this to start with the most dissimilar first, ultimately operating within the // threshold. The result is that the largest groups bubble up to the top, ensuring that we're // casting the widest net from closer matches when building the result set. for ( idx , step ) in dend . steps ( ) . iter ( ) . enumerate ( ) . rev ( ) { if config . threshold . within ( step . dissimilarity ) { match extract_values ( & mut dendro , base + idx ) . as_slice ( ) { [ first , rest @ .. ] => { results . entry ( * first ) . or_insert ( vec ! [ ] ) . extend ( rest ) ; } [ ] => { } } } } for node in get_remaining_nodes ( & dendro ) { results . insert ( node , vec ! [ ] ) ; } results }
Group records based on a particular configuration
Group records based on a particular configuration
records
&'a [V]
config
&'b Config<V>
records
&'a [V]
config
&'b Config<V>