fn try_merge_blobs(&mut self, low: usize, max: usize) -> Result<()> {
        let mut need_merge_blobs = Vec::new();
        for idx in 0..self.states.len() {
            let blob_info = self.ori_blob_mgr.get_blob(idx).unwrap();
            match self.states[idx].as_ref().unwrap() {
                State::Original(cs) => {
                    let blob_size = if blob_info.compressed_blob_size == 0 {
                        cs.total_size
                    } else {
                        blob_info.compressed_blob_size as usize
                    };
                    if blob_size < low {
                        info!("blob {} size {}, try merge", blob_info.blob_id, blob_size);
                        need_merge_blobs.push((idx, blob_size));
                    }
                }
                State::Rebuild(cs) => {
                    if cs.total_size < low {
                        info!(
                            "blob {} size {}, try merge",
                            blob_info.blob_id, cs.total_size
                        );
                        need_merge_blobs.push((idx, cs.total_size));
                    }
                }
                _ => {}
            }
        }
        // sort by size
        need_merge_blobs.sort_by(|(_, len1), (_, len2)| len1.cmp(len2));
        // try merge
        if need_merge_blobs.len() < 2 {
            return Ok(());
        }
        let mut merge_to = need_merge_blobs[0].0;
        for (blob_idx, _) in need_merge_blobs.iter().skip(1) {
            let before_size = self.states[merge_to].as_ref().unwrap().chunk_total_size()?;
            let append_size = self.states[*blob_idx]
                .as_ref()
                .unwrap()
                .chunk_total_size()?;
            if before_size + append_size <= max {
                self.prepare_to_rebuild(merge_to)?;
                self.merge_blob(*blob_idx, merge_to)?;
            } else {
                merge_to = *blob_idx;
            }
        }
        Ok(())
    }
/// use greedy algorithm to merge small blobs(<low)
use greedy algorithm to merge small blobs(<low)
use greedy algorithm to merge small blobs ( <low )
fn try_merge_blobs(&mut self, low: usize, max: usize) -> Result<()> {
        let mut need_merge_blobs = Vec::new();
        for idx in 0..self.states.len() {
            let blob_info = self.ori_blob_mgr.get_blob(idx).unwrap();
            match self.states[idx].as_ref().unwrap() {
                State::Original(cs) => {
                    let blob_size = if blob_info.compressed_blob_size == 0 {
                        cs.total_size
                    } else {
                        blob_info.compressed_blob_size as usize
                    };
                    if blob_size < low {
                        info!("blob {} size {}, try merge", blob_info.blob_id, blob_size);
                        need_merge_blobs.push((idx, blob_size));
                    }
                }
                State::Rebuild(cs) => {
                    if cs.total_size < low {
                        info!(
                            "blob {} size {}, try merge",
                            blob_info.blob_id, cs.total_size
                        );
                        need_merge_blobs.push((idx, cs.total_size));
                    }
                }
                _ => {}
            }
        }
        // sort by size
        need_merge_blobs.sort_by(|(_, len1), (_, len2)| len1.cmp(len2));
        // try merge
        if need_merge_blobs.len() < 2 {
            return Ok(());
        }
        let mut merge_to = need_merge_blobs[0].0;
        for (blob_idx, _) in need_merge_blobs.iter().skip(1) {
            let before_size = self.states[merge_to].as_ref().unwrap().chunk_total_size()?;
            let append_size = self.states[*blob_idx]
                .as_ref()
                .unwrap()
                .chunk_total_size()?;
            if before_size + append_size <= max {
                self.prepare_to_rebuild(merge_to)?;
                self.merge_blob(*blob_idx, merge_to)?;
            } else {
                merge_to = *blob_idx;
            }
        }
        Ok(())
    }
fn try_merge_blobs ( & mut self , low : usize , max : usize ) -> Result < ( ) > { let mut need_merge_blobs = Vec :: new ( ) ; for idx in 0 .. self . states . len ( ) { let blob_info = self . ori_blob_mgr . get_blob ( idx ) . unwrap ( ) ; match self . states [ idx ] . as_ref ( ) . unwrap ( ) { State :: Original ( cs ) => { let blob_size = if blob_info . compressed_blob_size == 0 { cs . total_size } else { blob_info . compressed_blob_size as usize } ; if blob_size < low { info ! ( " " blob_info blob_id blob_size ) ; need_merge_blobs . push ( ( idx , blob_size ) ) ; } } State :: Rebuild ( cs ) => { if cs . total_size < low { info ! ( " " blob_info blob_id cs total_size ) ; need_merge_blobs . push ( ( idx , cs . total_size ) ) ; } } _ => { } } } // sort by size need_merge_blobs . sort_by ( | ( _ , len1 ) , ( _ , len2 ) | len1 . cmp ( len2 ) ) ; // try merge if need_merge_blobs . len ( ) < 2 { return Ok ( ( ) ) ; } let mut merge_to = need_merge_blobs [ 0 ] . 0 ; for ( blob_idx , _ ) in need_merge_blobs . iter ( ) . skip ( 1 ) { let before_size = self . states [ merge_to ] . as_ref ( ) . unwrap ( ) . chunk_total_size ( ) ? ; let append_size = self . states [ * blob_idx ] . as_ref ( ) . unwrap ( ) . chunk_total_size ( ) ? ; if before_size + append_size <= max { self . prepare_to_rebuild ( merge_to ) ? ; self . merge_blob ( * blob_idx , merge_to ) ? ; } else { merge_to = * blob_idx ; } } Ok ( ( ) ) }
use greedy algorithm to merge small blobs(<low)
use greedy algorithm to merge small blobs ( <low )
&mut self
low
usize
max
usize
&mut self
low
usize
max
usize