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 arrow2::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), "[0b___01101]".to_string());

// It supports mutation in place
bitmap.set(0, false);
assert_eq!(format!("{:?}", bitmap), "[0b___01100]".to_string());
// and `O(1)` random access
assert_eq!(bitmap.get(0), false);

Implementation

This container is internally a Vec<u8>.

Implementations

Initializes an empty MutableBitmap.

Initializes a new MutableBitmap from a Vec<u8> and a length.

Errors

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

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.

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

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

Pop the last bit from the MutableBitmap. Note if the MutableBitmap is empty, this method will return None.

Returns whether the position index is set.

Panics

Panics iff index >= self.len().

Sets the position index to value

Panics

Panics iff index >= self.len().

constructs a new iterator over the bits of MutableBitmap.

Empties the MutableBitmap.

Extends MutableBitmap by additional values of constant value.

Implementation

This function is an order of magnitude faster than pushing element by element.

Initializes a zeroed MutableBitmap.

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

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

Returns the capacity of MutableBitmap in number of bits.

Pushes a new bit to the MutableBitmap

Safety

The caller must ensure that the MutableBitmap has sufficient capacity.

Returns the number of unset bits on this MutableBitmap.

Guaranted to be <= self.len().

Implementation

This function is O(N)

👎 Deprecated since 0.13.0:

use unset_bits instead

Returns the number of unset bits on this MutableBitmap.

Returns the length of the MutableBitmap.

Returns whether MutableBitmap is empty.

Sets the position index to value

Safety

Caller must ensure that index < self.len()

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

Extends self from a TrustedLen iterator.

Extends self from an iterator of trusted len.

Safety

The caller must guarantee that the iterator has a trusted len.

Creates a new MutableBitmap from an iterator of booleans.

Safety

The iterator must report an accurate length.

Creates a new MutableBitmap from an iterator of booleans.

Creates a new MutableBitmap from an iterator of booleans.

Creates a new MutableBitmap from an falible iterator of booleans.

Safety

The caller must guarantee that the iterator is TrustedLen.

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.

Extends the MutableBitmap from a Bitmap.

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

Trait Implementations

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

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.

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.