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 re_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
impl Bitmap
sourcepub fn iter(&self) -> BitmapIter<'_> ⓘ
pub fn iter(&self) -> BitmapIter<'_> ⓘ
Returns a new iterator of bool
over this bitmap
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.
sourcepub fn as_slice(&self) -> (&[u8], usize, usize)
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 range0 <= offsets < 8
..3
: The length in number of bits.
sourcepub const fn unset_bits(&self) -> usize
pub const fn unset_bits(&self) -> usize
sourcepub fn null_count(&self) -> usize
👎Deprecated since 0.13.0: use unset_bits
instead
pub fn null_count(&self) -> usize
unset_bits
insteadReturns the number of unset bits on this Bitmap
.
sourcepub fn slice(&mut self, offset: usize, length: usize)
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
.
sourcepub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize)
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()
sourcepub fn sliced(self, offset: usize, length: usize) -> Self
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
.
sourcepub unsafe fn sliced_unchecked(self, offset: usize, length: usize) -> Self
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()
sourcepub unsafe fn get_bit_unchecked(&self, i: usize) -> bool
pub unsafe fn get_bit_unchecked(&self, i: usize) -> bool
sourcepub fn into_mut(self) -> Either<Self, MutableBitmap> ⓘ
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:
sourcepub fn make_mut(self) -> MutableBitmap
pub fn make_mut(self) -> MutableBitmap
Converts this Bitmap
into a MutableBitmap
, cloning its internal
buffer if required (clone-on-write).
sourcepub fn new_constant(value: bool, length: usize) -> Self
pub fn new_constant(value: bool, length: usize) -> Self
Initializes an new Bitmap
filled with set/unset values.
sourcepub fn new_zeroed(length: usize) -> Self
pub fn new_zeroed(length: usize) -> Self
Initializes an new Bitmap
filled with unset values.
sourcepub fn null_count_range(&self, offset: usize, length: usize) -> usize
pub fn null_count_range(&self, offset: usize, length: usize) -> usize
Counts the nulls (unset bits) starting from offset
bits and for length
bits.
sourcepub fn from_u8_slice<T: AsRef<[u8]>>(slice: T, length: usize) -> Self
pub fn from_u8_slice<T: AsRef<[u8]>>(slice: T, length: usize) -> Self
sourcepub fn from_u8_vec(vec: Vec<u8>, length: usize) -> Self
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
sourcepub fn into_inner(self) -> (Arc<Bytes<u8>>, usize, usize, usize)
pub fn into_inner(self) -> (Arc<Bytes<u8>>, usize, usize, usize)
Returns its internal representation
source§impl Bitmap
impl Bitmap
sourcepub unsafe fn from_trusted_len_iter_unchecked<I: Iterator<Item = bool>>(
iterator: I
) -> Self
pub unsafe fn from_trusted_len_iter_unchecked<I: Iterator<Item = bool>>( iterator: I ) -> Self
sourcepub fn from_trusted_len_iter<I: TrustedLen<Item = bool>>(iterator: I) -> Self
pub fn from_trusted_len_iter<I: TrustedLen<Item = bool>>(iterator: I) -> Self
Creates a new Bitmap
from an iterator of booleans.
sourcepub fn try_from_trusted_len_iter<E, I: TrustedLen<Item = Result<bool, E>>>(
iterator: I
) -> Result<Self, E>
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.
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> 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 From<MutableBitmap> for Bitmap
impl From<MutableBitmap> for Bitmap
source§fn from(buffer: MutableBitmap) -> Self
fn from(buffer: MutableBitmap) -> Self
source§impl FromIterator<bool> for Bitmap
impl FromIterator<bool> for Bitmap
source§impl<'a> IntoIterator for &'a Bitmap
impl<'a> IntoIterator for &'a Bitmap
source§impl IntoIterator for Bitmap
impl IntoIterator for Bitmap
Auto Trait Implementations§
impl Freeze for Bitmap
impl RefUnwindSafe for Bitmap
impl Send for Bitmap
impl Sync for Bitmap
impl Unpin for Bitmap
impl UnwindSafe for Bitmap
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> 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