pub struct BitVector { /* private fields */ }Expand description
A cache-oblivious succinct bit vector.
Implementations§
Source§impl BitVector
impl BitVector
Sourcepub fn new(bits: &[u64], len: usize) -> Self
pub fn new(bits: &[u64], len: usize) -> Self
Create a new BitVector from a sequence of bits.
use sbits::BitVector;
let bits = vec![0b1011u64]; // bits 0, 1, 3 are set
let bv = BitVector::new(&bits, 64);
assert!(bv.get(0));
assert!(!bv.get(2));
assert_eq!(bv.rank1(4), 3); // three 1-bits in [0, 4)
assert_eq!(bv.select1(2), Some(3)); // third 1-bit is at position 3Sourcepub fn from_ones(positions: impl Iterator<Item = usize>, len: usize) -> Self
pub fn from_ones(positions: impl Iterator<Item = usize>, len: usize) -> Self
Create a BitVector from an iterator of set-bit positions.
use sbits::BitVector;
let bv = BitVector::from_ones([0, 1, 3, 7].into_iter(), 16);
assert_eq!(bv.rank1(4), 3);
assert_eq!(bv.select1(3), Some(7));Sourcepub fn from_parts(
storage: Vec<u64>,
select1_index: Vec<u32>,
select0_index: Vec<u32>,
len: usize,
) -> Result<Self>
pub fn from_parts( storage: Vec<u64>, select1_index: Vec<u32>, select0_index: Vec<u32>, len: usize, ) -> Result<Self>
Reconstruct a BitVector from its internal parts.
This is primarily intended for serialization round-trips.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serialize this bitvector to a stable binary encoding (little-endian).
Format (versioned):
- magic: 8 bytes (
SBITBV01) - len: u64
- storage_len: u64, then
storage_lenu64 words - select1_len: u64, then
select1_lenu32 words - select0_len: u64, then
select0_lenu32 words
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Deserialize a BitVector from to_bytes() output.
Sourcepub fn heap_bytes(&self) -> usize
pub fn heap_bytes(&self) -> usize
Heap memory usage in bytes.
Sourcepub fn select1(&self, k: usize) -> Option<usize>
pub fn select1(&self, k: usize) -> Option<usize>
Return the position of the $k$-th set bit (0-indexed).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BitVector
impl RefUnwindSafe for BitVector
impl Send for BitVector
impl Sync for BitVector
impl Unpin for BitVector
impl UnsafeUnpin for BitVector
impl UnwindSafe for BitVector
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
Mutably borrows from an owned value. Read more