Struct arrow2::bitmap::Bitmap

source ·
pub struct Bitmap { /* private fields */ }
Expand description

An immutable container semantically equivalent to Arc<Vec<bool>> but represented as Arc<Vec<u8>> where each boolean is represented as a single bit.

Examples

use arrow2::bitmap::{Bitmap, MutableBitmap};

let bitmap = Bitmap::from([true, false, true]);
assert_eq!(bitmap.iter().collect::<Vec<_>>(), vec![true, false, true]);

// creation directly from bytes
let bitmap = Bitmap::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(), 0, 5));
// debug helps :)
assert_eq!(format!("{:?}", bitmap), "[0b___01101]".to_string());

// it supports copy-on-write semantics (to a `MutableBitmap`)
let bitmap: MutableBitmap = bitmap.into_mut().right().unwrap();
assert_eq!(bitmap, MutableBitmap::from([true, false, true, true, false]));

// slicing is 'O(1)' (data is shared)
let bitmap = Bitmap::try_new(vec![0b00001101], 5).unwrap();
let mut sliced = bitmap.clone();
sliced.slice(1, 4);
assert_eq!(sliced.as_slice(), ([0b00001101u8].as_ref(), 1, 4)); // 1 here is the offset:
assert_eq!(format!("{:?}", sliced), "[0b___0110_]".to_string());
// when sliced (or cloned), it is no longer possible to `into_mut`.
let same: Bitmap = sliced.into_mut().left().unwrap();

Implementations§

source§

impl Bitmap

source

pub fn new() -> Self

Initializes an empty Bitmap.

source

pub fn try_new(bytes: Vec<u8>, length: usize) -> Result<Self, Error>

Initializes a new Bitmap from vector of bytes and a length.

Errors

This function errors iff length > bytes.len() * 8

source

pub fn len(&self) -> usize

Returns the length of the Bitmap.

source

pub fn is_empty(&self) -> bool

Returns whether Bitmap is empty

source

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

Returns a new iterator of bool over this bitmap

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 as_slice(&self) -> (&[u8], usize, usize)

Returns the byte slice of this Bitmap.

The returned tuple contains:

  • .1: The byte slice, truncated to the start of the first bit. So the start of the slice is within the first 8 bits.
  • .2: The start offset in bits on a range 0 <= offsets < 8.
  • .3: The length in number of bits.
source

pub const fn unset_bits(&self) -> usize

Returns the number of unset bits on this Bitmap.

Guaranteed to be <= self.len().

Implementation

This function is O(1) - the number of unset bits is computed when the bitmap is created

source

pub fn null_count(&self) -> usize

👎Deprecated since 0.13.0: use unset_bits instead

Returns the number of unset bits on this Bitmap.

source

pub fn slice(&mut self, offset: usize, length: usize)

Slices self, offsetting by offset and truncating up to length bits.

Panic

Panics iff offset + length > self.length, i.e. if the offset and length exceeds the allocated capacity of self.

source

pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize)

Slices self, offseting by offset and truncating up to length bits.

Safety

The caller must ensure that self.offset + offset + length <= self.len()

source

pub fn sliced(self, offset: usize, length: usize) -> Self

Slices self, offsetting by offset and truncating up to length bits.

Panic

Panics iff offset + length > self.length, i.e. if the offset and length exceeds the allocated capacity of self.

source

pub unsafe fn sliced_unchecked(self, offset: usize, length: usize) -> Self

Slices self, offseting by offset and truncating up to length bits.

Safety

The caller must ensure that self.offset + offset + length <= self.len()

source

pub fn get_bit(&self, i: usize) -> bool

Returns whether the bit at position i is set.

Panics

Panics iff i >= self.len().

source

pub unsafe fn get_bit_unchecked(&self, i: usize) -> bool

Unsafely returns whether the bit at position i is set.

Safety

Unsound iff i >= self.len().

source

pub fn into_mut(self) -> Either<Self, MutableBitmap>

Converts this Bitmap to MutableBitmap, returning itself if the conversion is not possible

This operation returns a MutableBitmap iff:

  • this Bitmap is not an offsetted slice of another Bitmap
  • this Bitmap has not been cloned (i.e. Arc::get_mut yields Some)
  • this Bitmap was not imported from the c data interface (FFI)
source

pub fn make_mut(self) -> MutableBitmap

Converts this Bitmap into a MutableBitmap, cloning its internal buffer if required (clone-on-write).

source

pub fn new_zeroed(length: usize) -> Self

