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>
impl<const N: usize> Prunable<N>
Sourcepub const CHUNK_SIZE_BITS: u64 = BitMap<N>::CHUNK_SIZE_BITS
pub const CHUNK_SIZE_BITS: u64 = BitMap<N>::CHUNK_SIZE_BITS
The size of a chunk in bits.
Sourcepub fn new_with_pruned_chunks(pruned_chunks: usize) -> Result<Self, Error>
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.
Sourcepub fn is_chunk_aligned(&self) -> bool
pub fn is_chunk_aligned(&self) -> bool
Returns true if the bitmap length is aligned to a chunk boundary.
Sourcepub fn chunks_len(&self) -> usize
pub fn chunks_len(&self) -> usize
Return the number of unpruned chunks in the bitmap.
Sourcepub fn pruned_chunks(&self) -> usize
pub fn pruned_chunks(&self) -> usize
Return the number of pruned chunks.
Sourcepub fn pruned_bits(&self) -> u64
pub fn pruned_bits(&self) -> u64
Return the number of pruned bits.
Sourcepub fn get_chunk_containing(&self, bit: u64) -> &[u8; N]
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.
Sourcepub fn get_bit_from_chunk(chunk: &[u8; N], bit: u64) -> bool
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.
Sourcepub fn last_chunk(&self) -> (&[u8; N], u64)
pub fn last_chunk(&self) -> (&[u8; N], u64)
Return the last chunk of the bitmap and its size in bits.
Sourcepub fn push_chunk(&mut self, chunk: &[u8; N])
pub fn push_chunk(&mut self, chunk: &[u8; N])
Sourcepub fn pop_chunk(&mut self) -> [u8; N]
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.
Sourcepub fn prune_to_bit(&mut self, bit: u64)
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.
Sourcepub fn chunk_byte_bitmask(bit: u64) -> u8
pub fn chunk_byte_bitmask(bit: u64) -> u8
Convert a bit into a bitmask for the byte containing that bit.
Sourcepub fn chunk_byte_offset(bit: u64) -> usize
pub fn chunk_byte_offset(bit: u64) -> usize
Convert a bit into the index of the byte within a chunk containing the bit.
Sourcepub fn pruned_chunk(&self, bit: u64) -> usize
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.
Sourcepub fn unpruned_chunk(bit: u64) -> usize
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.