Prunable

Struct Prunable 

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

A prunable 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> Prunable<N>

Source

pub const CHUNK_SIZE_BITS: u64 = BitMap<N>::CHUNK_SIZE_BITS

The size of a chunk in bits.

Source

pub fn new() -> Self

Create a new empty prunable bitmap.

Source

pub fn new_with_pruned_chunks(pruned_chunks: usize) -> Result<Self, Error>

Create a new empty prunable bitmap with the given number of pruned chunks.

§Errors

Returns an error if pruned_chunks violates the invariant that pruned_chunks as u64 * CHUNK_SIZE_BITS must not overflow u64.

Source

pub fn len(&self) -> u64

Return the number of bits in the bitmap, irrespective of any pruning.

Source

pub fn is_empty(&self) -> bool

Return 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 chunks_len(&self) -> usize

Return the number of unpruned chunks in the bitmap.

Source

pub fn pruned_chunks(&self) -> usize

Return the number of pruned chunks.

Source

pub fn pruned_bits(&self) -> u64

Return the number of pruned bits.

Source

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

Get the value of a bit.

§Warning

Panics if the bit doesn’t exist or has been pruned.

Source

pub fn get_chunk_containing(&self, bit: u64) -> &[u8; N]

Returns the bitmap chunk containing the specified bit.

§Warning

Panics if the bit doesn’t exist or has been pruned.

Source

pub fn get_bit_from_chunk(chunk: &[u8; N], bit: u64) -> bool

Get the value of a bit from its chunk. bit is an index into the entire bitmap, not just the chunk.

Source

pub fn last_chunk(&self) -> (&[u8; N], u64)

Return the last chunk of the bitmap and its size in bits.

Source

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

Set the value of the given bit.

§Warning

Panics if the bit doesn’t exist or has been pruned.

Source

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

Add a single bit to the end of 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 push_byte(&mut self, byte: u8)

Add a byte to the bitmap.

§Warning

Panics if self.next_bit is not byte aligned.

Source

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

Add a chunk of bits to the bitmap.

§Warning

Panics if self.next_bit is not chunk aligned.

Source

pub fn pop_chunk(&mut self) -> [u8; N]

Remove and return the last complete chunk from the bitmap.

§Warning

Panics if the bitmap has fewer than CHUNK_SIZE_BITS bits or if not chunk-aligned.

Source

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

Prune all complete chunks before the chunk containing the given bit.

The chunk containing bit and all subsequent chunks are retained. All chunks before it are pruned.

If bit equals the bitmap length, this prunes all complete chunks while retaining the empty trailing chunk, preparing the bitmap for appending new data.

§Warning

Panics if bit is greater than the bitmap length.

Source

pub fn chunk_byte_bitmask(bit: u64) -> u8

Convert a bit into a bitmask for the byte containing that bit.

Source

pub fn chunk_byte_offset(bit: u64) -> usize

Convert a bit into the index of the byte within a chunk containing the bit.

Source

pub fn pruned_chunk(&self, bit: u64) -> usize

Convert a bit into the index of the chunk it belongs to within the bitmap, taking pruned chunks into account. That is, the returned value is a valid index into the inner bitmap.

§Warning

Panics if the bit doesn’t exist or has been pruned.

Source

pub fn unpruned_chunk(bit: u64) -> usize

Convert a bit into the number of the chunk it belongs to, ignoring any pruning.

§Panics

Panics if bit / CHUNK_SIZE_BITS > usize::MAX.

Source

pub fn get_chunk(&self, chunk: usize) -> &[u8; N]

Get a reference to a chunk by its index in the current bitmap Note this is an index into the chunks, not a bit.

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Prunable<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 Prunable<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 Prunable<N>

Source§

fn default() -> Self

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

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

Source§

fn encode_size(&self) -> usize

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

impl<const N: usize> Read for Prunable<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 Prunable<N>

Source§

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

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<const N: usize> UnwindSafe for Prunable<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,