mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-06 17:22:54 +00:00
move minmax to bitpacker
move minmax to bitpacker use minmax in blocked bitpacker
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user