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

Commit

Permalink
add new_constant for Bitmap (#1579)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dousir9 authored Oct 13, 2023
1 parent dd80c89 commit 6a4b531
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/bitmap/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@ impl Bitmap {
}
}

/// Initializes an new [`Bitmap`] filled with set/unset values.
#[inline]
pub fn new_constant(value: bool, length: usize) -> Self {
match value {
true => Self::new_trued(length),
false => Self::new_zeroed(length),
}
}

/// Initializes an new [`Bitmap`] filled with unset values.
#[inline]
pub fn new_zeroed(length: usize) -> Self {
Expand All @@ -292,6 +301,15 @@ impl Bitmap {
unsafe { Bitmap::from_inner_unchecked(Arc::new(bytes.into()), 0, length, length) }
}

/// Initializes an new [`Bitmap`] filled with set values.
#[inline]
pub fn new_trued(length: usize) -> Self {
// just set each byte to u8::MAX
// we will not access data with index >= length
let bytes = vec![0b11111111u8; length.saturating_add(7) / 8];
unsafe { Bitmap::from_inner_unchecked(Arc::new(bytes.into()), 0, length, length) }
}

/// Counts the nulls (unset bits) starting from `offset` bits and for `length` bits.
#[inline]
pub fn null_count_range(&self, offset: usize, length: usize) -> usize {
Expand Down

0 comments on commit 6a4b531

Please sign in to comment.