pub fn group_potential_duplicates<C>(chunks: Vec<C>) -> Result<Vec<Vec<C>>>
where
    C: Prunable,
{
    let mut groups: Vec<Vec<KeyStats<'_, _>>> = vec![];

    // Step 1: find the up groups using references to `chunks` stored
    // in KeyStats views
    for (idx, chunk) in chunks.iter().enumerate() {
        // try to find a place to put this chunk
        let mut key_stats = Some(KeyStats::new(idx, chunk));

        'outer: for group in &mut groups {
            // If this chunk overlaps any existing chunk in group add
            // it to group
            for ks in group.iter() {
                if ks.potential_overlap(key_stats.as_ref().unwrap())? {
                    group.push(key_stats.take().unwrap());
                    break 'outer;
                }
            }
        }

        if let Some(key_stats) = key_stats {
            // couldn't place key_stats in any existing group, needs a
            // new group
            groups.push(vec![key_stats])
        }
    }

    // Now some shenanigans to rearrange the actual input chunks into
    // the final resulting groups corresponding to the groups of
    // KeyStats

    // drop all references to chunks, and only keep indicides
    let groups: Vec<Vec<usize>> = groups
        .into_iter()
        .map(|group| group.into_iter().map(|key_stats| key_stats.index).collect())
        .collect();

    let mut chunks: Vec<Option<C>> = chunks.into_iter().map(Some).collect();

    let groups = groups
        .into_iter()
        .map(|group| {
            group
                .into_iter()
                .map(|index| {
                    chunks[index]
                        .take()
                        .expect("Internal mismatch while gathering into groups")
                })
                .collect::<Vec<C>>()
        })
        .collect::<Vec<Vec<C>>>();

    Ok(groups)
}
/// Groups [`Prunable`] objects into disjoint sets using values of
/// min/max statistics. The groups are formed such that each group
/// *may* contain InfluxDB data model primary key duplicates with
/// others in that set.
///
/// The *may* overlap calculation is conservative -- that is it may
/// flag two chunks as having overlapping data when in reality they do
/// not. If chunks are split into different groups, then they are
/// guaranteed not to contain any rows with the same primary key.
///
/// Note 1: since this algorithm is based on statistics, it may have
/// false positives (flag that two objects may have overlap when in
/// reality they do not)
///
/// Note 2: this algorithm is O(n^2) worst case (when no chunks have
/// any overlap)
Groups [`Prunable`] objects into disjoint sets using values of
min/max statistics. The groups are formed such that each group
may* contain InfluxDB data model primary key duplicates with
others in that set.

The *may* overlap calculation is conservative -- that is it may
flag two chunks as having overlapping data when in reality they do
not. If chunks are split into different groups, then they are
guaranteed not to contain any rows with the same primary key.

Note 1: since this algorithm is based on statistics, it may have
false positives (flag that two objects may have overlap when in
reality they do not)

Note 2: this algorithm is O(n^2) worst case (when no chunks have
any overlap)
Groups [ ` Prunable ` ] objects into disjoint sets using values of min / max statistics . The groups are formed such that each group may * contain InfluxDB data model primary key duplicates with others in that set . The * may * overlap calculation is conservative -- that is it may flag two chunks as having overlapping data when in reality they do not . If chunks are split into different groups then they are guaranteed not to contain any rows with the same primary key . Note 1 : since this algorithm is based on statistics it may have false positives ( flag that two objects may have overlap when in reality they do not ) Note 2 : this algorithm is O ( n^2 ) worst case ( when no chunks have any overlap )
pub fn group_potential_duplicates<C>(chunks: Vec<C>) -> Result<Vec<Vec<C>>>
where
    C: Prunable,
{
    let mut groups: Vec<Vec<KeyStats<'_, _>>> = vec![];
    // Step 1: find the up groups using references to `chunks` stored
    // in KeyStats views
    for (idx, chunk) in chunks.iter().enumerate() {
        // try to find a place to put this chunk
        let mut key_stats = Some(KeyStats::new(idx, chunk));
        'outer: for group in &mut groups {
            // If this chunk overlaps any existing chunk in group add
            // it to group
            for ks in group.iter() {
                if ks.potential_overlap(key_stats.as_ref().unwrap())? {
                    group.push(key_stats.take().unwrap());
                    break 'outer;
                }
            }
        }
        if let Some(key_stats) = key_stats {
            // couldn't place key_stats in any existing group, needs a
            // new group
            groups.push(vec![key_stats])
        }
    }
    // Now some shenanigans to rearrange the actual input chunks into
    // the final resulting groups corresponding to the groups of
    // KeyStats
    // drop all references to chunks, and only keep indicides
    let groups: Vec<Vec<usize>> = groups
        .into_iter()
        .map(|group| group.into_iter().map(|key_stats| key_stats.index).collect())
        .collect();
    let mut chunks: Vec<Option<C>> = chunks.into_iter().map(Some).collect();
    let groups = groups
        .into_iter()
        .map(|group| {
            group
                .into_iter()
                .map(|index| {
                    chunks[index]
                        .take()
                        .expect("Internal mismatch while gathering into groups")
                })
                .collect::<Vec<C>>()
        })
        .collect::<Vec<Vec<C>>>();
    Ok(groups)
}
pub fn group_potential_duplicates < C > ( chunks : Vec < C > ) -> Result < Vec < Vec < C > > > where C : Prunable , { let mut groups : Vec < Vec < KeyStats < ' _ , _ > > > = vec ! [ ] ; // Step 1: find the up groups using references to `chunks` stored // in KeyStats views for ( idx , chunk ) in chunks . iter ( ) . enumerate ( ) { // try to find a place to put this chunk let mut key_stats = Some ( KeyStats :: new ( idx , chunk ) ) ; ' outer : for group in & mut groups { // If this chunk overlaps any existing chunk in group add // it to group for ks in group . iter ( ) { if ks . potential_overlap ( key_stats . as_ref ( ) . unwrap ( ) ) ? { group . push ( key_stats . take ( ) . unwrap ( ) ) ; break ' outer ; } } } if let Some ( key_stats ) = key_stats { // couldn't place key_stats in any existing group, needs a // new group groups . push ( vec ! [ key_stats ] ) } } // Now some shenanigans to rearrange the actual input chunks into // the final resulting groups corresponding to the groups of // KeyStats // drop all references to chunks, and only keep indicides let groups : Vec < Vec < usize > > = groups . into_iter ( ) . map ( | group | group . into_iter ( ) . map ( | key_stats | key_stats . index ) . collect ( ) ) . collect ( ) ; let mut chunks : Vec < Option < C > > = chunks . into_iter ( ) . map ( Some ) . collect ( ) ; let groups = groups . into_iter ( ) . map ( | group | { group . into_iter ( ) . map ( | index | { chunks [ index ] . take ( ) . expect ( " " ) } ) . collect :: < Vec < C > > ( ) } ) . collect :: < Vec < Vec < C > > > ( ) ; Ok ( groups ) }
Groups [`Prunable`] objects into disjoint sets using values of
min/max statistics.
Groups [ ` Prunable ` ] objects into disjoint sets using values of min / max statistics .
chunks
Vec<C>
chunks
Vec<C>