Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Fixed wrong null_count when slicing a sliced Bitmap #848

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bitmap/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Bitmap {
// count the smallest chunk
if length < self.length / 2 {
// count the null values in the slice
self.null_count = count_zeros(&self.bytes, offset, length);
self.null_count = count_zeros(&self.bytes, self.offset + offset, length);
} else {
// subtract the null count of the chunks we slice off
let start_end = self.offset + offset + length;
Expand Down
29 changes: 29 additions & 0 deletions src/bitmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,32 @@ mod bitmap_ops;
pub use bitmap_ops::*;

pub mod utils;

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn subslicing_gives_correct_null_count() {
let mut base = MutableBitmap::new();
base.push(false);
base.push(true);
base.push(true);
base.push(false);
base.push(false);
base.push(true);
base.push(true);
base.push(true);

let base = Bitmap::from(base);
assert_eq!(base.null_count(), 3);

let view1 = base.clone().slice(0, 1);
let view2 = base.slice(1, 7);
assert_eq!(view1.null_count(), 1);
assert_eq!(view2.null_count(), 2);

let view3 = view2.slice(0, 1);
assert_eq!(view3.null_count(), 0);
}
}