Skip to content

Commit

Permalink
Fixed edge case of a small bitpacked.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Aug 27, 2021
1 parent 7618890 commit 2c61012
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/encoding/hybrid_rle/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl<'a> Iterator for Decoder<'a> {
if indicator & 1 == 1 {
// is bitpacking
let bytes = (indicator as usize >> 1) * self.num_bits as usize;
let bytes = std::cmp::min(bytes, self.values.len());
let result = Some(HybridEncoded::Bitpacked(&self.values[..bytes]));
self.values = &self.values[bytes..];
result
Expand Down
13 changes: 13 additions & 0 deletions src/encoding/hybrid_rle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,17 @@ mod tests {

assert_eq!(result, (0..1000).collect::<Vec<_>>());
}

#[test]
fn small() {
let data = vec![3, 2];

let num_bits = 3;

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

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

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

0 comments on commit 2c61012

Please sign in to comment.