[][src]Struct indexed_bitvec::IndexedBits

pub struct IndexedBits<T: Deref<Target = [u8]>> { /* fields omitted */ }

Bits stored with extra index data for fast rank and select.

Methods

impl<T: Deref<Target = [u8]>> IndexedBits<T>
[src]

pub fn build_from_bits(bits: Bits<T>) -> Self
[src]

Build the index for a sequence of bits.

This is an expensive operation which will examine all of the data input.

pub fn build_from_bytes(bytes: T, len: u64) -> Option<Self>
[src]

Build an indexed bitvector from some bytes.

This is the same as using Bits::from_bytes and IndexedBits::build_from_bits

pub fn bits(&self) -> Bits<&[u8]>
[src]

pub fn decompose(self) -> Bits<T>
[src]

Discard the index and get the original bit sequence storage back.

pub fn len(&self) -> u64
[src]

The number of bits in the storage.

pub fn get(&self, idx_bits: u64) -> Option<bool>
[src]

Get the byte at a specific index.

Returns None for out-of-bounds.

use indexed_bitvec::IndexedBits;
let bits = IndexedBits::build_from_bytes(vec![0xFE, 0xFE], 15).unwrap();
assert_eq!(bits.get(0), Some(true));
assert_eq!(bits.get(7), Some(false));
assert_eq!(bits.get(14), Some(true));
assert_eq!(bits.get(15), None);

pub fn count_ones(&self) -> u64
[src]

Count the set bits (fast O(1)).

use indexed_bitvec::IndexedBits;
let bits = IndexedBits::build_from_bytes(vec![0xFE, 0xFE], 15).unwrap();
assert_eq!(bits.count_ones(), 14);
assert_eq!(bits.count_zeros(), 1);
assert_eq!(bits.count_ones() + bits.count_zeros(), bits.len());

pub fn count_zeros(&self) -> u64
[src]

Count the unset bits (fast O(1)).

use indexed_bitvec::IndexedBits;
let bits = IndexedBits::build_from_bytes(vec![0xFE, 0xFE], 15).unwrap();
assert_eq!(bits.count_ones(), 14);
assert_eq!(bits.count_zeros(), 1);
assert_eq!(bits.count_ones() + bits.count_zeros(), bits.len());

pub fn rank_ones(&self, idx: u64) -> Option<u64>
[src]

Count the set bits before a position in the bits (O(1)).

Returns None it the index is out of bounds.

use indexed_bitvec::IndexedBits;
let bits = IndexedBits::build_from_bytes(vec![0xFE, 0xFE], 15).unwrap();
assert!((0..bits.len()).all(|idx|
    bits.rank_ones(idx).unwrap()
    + bits.rank_zeros(idx).unwrap()
    == (idx as u64)));
assert_eq!(bits.rank_ones(7), Some(7));
assert_eq!(bits.rank_zeros(7), Some(0));
assert_eq!(bits.rank_ones(8), Some(7));
assert_eq!(bits.rank_zeros(8), Some(1));
assert_eq!(bits.rank_ones(9), Some(8));
assert_eq!(bits.rank_zeros(9), Some(1));
assert_eq!(bits.rank_ones(15), None);

pub fn rank_zeros(&self, idx: u64) -> Option<u64>
[src]

Count the unset bits before a position in the bits (O(1)).

Returns None it the index is out of bounds.

use indexed_bitvec::IndexedBits;
let bits = IndexedBits::build_from_bytes(vec![0xFE, 0xFE], 15).unwrap();
assert!((0..bits.len()).all(|idx|
    bits.rank_ones(idx).unwrap()
    + bits.rank_zeros(idx).unwrap()
    == (idx as u64)));
assert_eq!(bits.rank_ones(7), Some(7));
assert_eq!(bits.rank_zeros(7), Some(0));
assert_eq!(bits.rank_ones(8), Some(7));
assert_eq!(bits.rank_zeros(8), Some(1));
assert_eq!(bits.rank_ones(9), Some(8));
assert_eq!(bits.rank_zeros(9), Some(1));
assert_eq!(bits.rank_ones(15), None);

pub fn select_ones(&self, target_rank: u64) -> Option<u64>
[src]

Find the position of a set bit by its rank (O(log n)).

Returns None if no suitable bit is found. It is always the case otherwise that rank_ones(result) == Some(target_rank) and get(result) == Some(true).

use indexed_bitvec::IndexedBits;
let bits = IndexedBits::build_from_bytes(vec![0xFE, 0xFE], 15).unwrap();
assert_eq!(bits.select_ones(6), Some(6));
assert_eq!(bits.select_ones(7), Some(8));
assert_eq!(bits.select_zeros(0), Some(7));
assert_eq!(bits.select_zeros(1), None);

pub fn select_zeros(&self, target_rank: u64) -> Option<u64>
[src]

Find the position of an unset bit by its rank (O(log n)).

Returns None if no suitable bit is found. It is always the case otherwise that rank_zeros(result) == Some(target_rank) and get(result) == Some(false).

use indexed_bitvec::IndexedBits;
let bits = IndexedBits::build_from_bytes(vec![0xFE, 0xFE], 15).unwrap();
assert_eq!(bits.select_ones(6), Some(6));
assert_eq!(bits.select_ones(7), Some(8));
assert_eq!(bits.select_zeros(0), Some(7));
assert_eq!(bits.select_zeros(1), None);

Trait Implementations

impl<T: Clone + Deref<Target = [u8]>> Clone for IndexedBits<T>
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Debug + Deref<Target = [u8]>> Debug for IndexedBits<T>
[src]

impl<T: Deref<Target = [u8]>> Serialize for IndexedBits<T> where
    T: Serialize
[src]

impl<'de, T: Deref<Target = [u8]>> Deserialize<'de> for IndexedBits<T> where
    T: Deserialize<'de>, 
[src]

Auto Trait Implementations

impl<T> Send for IndexedBits<T> where
    T: Send

impl<T> Sync for IndexedBits<T> where
    T: Sync

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]