Skip to content

Commit

Permalink
Merge dac7034 into c0494fe
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiKaiWi authored Mar 15, 2023
2 parents c0494fe + dac7034 commit 9022d23
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions analytic_engine/src/compaction/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ impl Bucket {

fn with_files(files: Vec<FileHandle>) -> Self {
let total: usize = files.iter().map(|f| f.size() as usize).sum();
Self {
avg_size: total / files.len(),
files,
}
let avg_size = if files.is_empty() {
0
} else {
total / files.len()
};
Self { avg_size, files }
}

fn insert_file(&mut self, file: &FileHandle) {
Expand Down Expand Up @@ -823,4 +825,11 @@ mod tests {
.collect::<Vec<_>>()
);
}

#[test]
fn empty_bucket() {
let bucket = Bucket::with_files(vec![]);
assert_eq!(bucket.avg_size, 0);
assert!(bucket.files.is_empty());
}
}

0 comments on commit 9022d23

Please sign in to comment.