polars_arrow::bitmap

Struct MutableBitmap

Source
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

Source

pub fn new() -> Self

Initializes an empty MutableBitmap.

Source

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

Source

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.

Source

pub fn with_capacity(capacity: usize) -> Self

Initializes a pre-allocated MutableBitmap with capacity for capacity bits.

Source

pub fn push(&mut self, value: bool)

Pushes a new bit to the MutableBitmap, re-sizing it if necessary.

Source

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.

Source

pub fn get(&self, index: usize) -> bool

Returns whether the position index is set.

§Panics

Panics iff index >= self.len().

Source

pub unsafe fn get_unchecked(&self, index: usize) -> bool

Returns whether the position index is set.

§Safety

The caller must ensure index < self.len().

Source

pub fn set(&mut self, index: usize, value: bool)

Sets the position index to value

§Panics

Panics iff index >= self.len().

Source

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().

Source

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().

Source

pub fn iter(&self) -> BitmapIter<'_>

constructs a new iterator over the bits of MutableBitmap.

Source

pub fn clear(&mut self)

Empties the MutableBitmap.

Source

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.

Source

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.

Source

pub fn from_len_zeroed(length: usize) -> Self

Initializes a zeroed MutableBitmap.

Source

pub fn from_len_set(length: usize) -> Self

Initializes a MutableBitmap with all values set to valid/ true.

Source

pub fn reserve(&mut self, additional: usize)

Reserves additional bits in the MutableBitmap, potentially re-allocating its buffer.

Source

pub fn capacity(&self) -> usize

Returns the capacity of MutableBitmap in number of bits.

Source

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.

Source

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)

Source

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)

Source

pub fn len(&self) -> usize

Returns the length of the MutableBitmap.

Source

pub fn is_empty(&self) -> bool

Returns whether MutableBitmap is empty.

Source

pub unsafe fn set_unchecked(&mut self, index: usize, value: bool)

Sets the position index to value

§Safety

Caller must ensure that index < self.len()

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the MutableBitmap to fit its current length.

Source

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.

Source

pub fn intersects_with(&self, other: &Self) -> bool

Source

pub fn freeze(self) -> Bitmap

Source§

impl MutableBitmap

Source

pub fn extend_from_trusted_len_iter<I: TrustedLen<Item = bool>>( &mut self, iterator: I, )

Extends self from a TrustedLen iterator.

Source

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.

Source

pub unsafe fn from_trusted_len_iter_unchecked<I>(iterator: I) -> Self
where I: Iterator<Item = bool>,

Creates a new MutableBitmap from an iterator of booleans.

§Safety

The iterator must report an accurate length.

Source

pub fn from_trusted_len_iter<I>(iterator: I) -> Self
where I: TrustedLen<Item = bool>,

Creates a new MutableBitmap from an iterator of booleans.

Source

pub fn try_from_trusted_len_iter<E, I>(iterator: I) -> Result<Self, E>
where I: TrustedLen<Item = Result<bool, E>>,

Creates a new MutableBitmap from an iterator of booleans.

Source

pub unsafe fn try_from_trusted_len_iter_unchecked<E, I>( iterator: I, ) -> Result<Self, E>
where I: Iterator<Item = Result<bool, E>>,

Creates a new MutableBitmap from an falible iterator of booleans.

§Safety

The caller must guarantee that the iterator is TrustedLen.

Source

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

Source

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.

Source

pub fn extend_from_bitmap(&mut self, bitmap: &Bitmap)

Extends the MutableBitmap from a Bitmap.

Source

pub fn as_slice(&self) -> &[u8]

Returns the slice of bytes of this MutableBitmap. Note that the last byte may not be fully used.

Source

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

Source§

type Output = MutableBitmap

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: &'a Bitmap) -> Self

Performs the & operation. Read more
Source§

impl<'a> BitAndAssign<&'a Bitmap> for &mut MutableBitmap

Source§

fn bitand_assign(&mut self, rhs: &'a Bitmap)

Performs the &= operation. Read more
Source§

impl<'a> BitOr<&'a Bitmap> for MutableBitmap

Source§

type Output = MutableBitmap

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &'a Bitmap) -> Self

Performs the | operation. Read more
Source§

impl<'a> BitOrAssign<&'a Bitmap> for &mut MutableBitmap

Source§

fn bitor_assign(&mut self, rhs: &'a Bitmap)

Performs the |= operation. Read more
Source§

impl<'a> BitOrAssign<&'a MutableBitmap> for &mut MutableBitmap

Source§

fn bitor_assign(&mut self, rhs: &'a MutableBitmap)

Performs the |= operation. Read more
Source§

impl<'a> BitXor<&'a Bitmap> for MutableBitmap

Source§

type Output = MutableBitmap

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: &'a Bitmap) -> Self

Performs the ^ operation. Read more
Source§

impl<'a> BitXorAssign<&'a Bitmap> for &mut MutableBitmap

Source§

fn bitxor_assign(&mut self, rhs: &'a Bitmap)

Performs the ^= operation. Read more
Source§

impl Clone for MutableBitmap

Source§

fn clone(&self) -> MutableBitmap

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MutableBitmap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MutableBitmap

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<MutableBitmap> for Bitmap

Source§

fn from(buffer: MutableBitmap) -> Self

Converts to this type from the input type.
Source§

impl From<MutableBitmap> for Option<Bitmap>

Source§

fn from(buffer: MutableBitmap) -> Self

Converts to this type from the input type.
Source§

impl<P: AsRef<[bool]>> From<P> for MutableBitmap

Source§

fn from(slice: P) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<bool> for MutableBitmap

Source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = bool>,

Creates a value from an iterator. Read more
Source§

impl<'a> IntoIterator for &'a MutableBitmap

Source§

type Item = bool

The type of the elements being iterated over.
Source§

type IntoIter = BitmapIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Not for MutableBitmap

Source§

type Output = MutableBitmap

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self

Performs the unary ! operation. Read more
Source§

impl PartialEq for MutableBitmap

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Pushable<bool> for MutableBitmap

Source§

type Freeze = Bitmap

Source§

fn reserve(&mut self, additional: usize)

Source§

fn len(&self) -> usize

Source§

fn push(&mut self, value: bool)

Source§

fn push_null(&mut self)

Source§

fn extend_constant(&mut self, additional: usize, value: bool)

Source§

fn extend_null_constant(&mut self, additional: usize)

Source§

fn freeze(self) -> Self::Freeze

Source§

fn with_capacity(capacity: usize) -> Self

Source§

fn extend_n(&mut self, n: usize, iter: impl Iterator<Item = T>)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.