pub struct BitVec { /* private fields */ }Expand description
A simple bit vector implementation.
Implementations§
Source§impl BitVec
impl BitVec
Sourcepub fn iter(&self) -> Iter<'_> ⓘ
pub fn iter(&self) -> Iter<'_> ⓘ
Returns an iterator over the bits of the vector.
§Examples
use bitvek::bitvec;
let vec = bitvec![true, false, true, false];
let mut iter = vec.iter();
assert_eq!(iter.next(), Some(true));
assert_eq!(iter.next(), Some(false));
assert_eq!(iter.next_back(), Some(false));
assert_eq!(iter.next_back(), Some(true));
assert_eq!(iter.next(), None);
assert_eq!(iter.next_back(), None);Source§impl BitVec
impl BitVec
Source§impl BitVec
impl BitVec
Sourcepub fn shrink_to_fit(&mut self) -> &mut Self
pub fn shrink_to_fit(&mut self) -> &mut Self
Shrinks the capacity of the vector as much as possible.
§Examples
use bitvek::BitVec;
let mut vec = BitVec::with_capacity(10);
vec.extend([true, false, true]);
assert!(vec.capacity() >= 16);
vec.shrink_to_fit();
assert!(vec.capacity() >= 8);Sourcepub fn shrink_to(&mut self, min_capacity: usize) -> &mut Self
pub fn shrink_to(&mut self, min_capacity: usize) -> &mut Self
Shrinks the capacity of the vector with a lower bound.
The capacity will remain at least as large as
(self.len().max(min_capacity) / 8 + 1) * 8.
If the current capacity is less than the lower limit, this is a no-op.
§Examples
use bitvek::BitVec;
let mut vec = BitVec::with_capacity(20);
vec.extend([true, false, true]);
assert!(vec.capacity() >= 24);
vec.shrink_to(10);
assert!(vec.capacity() >= 16);
vec.shrink_to(0);
assert!(vec.capacity() >= 8);Sourcepub fn get(&self, index: usize) -> Option<bool>
pub fn get(&self, index: usize) -> Option<bool>
Returns the bit at the specified index, if in bounds.
§Examples
use bitvek::bitvec;
let vec = bitvec![true, false, true, false];
assert_eq!(vec.get(3), Some(false));
assert_eq!(vec.get(4), None);Sourcepub unsafe fn get_unchecked(&self, index: usize) -> bool
pub unsafe fn get_unchecked(&self, index: usize) -> bool
Returns the bit at the specified index, without performing any bounds checking.
§Safety
Calling this method with an out-of-bounds index is undefined behavior.
§Examples
use bitvek::bitvec;
let vec = bitvec![true, false, true, false];
unsafe { assert_eq!(vec.get_unchecked(3), false) };Sourcepub fn set(&mut self, index: usize, value: bool) -> Option<&mut Self>
pub fn set(&mut self, index: usize, value: bool) -> Option<&mut Self>
Sets the bit at the specified index to the specified value, if in bounds.
§Examples
use bitvek::bitvec;
let expected = bitvec![true, true, true, true];
let mut vec = bitvec![true, false, true, false];
assert!(vec.set(1, true).is_some());
assert!(vec.set(3, true).is_some());
assert!(vec.set(4, true).is_none());
assert_eq!(vec, expected);Sourcepub unsafe fn set_unchecked(&mut self, index: usize, value: bool) -> &mut Self
pub unsafe fn set_unchecked(&mut self, index: usize, value: bool) -> &mut Self
Sets the bit at the specified index to the specified value, without performing any bounds checking.
§Safety
Calling this method with an out-of-bounds index is undefined behavior.
§Examples
use bitvek::bitvec;
let expected = bitvec![true, true, true, true];
let mut vec = bitvec![true, false, true, false];
unsafe {
vec.set_unchecked(1, true);
vec.set_unchecked(3, true);
}
assert_eq!(vec, expected);Sourcepub fn push(&mut self, value: bool) -> Option<&mut Self>
pub fn push(&mut self, value: bool) -> Option<&mut Self>
Appends a bit to the end of the vector, or returns None if the
length of the vector reaches usize::MAX.
§Examples
use bitvek::bitvec;
let expected = bitvec![true, false, true, false, true];
let mut vec = bitvec![true, false, true, false];
assert!(vec.push(true).is_some());
assert_eq!(vec, expected);Sourcepub fn pop(&mut self) -> Option<bool>
pub fn pop(&mut self) -> Option<bool>
Removes the last bit from the vector and returns it, or None if the
vector is empty.
§Examples
use bitvek::bitvec;
let expected = bitvec![true, false, true];
let mut vec = bitvec![true, false, true, false];
assert_eq!(vec.pop(), Some(false));
assert_eq!(vec, expected);Trait Implementations§
Source§impl Extend<bool> for BitVec
impl Extend<bool> for BitVec
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = bool>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = bool>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromIterator<bool> for BitVec
impl FromIterator<bool> for BitVec
Source§impl IntoIterator for BitVec
impl IntoIterator for BitVec
impl Eq for BitVec
Auto Trait Implementations§
impl Freeze for BitVec
impl RefUnwindSafe for BitVec
impl Send for BitVec
impl Sync for BitVec
impl Unpin for BitVec
impl UnwindSafe for BitVec
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)