[][src]Struct m4ri_rust::friendly::BinVector

pub struct BinVector { /* fields omitted */ }

Wrapper around BitVec

Methods

impl BinVector[src]

pub fn new() -> Self[src]

pub fn from(vec: Vob) -> Self[src]

pub fn from_elem(len: usize, elem: bool) -> Self[src]

pub fn from_bools(bools: &[bool]) -> BinVector[src]

pub fn from_function(len: usize, f: fn(_: usize) -> bool) -> BinVector[src]

Construct the BinVector from the result of a function

Example

let v = BinVector::from_function(4, |i| i % 2 == 0);
assert_eq!(v.get(0), Some(true));
assert_eq!(v.get(1), Some(false));

pub fn random(len: usize) -> BinVector[src]

pub fn with_capacity(len: usize) -> Self[src]

pub fn from_bytes(bytes: &[u8]) -> BinVector[src]

Create a new BinVector from an &[u8].

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

pub fn extend_from_binvec(&mut self, other: &BinVector)[src]

pub fn into_vob(self) -> Vob[src]

pub fn to_vob(self) -> Vob[src]

Deprecated since 0.3.3:

use into_vob instead

pub fn as_matrix(&self) -> BinMatrix[src]

pub fn as_column_matrix(&self) -> BinMatrix[src]

pub fn as_u32(&self) -> u32[src]

Get an u32 in the order as it's stored

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

Get an u64 in the order as it's stored

Methods from Deref<Target = Vob>

pub fn capacity(&self) -> usize[src]

Returns the number of bits the Vob can hold without reallocating.

Examples

use vob::Vob;
assert_eq!(Vob::new().capacity(), 0);
assert!(Vob::with_capacity(1).capacity() >= 1);

pub fn reserve(&mut self, additional: usize)[src]

Reserves capacity for at least additional more bits to be inserted in the Vob. The Vob may reserve more space to avoid frequent reallocations. After calling reserve, capacity will be greater than or equal to self.len() + additional. Does nothing if capacity is already sufficient.

Examples

use vob::Vob;
let mut v = Vob::new();
v.reserve(1);
assert!(v.capacity() >= 1);

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of the vector as much as possible.

It will drop down as close as possible to the length but the allocator may still inform the vector that there is space for a few more elements.

pub fn truncate(&mut self, len: usize)[src]

Shortens the Vob, keeping the first len elements and dropping the rest.

If len is greater than the vector's current length, this has no effect.

The drain method can emulate truncate, but causes the excess elements to be returned instead of dropped.

Note that this method has no effect on the allocated capacity of the vector.

Examples

use vob::vob;
fn main() {
    let mut v = vob![true, false, true];
    v.truncate(2);
    assert_eq!(v, vob![true, false]);
}

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

Appends a bool to the back of the Vob.

Examples

use vob::Vob;
let mut v = Vob::new();
v.push(true);
v.push(false);
assert_eq!(v.get(0), Some(true));
assert_eq!(v.get(1), Some(false));

pub fn pop(&mut self) -> Option<bool>[src]

Removes the last element from the Vob and returns it, or None if it is empty.

Examples

use vob::Vob;
let mut v = Vob::new();
v.push(true);
assert_eq!(v.pop(), Some(true));
assert_eq!(v.pop(), None);

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

Returns the number of elements in the Vob.

pub fn is_empty(&self) -> bool[src]

Returns true if the Vob has a length of 0.

Examples

use vob::Vob;
assert_eq!(Vob::from_elem(2, true).is_empty(), false);
assert_eq!(Vob::new().is_empty(), true);

pub fn split_off(&mut self, at: usize) -> Vob<T>[src]

Splits the collection into two at the given index.

Returns a newly allocated Self. self contains elements [0, at), and the returned Self contains elements [at, len).

Note that the capacity of self does not change.

Examples

use vob::Vob;
let mut v1 = Vob::new();
v1.push(true);
v1.push(false);
let v2 = v1.split_off(1);
assert_eq!(v1, Vob::from_elem(1, true));
assert_eq!(v2, Vob::from_elem(1, false));

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

Returns the value of the element at position index or None if out of bounds.

Examples

use vob::Vob;
let mut v = Vob::new();
v.push(false);
assert_eq!(v.get(0), Some(false));
assert_eq!(v.get(1), None);

pub fn set(&mut self, index: usize, value: bool) -> bool[src]

Sets the value of the element at position index. Returns true if this led to a change in the underlying storage or false otherwise.

Examples

use vob::Vob;
let mut v = Vob::new();
v.push(false);
v.set(0, true);
assert_eq!(v.get(0), Some(true));
assert_eq!(v.set(0, false), true);
assert_eq!(v.set(0, false), false);

