Skip to content

Commit

Permalink
Fixed error in reading empty values in hybrid-RLE (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Jan 25, 2022
1 parent a554f3a commit 3897f1a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/encoding/hybrid_rle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ fn read_next<'a, 'b>(decoder: &'b mut Decoder<'a>, remaining: usize) -> State<'a
return State::None;
};

let state = decoder.next().unwrap();
match state {
HybridEncoded::Bitpacked(packed) => {
match decoder.next() {
Some(HybridEncoded::Bitpacked(packed)) => {
let num_bits = decoder.num_bits();
let length = std::cmp::min(packed.len() * 8 / num_bits as usize, remaining);
let decoder = bitpacking::Decoder::new(packed, num_bits as u8, length);
State::Bitpacked(decoder)
}
HybridEncoded::Rle(pack, additional) => {
Some(HybridEncoded::Rle(pack, additional)) => {
let mut bytes = [0u8; std::mem::size_of::<u32>()];
pack.iter()
.enumerate()
.for_each(|(i, byte)| bytes[i] = *byte);
let value = u32::from_le_bytes(bytes);
State::Rle(std::iter::repeat(value).take(additional))
}
None => State::None,
}
}

Expand Down Expand Up @@ -225,4 +225,17 @@ mod tests {

assert_eq!(result, &[0, 0]);
}

#[test]
fn empty_values() {
let data = [];

let num_bits = 1;

let decoder = HybridRleDecoder::new(&data, num_bits as u32, 100);

let result = decoder.collect::<Vec<_>>();

assert_eq!(result, vec![0; 100]);
}
}

0 comments on commit 3897f1a

Please sign in to comment.