BatchGuard

Struct BatchGuard 

Source
pub struct BatchGuard<'a, const N: usize> { /* private fields */ }
Expand description

Guard for an active batch on a historical bitmap.

Provides mutable access to an active batch, allowing operations that modify the bitmap through a diff layer. Changes are not applied to the underlying bitmap until commit is called.

§Lifecycle

The guard must be either:

  • Committed: Call commit(commit_number) to apply changes and store a historical snapshot.
  • Dropped: Drop without committing to discard all changes.

§Examples

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

// Create a batch guard and make changes
let mut batch = bitmap.start_batch();
batch.push(true);
batch.push(false);
batch.commit(1).unwrap();

// Bitmap is now modified
assert_eq!(bitmap.len(), 2);

§Discarding Changes

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

{
    let mut batch = bitmap.start_batch();
    batch.push(true);
    // batch dropped here without commit
}

// Bitmap is unchanged
assert_eq!(bitmap.len(), 0);

Implementations§

Source§

impl<'a, const N: usize> BatchGuard<'a, N>

Source

pub fn len(&self) -> u64

Get the length of the bitmap as it would be after committing this batch.

Source

pub fn is_empty(&self) -> bool

Returns true if the bitmap would be empty after committing this batch.

Source

pub fn pruned_chunks(&self) -> usize

Get the number of pruned chunks after this batch.

Source

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

Get a bit value with read-through semantics.

Returns the bit’s value as it would be after committing this batch. Priority: appended bits > modified bits > original bitmap.

§Panics

Panics if the bit offset is out of bounds or if the bit has been pruned.

Source

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

Get a chunk value with read-through semantics.

Reconstructs the chunk if it has modifications, otherwise returns from current.

§Panics

Panics if the bit offset is out of bounds or if the chunk has been pruned.

Source

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

Set a bit value in the batch.

§Panics

Panics if the bit offset is out of bounds or if the bit has been pruned.

Source

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

Push a bit to the end of the bitmap.

Source

pub fn push_byte(&mut self, byte: u8) -> &mut Self

Push a byte to the end of the bitmap.

Source

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

Push a full chunk to the end of the bitmap.

Source

pub fn pop(&mut self) -> bool

Pop the last bit from the bitmap.

Returns the value of the popped bit, accounting for any modifications in this batch.

§Panics

Panics if the bitmap is empty.

Source

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

Prune chunks up to the chunk containing the given bit offset.

Note: bit can equal projected_len when pruning at a chunk boundary.

§Panics

Panics if bit is > the projected length of the batch.

Source

pub fn commit(self, commit_number: u64) -> Result<(), Error>

Commit the batch, applying its changes and storing a historical snapshot.

§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.

Trait Implementations§

Source§

impl<'a, const N: usize> Drop for BatchGuard<'a, N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, const N: usize> Freeze for BatchGuard<'a, N>

§

impl<'a, const N: usize> RefUnwindSafe for BatchGuard<'a, N>

§

impl<'a, const N: usize> Send for BatchGuard<'a, N>

§

impl<'a, const N: usize> Sync for BatchGuard<'a, N>

§

impl<'a, const N: usize> Unpin for BatchGuard<'a, N>

§

impl<'a, const N: usize> !UnwindSafe for BatchGuard<'a, 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> 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, 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