Panics

If index is out of bounds.

pub fn iter(&self) -> Iter<T>[src]

Returns an iterator over the slice.

Examples

use vob::Vob;
let mut v = Vob::new();
v.push(false);
v.push(true);
let mut iterator = v.iter();
assert_eq!(iterator.next(), Some(false));
assert_eq!(iterator.next(), Some(true));
assert_eq!(iterator.next(), None);

pub fn iter_set_bits<R>(&self, range: R) -> IterSetBits<T> where
    R: RangeBounds<usize>, 
[src]

Returns an iterator which efficiently produces the index of each set bit in the specified range. Assuming appropriate support from your CPU, this is much more efficient than checking each bit individually.

Examples

use vob::Vob;
let mut v = Vob::new();
v.push(false);
v.push(true);
let mut iterator = v.iter_set_bits(..);
assert_eq!(iterator.next(), Some(1));
assert_eq!(iterator.next(), None);

pub fn iter_unset_bits<R>(&self, range: R) -> IterUnsetBits<T> where
    R: RangeBounds<usize>, 
[src]

Returns an iterator which efficiently produces the index of each unset bit in the specified range. Assuming appropriate support from your CPU, this is much more efficient than checking each bit individually.

Examples

use vob::Vob;
let mut v = Vob::new();
v.push(false);
v.push(true);
let mut iterator = v.iter_unset_bits(..);
assert_eq!(iterator.next(), Some(0));
assert_eq!(iterator.next(), None);

pub fn iter_storage(&self) -> StorageIter<T>[src]

Return an iterator over the underlying storage blocks. The last block is guaranteed to have "unused" bits (i.e. those past self.len()) set to 0.

Examples

use vob::Vob;
let v1 = Vob::from_elem(10, true);
assert_eq!(v1.iter_storage().next(), Some((1 << 10) - 1));
let v2 = Vob::from_elem(129, true);
assert_eq!(v2.iter_storage().last(), Some(1));

pub fn resize(&mut self, new_len: usize, value: bool)[src]

Resizes the Vob in-place so that len is equal to new_len.

If new_len is greater than len, the Vob is extended by the difference, with each additional slot filled with value. If new_len is less than len, the vob is simply truncated.

Examples

use vob::Vob;
let mut v = Vob::new();
v.push(false);
v.resize(129, true);
assert_eq!(v.len(), 129);
assert_eq!(v.get(0), Some(false));
assert_eq!(v.get(128), Some(true));

pub fn extend_from_slice(&mut self, other: &[bool])[src]

Appends all elements in a slice to the Vob.

Iterates over the slice other and appends elements in order.

Note that this function is same as extend except that it is specialized to work with slices instead. If and when Rust gets specialization this function will likely be deprecated (but still available).

Examples

use vob::vob;
fn main() {
    let mut v = vob![true];
    v.extend_from_slice(&vec![false, true]);
    assert_eq!(v, vob![true, false, true]);
}

pub fn extend_from_vob(&mut self, other: &Vob<T>)[src]

Append all elements from a second Vob to this Vob.

Use this instead of extend() when extending with a Vob, because this method is a lot faster.

Examples

use vob::vob;
fn main() {
    let mut v1 = vob![true];
    let v2 = vob![false, false];
    v1.extend_from_vob(&v2);
    assert_eq!(v1, vob![true, false, false]);
}

pub fn clear(&mut self)[src]

Clears the Vob, removing all values.

Note that this method has no effect on the allocated capacity of the Vob.

pub fn set_all(&mut self, value: bool)[src]

Sets all bits in the Vob to value. Notice that this does not change the number of bits stored in the Vob.

Examples

use vob::vob;
fn main() {
    let mut v = vob![true, false, true];
    v.set_all(false);
    assert_eq!(v, vob![false, false, false]);
}

pub fn negate(&mut self)[src]

Negates all bits in the Vob.

Examples

use vob::vob;
fn main() {
    let mut v = vob![true, false];
    v.negate();
    assert_eq!(v, vob![false, true]);
}

pub fn and(&mut self, other: &Vob<T>) -> bool[src]

For each bit in this Vob, and it with the corresponding bit in other, returning true if this led to any changes or false otherwise. The two Vobs must have the same number of bits.

Panics

If the two Vobs are of different length.

Examples

use vob::vob;
fn main() {
    let mut v1 = vob![true, false, false];
    let v2 = vob![true, true, false];
    assert_eq!(v1.and(&v2), false);
    assert_eq!(v1, vob![true, false, false]);
}

pub fn or(&mut self, other: &Vob<T>) -> bool[src]

