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 sliced = bitmap.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

Initializes an empty Bitmap.

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

Errors

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

Returns the length of the Bitmap.

Returns whether Bitmap is empty

Returns a new iterator of bool over this bitmap

Returns an iterator over bits in bit chunks BitChunk.

This iterator is useful to operate over multiple bits via e.g. bitwise.

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.

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

👎 Deprecated since 0.13.0:

use unset_bits instead

Returns the number of unset bits on this 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.

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

Safety

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

Returns whether the bit at position i is set.

Panics

Panics iff i >= self.len().

Unsafely returns whether the bit at position i is set.

Safety

Unsound iff i >= self.len().

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)

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

Initializes an new Bitmap filled with unset values.

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

Creates a new Bitmap from a slice and length.

Panic

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

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

Panic

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

Returns whether the bit at position i is set.

Creates a new Bitmap from an iterator of booleans.

Safety

The iterator must report an accurate length.

Creates a new Bitmap from an iterator of booleans.

Creates a new Bitmap from a fallible iterator of booleans.

Creates a new Bitmap from a fallible iterator of booleans.

Safety

The iterator must report an accurate length.

Trait Implementations

The resulting type after applying the & operator.

Performs the & operation. Read more

The resulting type after applying the & operator.

Performs the & operation. Read more

Performs the &= operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

Performs the |= operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

Performs the ^= operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Converts to this type from the input type.

Converts to this type from the input type.

Creates a value from an iterator. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.