Struct qwt::bitvector::BitVector

source ·
pub struct BitVector { /* private fields */ }

Implementations§

source§

impl BitVector

source

pub fn new() -> Self

Creates a new empty binary vector.

source

pub fn with_capacity(n_bits: usize) -> Self

Creates an empty binary vector with at least a capacity of n_bits.

source

pub fn with_zeros(n_bits: usize) -> Self

Creates a binary vector with n_bits set to 0.

source

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

Pushes a bit at the end of the binary vector.

Example
use qwt::{BitVector, AccessBin};

let mut bv = BitVector::new();
bv.push(true);
bv.push(false);
bv.push(true);
assert_eq!(bv.len(), 3);
assert_eq!(bv.get(0), Some(true));
source

pub fn append_bits(&mut self, bits: u64, len: usize)

Appends len bits at the end of the bit vector by taking the least significant len bits in the u64 value bits.

Panics

Panics if len is larger than 64 or if a bit of position
larger than len is set in bits.

Examples
use qwt::BitVector;

let mut bv = BitVector::new();
bv.append_bits(5, 3); // appends 101
bv.append_bits(6, 4); // appends 0110          
assert_eq!(bv.len(), 7);
assert_eq!(bv.get_bits(0, 3), Some(5));
source

pub fn extend_with_zeros(&mut self, n: usize)

Extends the bit vector by adding n bits set to 0.

Examples
use qwt::{BitVector, AccessBin};

let mut bv = BitVector::new();
bv.extend_with_zeros(10);
assert_eq!(bv.len(), 10);
assert_eq!(bv.get(8), Some(false));
source

pub fn set(&mut self, index: usize, bit: bool)

Sets the to bit the given position index.

Panics

Panics if index is out of bounds.

source

pub fn get_bits(&self, index: usize, len: usize) -> Option<u64>

Accesses len bits, with 1 <= len <= 64, starting at position index.

Returns None if index+len is out of bounds or len == 0 or len > 64.

source

pub fn set_bits(&mut self, index: usize, len: usize, bits: u64)

Sets len bits, with 1 <= len <= 64, starting at position index to the len least significant bits in bits.

Panics

Panics if index+len is out of bounds or len > 64 or if most significant bit in bits ia at a position larger than of equal to len.

source

pub fn ones(&self) -> BitVectorBitPositionsIter<'_, true>

Returns an iterator over positions of bit set to 1 in the bit vector.

Examples
use qwt::BitVector;
let vv: Vec<usize> = vec![0, 63, 128, 129, 254, 1026];
let bv: BitVector = vv.iter().copied().collect();

let v: Vec<usize> = bv.ones().collect();
assert_eq!(v, vv);
source

pub fn zeros(&self) -> BitVectorBitPositionsIter<'_, false>

Gives an iterator over positions of bit set to 0 in the bit vector.

source

pub fn get_word(&self, i: usize) -> u64

Gets a whole 64bit word.

source

pub fn shrink_to_fit(&mut self)

Shrinks the underlying vector of 64bit words to fit.

source

pub fn is_empty(&self) -> bool

Checks if the vector is empty.

source

pub fn len(&self) -> usize

Returns the number of bits in the bitvector.

source

pub fn iter(&self) -> BitVectorIter<'_>

Returns a non-consuming iterator over bits of the bit vector.

Trait Implementations§

source§

impl AccessBin for BitVector

source§

fn get(&self, i: usize) -> Option<bool>

Returns the bit at the given position i, or None if i is out of bounds.

Examples
use qwt::{BitVector, AccessBin};

let mut bv = BitVector::new();
bv.extend_with_zeros(10);
assert_eq!(bv.get(8), Some(false));
source§

unsafe fn get_unchecked(&self, i: usize) -> bool

Returns the symbol at position i.

Safety

Calling this method with an out-of-bounds index is undefined behavior.

source§

impl Clone for BitVector

source§

fn clone(&self) -> BitVector

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for BitVector

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for BitVector

source§

fn default() -> BitVector

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for BitVector

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Extend<bool> for BitVector

source§

fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item = bool>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<usize> for BitVector

source§

fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item = usize>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl FromIterator<bool> for BitVector

source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = bool>,

Creates a value from an iterator. Read more
source§

impl FromIterator<usize> for BitVector

source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = usize>,

Creates a value from an iterator. Read more
source§

impl<'a> IntoIterator for &'a BitVector

§

type IntoIter = BitVectorIter<'a>

Which kind of iterator are we turning this into?
§

type Item = bool

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for BitVector

§

type IntoIter = BitVectorIntoIter

Which kind of iterator are we turning this into?
§

type Item = bool

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq for BitVector

source§

fn eq(&self, other: &BitVector) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for BitVector

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl SpaceUsage for BitVector

source§

fn space_usage_byte(&self) -> usize

Returns the space usage in bytes.

source§

fn space_usage_KiB(&self) -> f64

Gives the space usage of the data structure in KiB.
source§

fn space_usage_MiB(&self) -> f64

Gives the space usage of the data structure in MiB.
source§

fn space_usage_GiB(&self) -> f64

Gives the space usage of the data structure in GiB.
source§

impl Eq for BitVector

source§

impl StructuralEq for BitVector

source§

impl StructuralPartialEq for BitVector

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

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