Skip to content

Commit

Permalink
Fixed issue when no compressor can fulfill the maximum error allowed.…
Browse files Browse the repository at this point in the history
… Chosing on file size.
cjrolo committed Sep 17, 2024
1 parent 5bd611c commit 42a4343
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions brro-compressor/src/frame/mod.rs
Original file line number Diff line number Diff line change
@@ -97,20 +97,21 @@ impl CompressorFrame {
.compressed_data;
} else {
// Run all the eligible compressors and choose smallest
let (smallest_result, chosen_compressor) = compressor_list
.iter()
.map(|compressor| {
(
compressor.get_compress_bounded_results(data, max_error as f64),
compressor,
)
})
let compressor_results = compressor_list.iter().map(|compressor| {
(
compressor.get_compress_bounded_results(data, max_error as f64),
compressor,
)
});
let best_compressor = compressor_results
.clone()
.filter(|(result, _)| result.error <= max_error as f64)
.min_by_key(|x| x.0.compressed_data.len())
.unwrap();
.or_else(|| compressor_results.min_by_key(|x| x.0.compressed_data.len()));

self.data = smallest_result.compressed_data;
self.compressor = *chosen_compressor;
let selection = best_compressor.unwrap();
self.data = selection.0.compressed_data;
self.compressor = *selection.1;
}
debug!("Auto Compressor Selection: {:?}", self.compressor);
}

0 comments on commit 42a4343

Please sign in to comment.