move minmax to bitpacker

move minmax to bitpacker
use minmax in blocked bitpacker
This commit is contained in:
Pascal Seitz
2021-04-30 17:07:30 +02:00
parent fde9d27482
commit 478571ebb4
5 changed files with 22 additions and 24 deletions

View File

@@ -1,4 +1,4 @@
use crate::BitUnpacker;
use crate::{minmax, BitUnpacker};
use super::{bitpacker::BitPacker, compute_num_bits};
@@ -83,14 +83,9 @@ impl BlockedBitpacker {
}
pub fn flush(&mut self) {
if let Some(min_value) = self.buffer.iter().min() {
if let Some((min_value, max_value)) = minmax(self.buffer.iter()) {
let mut bit_packer = BitPacker::new();
let num_bits_block = self
.buffer
.iter()
.map(|val| compute_num_bits(*val - min_value))
.max()
.unwrap();
let num_bits_block = compute_num_bits(*max_value - min_value);
// todo performance: the padding handling could be done better, e.g. use a slice and
// return num_bytes written from bitpacker
self.compressed_blocks

View File

@@ -37,3 +37,16 @@ pub fn compute_num_bits(n: u64) -> u8 {
64
}
}
pub fn minmax<I, T>(mut vals: I) -> Option<(T, T)>
where
I: Iterator<Item = T>,
T: Copy + Ord,
{
if let Some(first_el) = vals.next() {
return Some(vals.fold((first_el, first_el), |(min_val, max_val), el| {
(min_val.min(el), max_val.max(el))
}));
}
None
}