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

Commit

Permalink
Made null_count not cached.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Oct 31, 2021
1 parent 5fc843d commit 296838f
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions src/bitmap/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ pub struct Bitmap {
// both are measured in bits. They are used to bound the bitmap to a region of Bytes.
offset: usize,
length: usize,
// this is a cache: it must be computed on initialization
null_count: usize,
}

impl std::fmt::Debug for Bitmap {
Expand Down Expand Up @@ -68,12 +66,10 @@ impl Bitmap {
#[inline]
pub(crate) fn from_bytes(bytes: Bytes<u8>, length: usize) -> Self {
assert!(length <= bytes.len() * 8);
let null_count = count_zeros(&bytes, 0, length);
Self {
length,
offset: 0,
bytes: Arc::new(bytes),
null_count,
}
}

Expand Down Expand Up @@ -103,7 +99,7 @@ impl Bitmap {
/// Returns the number of unset bits on this [`Bitmap`].
#[inline]
pub fn null_count(&self) -> usize {
self.null_count
count_zeros(&self.bytes, self.offset, self.length)
}

/// Slices `self`, offseting by `offset` and truncating up to `length` bits.
Expand All @@ -121,17 +117,6 @@ impl Bitmap {
/// The caller must ensure that `self.offset + offset + length <= self.len()`
#[inline]
pub unsafe fn slice_unchecked(mut self, offset: usize, length: usize) -> Self {
// 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);
} else {
// subtract the null count of the chunks we slice off
let start_end = self.offset + offset + length;
let head_count = count_zeros(&self.bytes, self.offset, offset);
let tail_count = count_zeros(&self.bytes, start_end, self.length - length - offset);
self.null_count -= head_count + tail_count;
}
self.offset += offset;
self.length = length;
self
Expand Down

0 comments on commit 296838f

Please sign in to comment.