[][src]Struct indexed_bitvec::bits::Bits

pub struct Bits<T: Deref<Target = [u8]>>(_);

A bitvector stored as a sequence of bytes (most significant bit first).

Methods

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

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

pub fn all_bytes(&self) -> &[u8]
[src]

All of the bytes stored in the byte sequence: not just the ones actually used.

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

The number of bits in the storage.

pub fn bytes(&self) -> &[u8]
[src]

The used bytes of the byte sequence: bear in mind some of the bits in the last byte may be unused.

pub fn decompose(self) -> (T, u64)
[src]

Deconstruct the bits storage to get back what it was constructed from.

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::Bits;
let bits = Bits::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 (O(n)).

use indexed_bitvec::Bits;
let bits = Bits::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 (O(n)).

use indexed_bitvec::Bits;
let bits = Bits::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(n)).

Returns None it the index is out of bounds.

use indexed_bitvec::Bits;
let bits = Bits::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(n)).

Returns None it the index is out of bounds.

use indexed_bitvec::Bits;
let bits = Bits::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(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::Bits;
let bits = Bits::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(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::Bits;
let bits = Bits::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 clone_ref(&self) -> Bits<&[u8]>
[src]

Create a reference to these same bits.

impl<T: DerefMut<Target = [u8]>> Bits<T>
[src]

pub fn all_bytes_mut(&mut self) -> &mut [u8]
[src]

pub fn set(&mut self, idx_bits: u64, to: bool) -> Result<(), &'static str>
[src]

Set the byte at a specific index.

Returns an error if the index is out of bounds.

use indexed_bitvec::Bits;
let mut bits = Bits::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);
assert!(bits.set(0, false).is_ok());
assert_eq!(bits.get(0), Some(false));
assert!(bits.set(0, true).is_ok());
assert_eq!(bits.get(0), Some(true));
assert!(bits.set(7, false).is_ok());
assert_eq!(bits.get(7), Some(false));
assert!(bits.set(14, false).is_ok());
assert_eq!(bits.get(14), Some(false));
assert!(bits.set(15, false).is_err());

impl Bits<Vec<u8>>
[src]

pub fn push(&mut self, bit: bool)
[src]

Add a specific bit to the end of the vector.

This will enlarge the used section of bits (corresponding to Bits::len) and overwrite any content already in the newly used storage.

use indexed_bitvec::Bits;
let mut bits = Bits::from_bytes(vec![0x80], 0).unwrap();
assert_eq!(0x80, bits.all_bytes()[0]);
assert_eq!(None, bits.get(0));
bits.push(false);
assert_eq!(0x00, bits.all_bytes()[0]);
assert_eq!(Some(false), bits.get(0));
bits.push(true);
assert_eq!(0x40, bits.all_bytes()[0]);
assert_eq!(Some(true), bits.get(1));
for _ in 0..6 { bits.push(false) };
assert_eq!(0x40, bits.all_bytes()[0]);
assert_eq!(1, bits.all_bytes().len());
bits.push(true);
assert_eq!(2, bits.all_bytes().len());
assert_eq!(0x80, bits.all_bytes()[1]);
assert_eq!(Some(true), bits.get(8));

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

Important traits for BitIterator<T>
pub fn iter(&self) -> BitIterator<&[u8]>
[src]

Important traits for OneBitIndexIterator<T>
pub fn into_iter_one_bits(self) -> OneBitIndexIterator<T>
[src]

Important traits for OneBitIndexIterator<T>
pub fn iter_one_bits(&self) -> OneBitIndexIterator<&[u8]>
[src]

Important traits for ZeroBitIndexIterator<T>
pub fn into_iter_zero_bits(self) -> ZeroBitIndexIterator<T>
[src]

Important traits for ZeroBitIndexIterator<T>
pub fn iter_zero_bits(&self) -> ZeroBitIndexIterator<&[u8]>
[src]

Trait Implementations

impl<'a, T: Deref<Target = [u8]>> From<&'a Bits<T>> for BitsRef<'a>
[src]

impl<'a> From<Bits<&'a [u8]>> for BitsRef<'a>
[src]

impl<'a> From<BitsRef<'a>> for Bits<&'a [u8]>
[src]

impl<T: Deref<Target = [u8]>> IntoIterator for Bits<T>
[src]

type Item = bool

The type of the elements being iterated over.

type IntoIter = BitIterator<T>

Which kind of iterator are we turning this into?

impl<T: Deref<Target = [u8]>> Eq for Bits<T>
[src]

impl<T: Deref<Target = [u8]>> PartialOrd<Bits<T>> for Bits<T>
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T: Copy + Deref<Target = [u8]>> Copy for Bits<T>
[src]

impl<T: Deref<Target = [u8]>> PartialEq<Bits<T>> for Bits<T>
[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

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

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

Performs copy-assignment from source. Read more

impl<T: Deref<Target = [u8]>> Ord for Bits<T>
[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

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

impl<T: Serialize + Deref<Target = [u8]>> Serialize for Bits<T>
[src]

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

Auto Trait Implementations

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

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

Blanket Implementations

impl<T> From for T
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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]