BitMap

Struct BitMap 

Source
pub struct BitMap<const N: usize = DEFAULT_CHUNK_SIZE> { /* private fields */ }
Expand description

A bitmap that stores data in chunks of N bytes.

§Panics

Operations panic if bit / CHUNK_SIZE_BITS > usize::MAX. On 32-bit systems with N=32, this occurs at bit >= 1,099,511,627,776.

Implementations§

Source§

impl<const N: usize> BitMap<N>

Source

pub const CHUNK_SIZE_BITS: u64

The size of a chunk in bits.

Source

pub fn new() -> Self

Create a new empty bitmap.

Source

pub fn with_capacity(size: u64) -> Self

Source

pub fn zeroes(size: u64) -> Self

Create a new bitmap with size bits, with all bits set to 0.

Source

pub fn ones(size: u64) -> Self

Create a new bitmap with size bits, with all bits set to 1.

Source

pub fn len(&self) -> u64

Return the number of bits currently stored in the bitmap.

Source

pub fn is_empty(&self) -> bool

Returns true if the bitmap is empty.

Source

pub fn is_chunk_aligned(&self) -> bool

Returns true if the bitmap length is aligned to a chunk boundary.

Source

pub fn get(&self, bit: u64) -> bool

Get the value of the bit at the given index.

§Warning

Panics if the bit doesn’t exist.

Source

pub fn push(&mut self, bit: bool)

Add a single bit to the bitmap.

Source

pub fn pop(&mut self) -> bool

Remove and return the last bit from the bitmap.

§Warning

Panics if the bitmap is empty.

Source

pub fn flip(&mut self, bit: u64)

Flips the given bit.

§Panics

Panics if bit is out of bounds.

Source

pub fn flip_all(&mut self)

Flips all bits (1s become 0s and vice versa).

Source

pub fn set(&mut self, bit: u64, value: bool)

Set the value of the referenced bit.

§Warning

Panics if the bit doesn’t exist.

Source

pub fn set_all(&mut self, bit: bool)

Sets all bits to the specified value.

Source

pub fn push_chunk(&mut self, chunk: &[u8; N])

Add a chunk of bits to the bitmap.

§Warning

Panics if self.len is not chunk aligned.

Source

pub fn count_ones(&self) -> u64

Returns the number of bits set to 1.

Source

pub fn count_zeros(&self) -> u64

Returns the number of bits set to 0.

Source

pub fn iter(&self) -> Iterator<'_, N>

Creates an iterator over the bits.

Source

pub fn and(&mut self, other: &BitMap<N>)

Performs a bitwise AND with another BitMap.

§Panics

Panics if the lengths don’t match.

Source

pub fn or(&mut self, other: &BitMap<N>)

Performs a bitwise OR with another BitMap.

§Panics

Panics if the lengths don’t match.

Source

pub fn xor(&mut self, other: &BitMap<N>)

Performs a bitwise XOR with another BitMap.

§Panics

Panics if the lengths don’t match.

Trait Implementations§

Source§

impl<const N: usize> BitAnd for &BitMap<N>

Source§

type Output = BitMap<N>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<const N: usize> BitOr for &BitMap<N>

Source§

type Output = BitMap<N>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<const N: usize> BitXor for &BitMap<N>

Source§

type Output = BitMap<N>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<const N: usize> Clone for BitMap<N>

Source§

fn clone(&self) -> BitMap<N>

Returns a duplicate 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<const N: usize> Debug for BitMap<N>

Source§

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

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

impl<const N: usize> Default for BitMap<N>

Source§

fn default() -> Self

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

impl<const N: usize> EncodeSize for BitMap<N>

Source§

fn encode_size(&self) -> usize

Returns the encoded size of this value (in bytes).
Source§

impl<const N: usize> From<BitMap<N>> for Vec<bool>

Source§

fn from(bv: BitMap<N>) -> Self

Converts to this type from the input type.
Source§

impl<T: AsRef<[bool]>, const N: usize> From<T> for BitMap<N>

Source§

fn from(t: T) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> Hash for BitMap<N>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const N: usize> Index<u64> for BitMap<N>

Source§

fn index(&self, bit: u64) -> &Self::Output

Allows accessing bits using the [] operator.

Panics if out of bounds.

Source§

type Output = bool

The returned type after indexing.
Source§

impl<const N: usize> PartialEq for BitMap<N>

Source§

fn eq(&self, other: &BitMap<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> Read for BitMap<N>

Source§

type Cfg = u64

The Cfg type parameter allows passing configuration during the read process. This is crucial for safely decoding untrusted data, for example, by providing size limits for collections or strings. Read more
Source§

fn read_cfg(buf: &mut impl Buf, max_len: &Self::Cfg) -> Result<Self, CodecError>

Reads a value from the buffer using the provided configuration cfg. Read more
Source§

impl<const N: usize> Write for BitMap<N>

Source§

fn write(&self, buf: &mut impl BufMut)

Writes the binary representation of self to the provided buffer buf. Read more
Source§

impl<const N: usize> Eq for BitMap<N>

Source§

impl<const N: usize> StructuralPartialEq for BitMap<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for BitMap<N>

§

impl<const N: usize> RefUnwindSafe for BitMap<N>

§

impl<const N: usize> Send for BitMap<N>

§

impl<const N: usize> Sync for BitMap<N>

§

impl<const N: usize> Unpin for BitMap<N>

§

impl<const N: usize> UnwindSafe for BitMap<N>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Decode for T
where T: Read,

Source§

fn decode_cfg(buf: impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Decodes a value from buf using cfg, ensuring the entire buffer is consumed. Read more
Source§

impl<T> Encode for T
where T: Write + EncodeSize,

Source§

fn encode(&self) -> BytesMut

Encodes self into a new BytesMut buffer. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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<T> ToOwned for T
where T: Clone,

Source§

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

Source§

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

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Codec for T
where T: Encode + Decode,