pub struct BitBufferMut { /* private fields */ }Expand description
A mutable bitset buffer that allows random access to individual bits for set and get.
§Example
use vortex_buffer::BitBufferMut;
let mut bools = BitBufferMut::new_unset(10);
bools.set_to(9, true);
for i in 0..9 {
assert!(!bools.value(i));
}
assert!(bools.value(9));
// Freeze into a new bools vector.
let bools = bools.freeze();See also: BitBuffer.
Implementations§
Source§impl BitBufferMut
impl BitBufferMut
Sourcepub fn from_buffer(buffer: ByteBufferMut, offset: usize, len: usize) -> Self
pub fn from_buffer(buffer: ByteBufferMut, offset: usize, len: usize) -> Self
Create new bit buffer from given byte buffer and logical bit length
Sourcepub fn copy_from(bit_buffer: &BitBuffer) -> Self
pub fn copy_from(bit_buffer: &BitBuffer) -> Self
Creates a BitBufferMut from a BitBuffer by copying all of the data over.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new empty mutable bit buffer with requested capacity (in bits).
Sourcepub fn new_set(len: usize) -> Self
pub fn new_set(len: usize) -> Self
Create a new mutable buffer with requested len and all bits set to true.
Sourcepub fn new_unset(len: usize) -> Self
pub fn new_unset(len: usize) -> Self
Create a new mutable buffer with requested len and all bits set to false.
Sourcepub fn full(value: bool, len: usize) -> Self
pub fn full(value: bool, len: usize) -> Self
Create a new mutable buffer with requested len and all bits set to value.
Sourcepub fn inner(&self) -> &ByteBufferMut ⓘ
pub fn inner(&self) -> &ByteBufferMut ⓘ
Return the underlying byte buffer.
Sourcepub fn into_inner(self) -> ByteBufferMut ⓘ
pub fn into_inner(self) -> ByteBufferMut ⓘ
Consumes the buffer and return the underlying byte buffer.
Sourcepub unsafe fn value_unchecked(&self, index: usize) -> bool
pub unsafe fn value_unchecked(&self, index: usize) -> bool
Get the value at the requested index without bounds checking.
§Safety
The caller must ensure that index is less than the length of the buffer.
Sourcepub fn chunks(&self) -> BitChunks<'_>
pub fn chunks(&self) -> BitChunks<'_>
Access chunks of the underlying buffer as 8 byte chunks with a final trailer
If you’re performing operations on a single buffer, prefer BitBuffer::unaligned_chunks
Sourcepub fn set_to(&mut self, index: usize, value: bool)
pub fn set_to(&mut self, index: usize, value: bool)
Set the bit at index to the given boolean value.
This operation is checked so if index exceeds the buffer length, this will panic.
Sourcepub unsafe fn set_to_unchecked(&mut self, index: usize, value: bool)
pub unsafe fn set_to_unchecked(&mut self, index: usize, value: bool)
Set the bit at index to the given boolean value without checking bounds.
§Safety
The caller must ensure that index does not exceed the largest bit index in the backing buffer.
Sourcepub fn set(&mut self, index: usize)
pub fn set(&mut self, index: usize)
Set a position to true.
This operation is checked so if index exceeds the buffer length, this will panic.
Sourcepub fn unset(&mut self, index: usize)
pub fn unset(&mut self, index: usize)
Set a position to false.
This operation is checked so if index exceeds the buffer length, this will panic.
Sourcepub unsafe fn set_len(&mut self, new_len: usize)
pub unsafe fn set_len(&mut self, new_len: usize)
Foces the length of the BitBufferMut to new_len.
§Safety
new_lenmust be less than or equal tocapacity()- The elements at
old_len..new_lenmust be initialized
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Truncate the buffer to the given length.
If the given length is greater than the current length, this is a no-op.
Sourcepub fn append(&mut self, value: bool)
pub fn append(&mut self, value: bool)
Append a new boolean into the bit buffer, incrementing the length.
Sourcepub fn append_true(&mut self)
pub fn append_true(&mut self)
Append a new true value to the buffer.
Sourcepub fn append_false(&mut self)
pub fn append_false(&mut self)
Append a new false value to the buffer.
Sourcepub fn append_n(&mut self, value: bool, n: usize)
pub fn append_n(&mut self, value: bool, n: usize)
Append several boolean values into the bit buffer. After this operation,
the length will be incremented by n.
Panics if the buffer does not have n slots left.
Sourcepub fn append_buffer(&mut self, buffer: &BitBuffer)
pub fn append_buffer(&mut self, buffer: &BitBuffer)
Append a BitBuffer to this BitBufferMut
This efficiently copies all bits from the source buffer to the end of this buffer.
Sourcepub fn split_off(&mut self, at: usize) -> Self
pub fn split_off(&mut self, at: usize) -> Self
Splits the bit buffer into two at the given index.
Afterward, self contains elements [0, at), and the returned buffer contains elements
[at, capacity).
Unlike bytes, if the split position is not on a byte-boundary this operation will copy data into the result type, and mutate self.
Sourcepub fn unsplit(&mut self, other: Self)
pub fn unsplit(&mut self, other: Self)
Absorbs a mutable buffer that was previously split off.
If the two buffers were previously contiguous and not mutated in a way that causes re-allocation i.e., if other was created by calling split_off on this buffer, then this is an O(1) operation that just decreases a reference count and sets a few indices.
Otherwise, this method degenerates to self.append_buffer(&other).
Sourcepub fn freeze(self) -> BitBuffer
pub fn freeze(self) -> BitBuffer
Freeze the buffer in its current state into an immutable BoolBuffer.
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Get the underlying bytes as a mutable slice
Sourcepub fn as_mut_ptr(&mut self) -> *mut u8
pub fn as_mut_ptr(&mut self) -> *mut u8
Returns a raw mutable pointer to the internal buffer.
Sourcepub fn unaligned_chunks(&self) -> UnalignedBitChunk<'_>
pub fn unaligned_chunks(&self) -> UnalignedBitChunk<'_>
Access chunks of the buffer aligned to 8 byte boundary as [prefix, <full chunks>, suffix]
Sourcepub fn true_count(&self) -> usize
pub fn true_count(&self) -> usize
Get the number of set bits in the buffer.
Sourcepub fn false_count(&self) -> usize
pub fn false_count(&self) -> usize
Get the number of unset bits in the buffer.
Source§impl BitBufferMut
impl BitBufferMut
Sourcepub fn iter_bit_views<const NB: usize>(
&self,
) -> impl Iterator<Item = BitView<'_, NB>> + '_
pub fn iter_bit_views<const NB: usize>( &self, ) -> impl Iterator<Item = BitView<'_, NB>> + '_
Trait Implementations§
Source§impl Clone for BitBufferMut
impl Clone for BitBufferMut
Source§fn clone(&self) -> BitBufferMut
fn clone(&self) -> BitBufferMut
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BitBufferMut
impl Debug for BitBufferMut
Source§impl Default for BitBufferMut
impl Default for BitBufferMut
Source§impl From<&[bool]> for BitBufferMut
impl From<&[bool]> for BitBufferMut
Source§impl FromIterator<bool> for BitBufferMut
impl FromIterator<bool> for BitBufferMut
Source§impl Not for BitBufferMut
impl Not for BitBufferMut
Source§impl PartialEq for BitBufferMut
impl PartialEq for BitBufferMut
impl Eq for BitBufferMut
Auto Trait Implementations§
impl Freeze for BitBufferMut
impl RefUnwindSafe for BitBufferMut
impl Send for BitBufferMut
impl Sync for BitBufferMut
impl Unpin for BitBufferMut
impl UnwindSafe for BitBufferMut
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.