Skip to main content

CleanBitMap

Type Alias CleanBitMap 

Source
pub type CleanBitMap<const N: usize> = BitMap<N, Clean>;
Expand description

Type alias for a clean bitmap with no pending mutations.

Aliased Type§

pub struct CleanBitMap<const N: usize> { /* private fields */ }

Implementations§

Source§

impl<const N: usize> CleanBitMap<N>

Source

pub const fn new() -> Self

Create a new empty historical bitmap.

Source

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

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

Source

pub fn into_dirty(self) -> DirtyBitMap<N>

Transition to dirty state to begin making mutations.

All mutations are applied to a diff layer and do not affect the current bitmap until commit.

§Examples
let bitmap: BitMap<4> = BitMap::new();

let mut dirty = bitmap.into_dirty();
dirty.push(true);
dirty.push(false);
let bitmap = dirty.commit(1).unwrap();

assert_eq!(bitmap.len(), 2);
Source

pub fn apply_batch<F>(self, commit_number: u64, f: F) -> Result<Self, Error>
where F: FnOnce(&mut DirtyBitMap<N>),

Execute a closure with a dirty bitmap and commit it at the given commit number.

§Errors

Returns Error::NonMonotonicCommit if the commit number is not greater than the previous commit.

Returns Error::ReservedCommitNumber if the commit number is u64::MAX.

§Examples
let mut bitmap: BitMap<4> = BitMap::new();

bitmap = bitmap.apply_batch(1, |dirty| {
    dirty.push(true).push(false);
}).unwrap();

assert_eq!(bitmap.len(), 2);
Source

pub fn get_at_commit(&self, commit_number: u64) -> Option<Prunable<N>>

Get the bitmap state as it existed at a specific commit.

Returns None if the commit does not exist or if commit_number is u64::MAX (which is reserved and cannot be used as a commit number).

This reconstructs the historical state by applying reverse diffs backward from the current state. Each commit’s reverse diff describes the state before that commit, so we “undo” commits one by one until we reach the target.

§Examples
let mut bitmap: BitMap<4> = BitMap::new();

bitmap = bitmap.apply_batch(1, |dirty| {
    dirty.push(true);
    dirty.push(false);
}).unwrap();

bitmap = bitmap.apply_batch(2, |dirty| {
    dirty.set_bit(0, false);
    dirty.push(true);
}).unwrap();

// Get state as it was at commit 1
let state_at_1 = bitmap.get_at_commit(1).unwrap();
assert_eq!(state_at_1.len(), 2);
assert!(state_at_1.get_bit(0));
assert!(!state_at_1.get_bit(1));

// Current state is different
assert_eq!(bitmap.len(), 3);
assert!(!bitmap.get_bit(0));
Source

pub fn commit_exists(&self, commit_number: u64) -> bool

Check if a commit exists.

Source

pub fn commits(&self) -> impl Iterator<Item = u64> + '_

Get an iterator over all commit numbers in ascending order.

Source

pub fn latest_commit(&self) -> Option<u64>

Get the latest commit number, if any commits exist.

Source

pub fn earliest_commit(&self) -> Option<u64>

Get the earliest commit number, if any commits exist.

Source

pub const fn current(&self) -> &Prunable<N>

Get a reference to the current bitmap state.

Source

pub const fn len(&self) -> u64

Number of bits in the current bitmap.

Source

pub const fn is_empty(&self) -> bool

Returns true if the current bitmap is empty.

Source

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

Get the value of a bit in the current bitmap.

Source

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

Get the chunk containing a bit in the current bitmap.

Source

pub const fn pruned_chunks(&self) -> usize

Number of pruned chunks in the current bitmap.

Source

pub fn prune_commits_before(&mut self, commit_number: u64) -> usize

Remove all commits with numbers below the commit number.

Returns the number of commits removed.

Source

pub fn clear_history(&mut self)

Clear all historical commits.

Trait Implementations§

Source§

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

Source§

fn default() -> Self

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