Initializes an new Bitmap filled with unset values.

source

pub fn null_count_range(&self, offset: usize, length: usize) -> usize

Counts the nulls (unset bits) starting from offset bits and for length bits.

source

pub fn from_u8_slice<T: AsRef<[u8]>>(slice: T, length: usize) -> Self

Creates a new Bitmap from a slice and length.

Panic

Panics iff length <= bytes.len() * 8

source

pub fn from_u8_vec(vec: Vec<u8>, length: usize) -> Self

Alias for Bitmap::try_new().unwrap() This function is O(1)

Panic

This function panics iff length <= bytes.len() * 8

source

pub fn get(&self, i: usize) -> Option<bool>

Returns whether the bit at position i is set.

source

pub fn into_inner(self) -> (Arc<Bytes<u8>>, usize, usize, usize)

Returns its internal representation

source

pub unsafe fn from_inner( bytes: Arc<Bytes<u8>>, offset: usize, length: usize, unset_bits: usize ) -> Result<Self, Error>

Creates a [Bitmap] from its internal representation. This is the inverted from [Bitmap::into_inner]

Safety

The invariants of this struct must be upheld

source

pub unsafe fn from_inner_unchecked( bytes: Arc<Bytes<u8>>, offset: usize, length: usize, unset_bits: usize ) -> Self

Creates a [Bitmap] from its internal representation. This is the inverted from [Bitmap::into_inner]

Safety

Callers must ensure all invariants of this struct are upheld.

source§

impl Bitmap

source

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

Creates a new Bitmap from an iterator of booleans.

Safety

The iterator must report an accurate length.

source

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

Creates a new Bitmap from an iterator of booleans.

source

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

Creates a new Bitmap from a fallible iterator of booleans.

source

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

Creates a new Bitmap from a fallible iterator of booleans.

Safety

The iterator must report an accurate length.

source

pub fn from_null_buffer(value: NullBuffer) -> Self

Create a new Bitmap from an arrow NullBuffer

Trait Implementations§

source§

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

§

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, 'b> BitAnd<&'b Bitmap> for &'a Bitmap

§

type Output = Bitmap

The resulting type after applying the & operator.
source§

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

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

§

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, 'b> BitOr<&'b Bitmap> for &'a Bitmap

§

type Output = Bitmap

The resulting type after applying the | operator.
source§

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

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> BitXor<&'a Bitmap> for MutableBitmap

§

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, 'b> BitXor<&'b Bitmap> for &'a Bitmap

§

type Output = Bitmap

The resulting type after applying the ^ operator.
source§

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

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 Bitmap

source§

fn clone(&self) -> Bitmap

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 Bitmap

source§

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

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

impl Default for Bitmap

source§

fn default() -> Self

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

impl From<Bitmap> for NullBuffer

source§

fn from(value: Bitmap) -> Self

Converts to this type from the input type.
source§

impl From<MutableBitmap> for Bitmap

source§

fn from(buffer: MutableBitmap) -> Self

Converts to this type from the input type.
source§

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

source§

fn from(slice: P) -> Self

Converts to this type from the input type.
source§

impl FromIterator<bool> for Bitmap

source§

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

Creates a value from an iterator. Read more
source§

impl<'a> IntoIterator for &'a Bitmap

§

type Item = bool

The type of the elements being iterated over.
§

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 IntoIterator for Bitmap

§

type Item = bool

The type of the elements being iterated over.
§

type IntoIter = IntoIter

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 &Bitmap

§

type Output = Bitmap

The resulting type after applying the ! operator.
source§

fn not(self) -> Bitmap

Performs the unary ! operation. Read more
source§

impl PartialEq<Bitmap> for Bitmap

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere 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 Twhere 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<I> IntoStreamingIterator for Iwhere I: IntoIterator,

source§

fn into_streaming_iter(self) -> Convert<Self::IntoIter>

source§

fn into_streaming_iter_ref<'a, T>(self) -> ConvertRef<'a, Self::IntoIter, T>where Self: IntoIterator<Item = &'a T>, T: ?Sized,

Turns an IntoIterator of references into a StreamingIterator. Read more
source§

fn into_streaming_iter_mut<'a, T>(self) -> ConvertMut<'a, Self::IntoIter, T>where Self: IntoIterator<Item = &'a mut T>, T: ?Sized,

Turns an IntoIterator of mutable references into a StreamingIteratorMut. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> Allocation for Twhere T: RefUnwindSafe + Send + Sync,