For each bit in this Vob, or it with the corresponding bit in other, returning true if this led to any changes or false otherwise. The two Vobs must have the same number of bits.

Panics

If the two Vobs are of different length.

Examples

use vob::vob;
fn main() {
    let mut v1 = vob![true, false, false];
    let v2 = vob![false, true, false];
    assert_eq!(v1.or(&v2), true);
    assert_eq!(v1, vob![true, true, false]);
}

pub fn xor(&mut self, other: &Vob<T>) -> bool[src]

For each bit in this Vob, xor it with the corresponding bit in other, returning true if this led to any changes or false otherwise. The two Vobs must have the same number of bits.

Panics

If the two Vobs are of different length.

Examples

use vob::vob;
fn main() {
    let mut v1 = vob![true, false, true];
    let v2 = vob![false, true, true];
    assert_eq!(v1.xor(&v2), true);
    assert_eq!(v1, vob![true, true, false]);
}

pub fn mask_last_block(&mut self)[src]

We guarantee that the last storage block has no bits set past the "last" bit: this function clears any such bits.

This otherwise private function is exposed when unsafe_internals is enabled, to help callers maintain the internal assumptions.

pub unsafe fn get_storage_mut(&mut self) -> &mut Vec<T>[src]

Get a mutable reference to the underlying data structure

This is marked as unsafe as it allows to invalidate the assumptions made by this module. It is not in itself unsafe.

Assumptions:

  • Vob stores the bits in a little-endian order.
  • The length can't change, or should be updated using Vob::set_len().
  • Any bits past self.len() should be set to 0 in the last block. Vob::mask_last_block() can help you with that.
  • storage.len() may not be larger than ceil(self.len() / (8 * size_of::<T>))

Examples

use vob::vob;
fn main() {
    let mut v1 = vob![true, false, true];
    let storage = unsafe { v1.get_storage_mut() };
    assert_eq!(storage[0], 0b101);
}

pub unsafe fn set_len(&mut self, len: usize)[src]

Set the length of the Vob.

This will explicitly set the length of the Vob, without actually modifying the underlying data structure or doing any checks.

If you want to shorten your Vob, you're probably looking for truncate.

See Vob::get_storage_mut() for the other requirements.

Examples

use vob::Vob;
fn main() {
    let mut v1 = Vob::<u8>::new_with_storage_type(9);
    v1.push(true);
    v1.push(false);
    {
        let mut storage = unsafe { v1.get_storage_mut() };
        storage.push(0b1);
    }
    unsafe { v1.set_len(9); }
    assert_eq!(v1[0], true);
    assert_eq!(v1[1], false);
    assert_eq!(v1[2], false);
    assert_eq!(v1[8], true);
}

Trait Implementations

impl From<Vob<usize>> for BinVector[src]

impl PartialEq<BinVector> for BinVector[src]

impl Default for BinVector[src]

impl Clone for BinVector[src]

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

Performs copy-assignment from source. Read more

impl Eq for BinVector[src]

impl DerefMut for BinVector[src]

impl Deref for BinVector[src]

type Target = Vob

The resulting type after dereferencing.

impl Debug for BinVector[src]

impl<'a> Add<&'a BinVector> for &'a BinVector[src]

type Output = BinVector

The resulting type after applying the + operator.

impl Add<BinVector> for BinVector[src]

type Output = BinVector

The resulting type after applying the + operator.

impl<'a> Mul<&'a BinVector> for &'a BinMatrix[src]

type Output = BinVector

The resulting type after applying the * operator.

fn mul(self, other: &BinVector) -> Self::Output[src]

Computes (A * v^T)

impl Mul<BinVector> for BinMatrix[src]

type Output = BinVector

The resulting type after applying the * operator.

fn mul(self, other: BinVector) -> Self::Output[src]

Computes (A * v^T)

impl<'a> Mul<&'a BinMatrix> for &'a BinVector[src]

type Output = BinVector

The resulting type after applying the * operator.

fn mul(self, other: &BinMatrix) -> Self::Output[src]

computes v^T * A

impl Mul<BinMatrix> for BinVector[src]

type Output = BinVector

The resulting type after applying the * operator.

fn mul(self, other: BinMatrix) -> Self::Output[src]

computes v^T * A

impl<'a> Mul<&'a BinVector> for &'a BinVector[src]

type Output = bool

The resulting type after applying the * operator.

impl Mul<BinVector> for BinVector[src]

type Output = bool

The resulting type after applying the * operator.

fn mul(self, other: BinVector) -> Self::Output[src]

Compute the inner product between two vectors

impl<'a> AddAssign<&'a BinVector> for BinVector[src]

impl AddAssign<BinVector> for BinVector[src]

impl Hash for BinVector[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

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

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

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

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