pub struct Bitmap {
bytes: Arc<Bytes<u8>>,
offset: usize,
length: usize,
unset_bits: usize,
}
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();
Fields§
§bytes: Arc<Bytes<u8>>
§offset: usize
§length: usize
§unset_bits: usize
Implementations§
§impl Bitmap
impl Bitmap
pub fn iter(&self) -> BitmapIter<'_> ⓘ
pub fn iter(&self) -> BitmapIter<'_> ⓘ
Returns a new iterator of bool
over this bitmap
pub fn chunks<T>(&self) -> BitChunks<'_, T> ⓘwhere
T: BitChunk,
pub fn chunks<T>(&self) -> BitChunks<'_, T> ⓘwhere
T: BitChunk,
Returns an iterator over bits in bit chunks BitChunk
.
This iterator is useful to operate over multiple bits via e.g. bitwise.
pub 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.
pub const fn unset_bits(&self) -> usize
pub const fn unset_bits(&self) -> usize
pub 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
.
pub 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
.
pub 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()
pub fn sliced(self, offset: usize, length: usize) -> Bitmap
pub fn sliced(self, offset: usize, length: usize) -> Bitmap
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
.
pub unsafe fn sliced_unchecked(self, offset: usize, length: usize) -> Bitmap
pub unsafe fn sliced_unchecked(self, offset: usize, length: usize) -> Bitmap
Slices self
, offseting by offset
and truncating up to length
bits.
§Safety
The caller must ensure that self.offset + offset + length <= self.len()
pub unsafe fn get_bit_unchecked(&self, i: usize) -> bool
pub unsafe fn get_bit_unchecked(&self, i: usize) -> bool
pub fn into_mut(self) -> Either<Bitmap, MutableBitmap> ⓘ
pub fn into_mut(self) -> Either<Bitmap, MutableBitmap> ⓘ
Converts this Bitmap
to MutableBitmap
, returning itself if the conversion
is not possible
This operation returns a MutableBitmap
iff:
pub 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).
pub fn new_constant(value: bool, length: usize) -> Bitmap
pub fn new_constant(value: bool, length: usize) -> Bitmap
Initializes an new Bitmap
filled with set/unset values.
pub fn new_zeroed(length: usize) -> Bitmap
pub fn new_zeroed(length: usize) -> Bitmap
Initializes an new Bitmap
filled with unset values.
pub 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.
pub fn from_u8_slice<T>(slice: T, length: usize) -> Bitmap
pub fn from_u8_slice<T>(slice: T, length: usize) -> Bitmap
pub fn from_u8_vec(vec: Vec<u8>, length: usize) -> Bitmap
pub fn from_u8_vec(vec: Vec<u8>, length: usize) -> Bitmap
Alias for Bitmap::try_new().unwrap()
This function is O(1)
§Panic
This function panics iff length <= bytes.len() * 8
§impl Bitmap
impl Bitmap
pub unsafe fn from_trusted_len_iter_unchecked<I>(iterator: I) -> Bitmap
pub unsafe fn from_trusted_len_iter_unchecked<I>(iterator: I) -> Bitmap
pub fn from_trusted_len_iter<I>(iterator: I) -> Bitmapwhere
I: TrustedLen<Item = bool>,
pub fn from_trusted_len_iter<I>(iterator: I) -> Bitmapwhere
I: TrustedLen<Item = bool>,
Creates a new Bitmap
from an iterator of booleans.
pub fn try_from_trusted_len_iter<E, I>(iterator: I) -> Result<Bitmap, E>
pub fn try_from_trusted_len_iter<E, I>(iterator: I) -> Result<Bitmap, E>
Creates a new Bitmap
from a fallible iterator of booleans.
pub unsafe fn try_from_trusted_len_iter_unchecked<E, I>(
iterator: I
) -> Result<Bitmap, E>
pub unsafe fn try_from_trusted_len_iter_unchecked<E, I>( iterator: I ) -> Result<Bitmap, E>
pub fn from_null_buffer(value: NullBuffer) -> Bitmap
pub fn from_null_buffer(value: NullBuffer) -> Bitmap
Create a new Bitmap
from an arrow NullBuffer
Trait Implementations§
§impl<'a> BitAnd<&'a Bitmap> for MutableBitmap
impl<'a> BitAnd<&'a Bitmap> for MutableBitmap
§type Output = MutableBitmap
type Output = MutableBitmap
&
operator.§fn bitand(self, rhs: &'a Bitmap) -> MutableBitmap
fn bitand(self, rhs: &'a Bitmap) -> MutableBitmap
&
operation. Read more§impl<'a> BitAndAssign<&'a Bitmap> for &mut MutableBitmap
impl<'a> BitAndAssign<&'a Bitmap> for &mut MutableBitmap
§fn bitand_assign(&mut self, rhs: &'a Bitmap)
fn bitand_assign(&mut self, rhs: &'a Bitmap)
&=
operation. Read more§impl<'a> BitOr<&'a Bitmap> for MutableBitmap
impl<'a> BitOr<&'a Bitmap> for MutableBitmap
§type Output = MutableBitmap
type Output = MutableBitmap
|
operator.§fn bitor(self, rhs: &'a Bitmap) -> MutableBitmap
fn bitor(self, rhs: &'a Bitmap) -> MutableBitmap
|
operation. Read more§impl<'a> BitOrAssign<&'a Bitmap> for &mut MutableBitmap
impl<'a> BitOrAssign<&'a Bitmap> for &mut MutableBitmap
§fn bitor_assign(&mut self, rhs: &'a Bitmap)
fn bitor_assign(&mut self, rhs: &'a Bitmap)
|=
operation. Read more§impl<'a> BitXor<&'a Bitmap> for MutableBitmap
impl<'a> BitXor<&'a Bitmap> for MutableBitmap
§type Output = MutableBitmap
type Output = MutableBitmap
^
operator.§fn bitxor(self, rhs: &'a Bitmap) -> MutableBitmap
fn bitxor(self, rhs: &'a Bitmap) -> MutableBitmap
^
operation. Read more§impl<'a> BitXorAssign<&'a Bitmap> for &mut MutableBitmap
impl<'a> BitXorAssign<&'a Bitmap> for &mut MutableBitmap
§fn bitxor_assign(&mut self, rhs: &'a Bitmap)
fn bitxor_assign(&mut self, rhs: &'a Bitmap)
^=
operation. Read more§impl From<MutableBitmap> for Bitmap
impl From<MutableBitmap> for Bitmap
§fn from(buffer: MutableBitmap) -> Bitmap
fn from(buffer: MutableBitmap) -> Bitmap
§impl FromIterator<bool> for Bitmap
impl FromIterator<bool> for Bitmap
§impl<'a> IntoIterator for &'a Bitmap
impl<'a> IntoIterator for &'a Bitmap
§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> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request