pub struct MutableBitmap { /* private fields */ }Expand description
A container of booleans. MutableBitmap is semantically equivalent
to Vec<bool>.
The two main differences against Vec<bool> is that each element stored as a single bit,
thereby:
- it uses 8x less memory
- it cannot be represented as
&[bool](i.e. no pointer arithmetics).
A MutableBitmap can be converted to a Bitmap at O(1).
§Examples
use polars_arrow::bitmap::MutableBitmap;
let bitmap = MutableBitmap::from([true, false, true]);
assert_eq!(bitmap.iter().collect::<Vec<_>>(), vec![true, false, true]);
// creation directly from bytes
let mut bitmap = MutableBitmap::try_new(vec![0b00001101], 5).unwrap();
// note: the first bit is the left-most of the first byte
assert_eq!(bitmap.iter().collect::<Vec<_>>(), vec![true, false, true, true, false]);
// we can also get the slice:
assert_eq!(bitmap.as_slice(), [0b00001101u8].as_ref());
// debug helps :)
assert_eq!(format!("{:?}", bitmap), "Bitmap { len: 5, offset: 0, bytes: [0b___01101] }");
// It supports mutation in place
bitmap.set(0, false);
assert_eq!(format!("{:?}", bitmap), "Bitmap { len: 5, offset: 0, bytes: [0b___01100] }");
// and `O(1)` random access
assert_eq!(bitmap.get(0), false);§Implementation
This container is internally a Vec<u8>.
Implementations§
Source§impl MutableBitmap
impl MutableBitmap
Sourcepub fn new() -> Self
pub fn new() -> Self
Initializes an empty MutableBitmap.
Sourcepub fn try_new(bytes: Vec<u8>, length: usize) -> PolarsResult<Self>
pub fn try_new(bytes: Vec<u8>, length: usize) -> PolarsResult<Self>
Initializes a new MutableBitmap from a Vec<u8> and a length.
§Errors
This function errors iff length > bytes.len() * 8
Sourcepub fn from_vec(buffer: Vec<u8>, length: usize) -> Self
pub fn from_vec(buffer: Vec<u8>, length: usize) -> Self
Initializes a MutableBitmap from a Vec<u8> and a length.
This function is O(1).
§Panic
Panics iff the length is larger than the length of the buffer times 8.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Initializes a pre-allocated MutableBitmap with capacity for capacity bits.
Sourcepub fn push(&mut self, value: bool)
pub fn push(&mut self, value: bool)
Pushes a new bit to the MutableBitmap, re-sizing it if necessary.
Sourcepub fn pop(&mut self) -> Option<bool>
pub fn pop(&mut self) -> Option<bool>
Pop the last bit from the MutableBitmap.
Note if the MutableBitmap is empty, this method will return None.
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> bool
pub unsafe fn get_unchecked(&self, index: usize) -> bool
Sourcepub unsafe fn or_pos_unchecked(&mut self, index: usize, value: bool)
pub unsafe fn or_pos_unchecked(&mut self, index: usize, value: bool)
Sets the position index to the OR of its original value and value.
§Safety
It’s undefined behavior if index >= self.len().
Sourcepub unsafe fn and_pos_unchecked(&mut self, index: usize, value: bool)
pub unsafe fn and_pos_unchecked(&mut self, index: usize, value: bool)
Sets the position index to the AND of its original value and value.
§Safety
It’s undefined behavior if index >= self.len().
Sourcepub fn iter(&self) -> BitmapIter<'_> ⓘ
pub fn iter(&self) -> BitmapIter<'_> ⓘ
constructs a new iterator over the bits of MutableBitmap.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Empties the MutableBitmap.
Sourcepub fn extend_constant(&mut self, additional: usize, value: bool)
pub fn extend_constant(&mut self, additional: usize, value: bool)
Extends MutableBitmap by additional values of constant value.
§Implementation
This function is an order of magnitude faster than pushing element by element.
Sourcepub fn resize(&mut self, length: usize, value: bool)
pub fn resize(&mut self, length: usize, value: bool)
Resizes the MutableBitmap to the specified length, inserting value
if the length is bigger than the current length.
Sourcepub fn from_len_zeroed(length: usize) -> Self
pub fn from_len_zeroed(length: usize) -> Self
Initializes a zeroed MutableBitmap.
Sourcepub fn from_len_set(length: usize) -> Self
pub fn from_len_set(length: usize) -> Self
Initializes a MutableBitmap with all values set to valid/ true.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves additional bits in the MutableBitmap, potentially re-allocating its buffer.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the capacity of MutableBitmap in number of bits.
Sourcepub unsafe fn push_unchecked(&mut self, value: bool)
pub unsafe fn push_unchecked(&mut self, value: bool)
Pushes a new bit to the MutableBitmap
§Safety
The caller must ensure that the MutableBitmap has sufficient capacity.
Sourcepub fn unset_bits(&self) -> usize
pub fn unset_bits(&self) -> usize
Returns the number of unset bits on this MutableBitmap.
Guaranteed to be <= self.len().
§Implementation
This function is O(N)
Sourcepub fn set_bits(&self) -> usize
pub fn set_bits(&self) -> usize
Returns the number of set bits on this MutableBitmap.
Guaranteed to be <= self.len().
§Implementation
This function is O(N)
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the MutableBitmap.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether MutableBitmap is empty.
Sourcepub unsafe fn set_unchecked(&mut self, index: usize, value: bool)
pub unsafe fn set_unchecked(&mut self, index: usize, value: bool)
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the MutableBitmap to fit its current length.
Sourcepub fn chunks<T: BitChunk>(&self) -> BitChunks<'_, T> ⓘ
pub fn chunks<T: BitChunk>(&self) -> BitChunks<'_, T> ⓘ
Returns an iterator over bits in bit chunks BitChunk.
This iterator is useful to operate over multiple bits via e.g. bitwise.
pub fn intersects_with(&self, other: &Self) -> bool
pub fn freeze(self) -> Bitmap
Source§impl MutableBitmap
impl MutableBitmap
Sourcepub fn extend_from_trusted_len_iter<I: TrustedLen<Item = bool>>(
&mut self,
iterator: I,
)
pub fn extend_from_trusted_len_iter<I: TrustedLen<Item = bool>>( &mut self, iterator: I, )
Extends self from a TrustedLen iterator.
Sourcepub unsafe fn extend_from_trusted_len_iter_unchecked<I: Iterator<Item = bool>>(
&mut self,
iterator: I,
)
pub unsafe fn extend_from_trusted_len_iter_unchecked<I: Iterator<Item = bool>>( &mut self, iterator: I, )
Extends self from an iterator of trusted len.
§Safety
The caller must guarantee that the iterator has a trusted len.
Sourcepub unsafe fn from_trusted_len_iter_unchecked<I>(iterator: I) -> Self
pub unsafe fn from_trusted_len_iter_unchecked<I>(iterator: I) -> Self
Creates a new MutableBitmap from an iterator of booleans.
§Safety
The iterator must report an accurate length.
Sourcepub fn from_trusted_len_iter<I>(iterator: I) -> Selfwhere
I: TrustedLen<Item = bool>,
pub fn from_trusted_len_iter<I>(iterator: I) -> Selfwhere
I: TrustedLen<Item = bool>,
Creates a new MutableBitmap from an iterator of booleans.
Sourcepub fn try_from_trusted_len_iter<E, I>(iterator: I) -> Result<Self, E>
pub fn try_from_trusted_len_iter<E, I>(iterator: I) -> Result<Self, E>
Creates a new MutableBitmap from an iterator of booleans.
Sourcepub unsafe fn try_from_trusted_len_iter_unchecked<E, I>(
iterator: I,
) -> Result<Self, E>
pub unsafe fn try_from_trusted_len_iter_unchecked<E, I>( iterator: I, ) -> Result<Self, E>
Creates a new MutableBitmap from an falible iterator of booleans.
§Safety
The caller must guarantee that the iterator is TrustedLen.
Sourcepub unsafe fn extend_from_slice_unchecked(
&mut self,
slice: &[u8],
offset: usize,
length: usize,
)
pub unsafe fn extend_from_slice_unchecked( &mut self, slice: &[u8], offset: usize, length: usize, )
Extends the MutableBitmap from a slice of bytes with optional offset.
This is the fastest way to extend a MutableBitmap.
§Implementation
When both MutableBitmap’s length and offset are both multiples of 8,
this function performs a memcopy. Else, it first aligns bit by bit and then performs a memcopy.
§Safety
Caller must ensure offset + length <= slice.len() * 8
Sourcepub fn extend_from_slice(&mut self, slice: &[u8], offset: usize, length: usize)
pub fn extend_from_slice(&mut self, slice: &[u8], offset: usize, length: usize)
Extends the MutableBitmap from a slice of bytes with optional offset.
This is the fastest way to extend a MutableBitmap.
§Implementation
When both MutableBitmap’s length and offset are both multiples of 8,
this function performs a memcopy. Else, it first aligns bit by bit and then performs a memcopy.
pub fn extend_from_bitmask(&mut self, bitmask: BitMask<'_>)
Sourcepub fn extend_from_bitmap(&mut self, bitmap: &Bitmap)
pub fn extend_from_bitmap(&mut self, bitmap: &Bitmap)
Extends the MutableBitmap from a Bitmap.
Sourcepub fn as_slice(&self) -> &[u8] ⓘ
pub fn as_slice(&self) -> &[u8] ⓘ
Returns the slice of bytes of this MutableBitmap.
Note that the last byte may not be fully used.
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Returns the slice of bytes of this MutableBitmap.
Note that the last byte may not be fully used.
Trait Implementations§
Source§impl<'a> BitAnd<&'a Bitmap> for MutableBitmap
impl<'a> BitAnd<&'a Bitmap> for MutableBitmap
Source§impl<'a> BitAndAssign<&'a Bitmap> for &mut MutableBitmap
impl<'a> BitAndAssign<&'a Bitmap> for &mut MutableBitmap
Source§fn bitand_assign(&mut self, rhs: &'a Bitmap)
fn bitand_assign(&mut self, rhs: &'a Bitmap)
&= operation. Read moreSource§impl<'a> BitOr<&'a Bitmap> for MutableBitmap
impl<'a> BitOr<&'a Bitmap> for MutableBitmap
Source§impl<'a> BitOrAssign<&'a Bitmap> for &mut MutableBitmap
impl<'a> BitOrAssign<&'a Bitmap> for &mut MutableBitmap
Source§fn bitor_assign(&mut self, rhs: &'a Bitmap)
fn bitor_assign(&mut self, rhs: &'a Bitmap)
|= operation. Read moreSource§impl<'a> BitOrAssign<&'a MutableBitmap> for &mut MutableBitmap
impl<'a> BitOrAssign<&'a MutableBitmap> for &mut MutableBitmap
Source§fn bitor_assign(&mut self, rhs: &'a MutableBitmap)
fn bitor_assign(&mut self, rhs: &'a MutableBitmap)
|= operation. Read moreSource§impl<'a> BitXor<&'a Bitmap> for MutableBitmap
impl<'a> BitXor<&'a Bitmap> for MutableBitmap
Source§impl<'a> BitXorAssign<&'a Bitmap> for &mut MutableBitmap
impl<'a> BitXorAssign<&'a Bitmap> for &mut MutableBitmap
Source§fn bitxor_assign(&mut self, rhs: &'a Bitmap)
fn bitxor_assign(&mut self, rhs: &'a Bitmap)
^= operation. Read moreSource§impl Clone for MutableBitmap
impl Clone for MutableBitmap
Source§fn clone(&self) -> MutableBitmap
fn clone(&self) -> MutableBitmap
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MutableBitmap
impl Debug for MutableBitmap
Source§impl Default for MutableBitmap
impl Default for MutableBitmap
Source§impl Extend<bool> for MutableBitmap
impl Extend<bool> for MutableBitmap
Source§fn extend<T: IntoIterator<Item = bool>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = bool>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl From<MutableBitmap> for Bitmap
impl From<MutableBitmap> for Bitmap
Source§fn from(buffer: MutableBitmap) -> Self
fn from(buffer: MutableBitmap) -> Self
Source§impl From<MutableBitmap> for Option<Bitmap>
impl From<MutableBitmap> for Option<Bitmap>
Source§fn from(buffer: MutableBitmap) -> Self
fn from(buffer: MutableBitmap) -> Self
Source§impl FromIterator<bool> for MutableBitmap
impl FromIterator<bool> for MutableBitmap
Source§impl<'a> IntoIterator for &'a MutableBitmap
impl<'a> IntoIterator for &'a MutableBitmap
Source§impl Not for MutableBitmap
impl Not for MutableBitmap
Source§impl PartialEq for MutableBitmap
impl PartialEq for MutableBitmap
Source§impl Pushable<bool> for MutableBitmap
impl Pushable<bool> for MutableBitmap
type Freeze = Bitmap
fn reserve(&mut self, additional: usize)
fn len(&self) -> usize
fn push(&mut self, value: bool)
fn push_null(&mut self)
fn extend_constant(&mut self, additional: usize, value: bool)
fn extend_null_constant(&mut self, additional: usize)
fn freeze(self) -> Self::Freeze
fn with_capacity(capacity: usize) -> Self
fn extend_n(&mut self, n: usize, iter: impl Iterator<Item = T>)
Auto Trait Implementations§
impl Freeze for MutableBitmap
impl RefUnwindSafe for MutableBitmap
impl Send for MutableBitmap
impl Sync for MutableBitmap
impl Unpin for MutableBitmap
impl UnwindSafe for MutableBitmap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more