Struct sucds::bit_vector::BitVector
source · [−]pub struct BitVector { /* private fields */ }
Expand description
Bit vector in a plain format, supporting some utilities such as update, chunking, and predecessor queries.
This is a yet another Rust port of succinct::bit_vector.
Examples
use sucds::BitVector;
let bv = BitVector::from_bits(&[true, false, false, true]);
assert_eq!(bv.get_bit(0), true);
assert_eq!(bv.get_bit(1), false);
assert_eq!(bv.get_bit(2), false);
assert_eq!(bv.get_bit(3), true);
assert_eq!(bv.predecessor1(2), Some(0));
assert_eq!(bv.predecessor0(2), Some(2));
assert_eq!(bv.successor1(1), Some(3));
assert_eq!(bv.successor0(1), Some(1));
let mut bytes = vec![];
let size = bv.serialize_into(&mut bytes).unwrap();
let other = BitVector::deserialize_from(&bytes[..]).unwrap();
assert_eq!(bv, other);
assert_eq!(size, bytes.len());
assert_eq!(size, bv.size_in_bytes());
Implementations
Creates a new BitVector
that capa
bits are reserved.
Serializes the data structure into the writer, returning the number of serialized bytes.
Arguments
writer
:std::io::Write
variable.
Returns the number of bytes to serialize the data structure.
Creates a new BitVector
from input bitset bits
.
Arguments
bits
: List of bits.
Examples
use sucds::BitVector;
let bv = BitVector::from_bits(&[true, false, false, true]);
assert_eq!(bv.get_bit(0), true);
assert_eq!(bv.get_bit(1), false);
assert_eq!(bv.get_bit(2), false);
assert_eq!(bv.get_bit(3), true);
Sets the pos
-th bit to bit
.
Arguments
pos
: Bit position.bit
: Set bit.
Examples
use sucds::BitVector;
let mut bv = BitVector::from_bits(&[false, true, true, false]);
bv.set_bit(0, true);
bv.set_bit(2, false);
assert_eq!(bv.get_bit(0), true);
assert_eq!(bv.get_bit(1), true);
assert_eq!(bv.get_bit(2), false);
assert_eq!(bv.get_bit(3), false);
Gets the largest bit position pred
such that pred <= pos
and the pred
-th bit is set.
If not found, None
is returned.
Arguments
pos
: Bit position.
Examples
use sucds::BitVector;
let bv = BitVector::from_bits(&[false, true, false, true]);
assert_eq!(bv.predecessor1(3), Some(3));
assert_eq!(bv.predecessor1(2), Some(1));
assert_eq!(bv.predecessor1(1), Some(1));
assert_eq!(bv.predecessor1(0), None);
Gets the smallest bit position succ
such that succ >= pos
and the succ
-th bit is set.
If not found, None
is returned.
Arguments
pos
: Bit position.
Examples
use sucds::BitVector;
let bv = BitVector::from_bits(&[true, false, true, false]);
assert_eq!(bv.successor1(0), Some(0));
assert_eq!(bv.successor1(1), Some(2));
assert_eq!(bv.successor1(2), Some(2));
assert_eq!(bv.successor1(3), None);
Gets the largest bit position pred
such that pred <= pos
and the pred
-th bit is not set.
If not found, None
is returned.
Arguments
pos
: Bit position.
Examples
use sucds::BitVector;
let bv = BitVector::from_bits(&[true, false, true, false]);
assert_eq!(bv.predecessor0(3), Some(3));
assert_eq!(bv.predecessor0(2), Some(1));
assert_eq!(bv.predecessor0(1), Some(1));
assert_eq!(bv.predecessor0(0), None);
Gets the smallest bit position succ
such that succ >= pos
and the succ
-th bit is not set.
If not found, None
is returned.
Arguments
pos
: Bit position.
Examples
use sucds::BitVector;
let bv = BitVector::from_bits(&[false, true, false, true]);
assert_eq!(bv.successor0(0), Some(0));
assert_eq!(bv.successor0(1), Some(2));
assert_eq!(bv.successor0(2), Some(2));
assert_eq!(bv.successor0(3), None);
pub fn unary_iter(&self, pos: usize) -> UnaryIterator<'_>ⓘNotable traits for UnaryIterator<'a>impl<'a> Iterator for UnaryIterator<'a> type Item = usize;
pub fn unary_iter(&self, pos: usize) -> UnaryIterator<'_>ⓘNotable traits for UnaryIterator<'a>impl<'a> Iterator for UnaryIterator<'a> type Item = usize;
impl<'a> Iterator for UnaryIterator<'a> type Item = usize;
Creates an iterator for enumerating positions of set bits.
Examples
use sucds::BitVector;
let bv = BitVector::from_bits(&[false, true, false, false, true]);
let mut it = bv.unary_iter(1);
assert_eq!(it.next(), Some(1));
assert_eq!(it.next(), Some(4));
assert_eq!(it.next(), None);
Gets get_bits(pos, 64)
but it can extend further len()
, padding with zeros.
Shrinks the capacity of the vector as much as possible.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for BitVector
impl UnwindSafe for BitVector
Blanket Implementations
Mutably borrows from an owned value. Read more