[][src]Struct bitvector::BitVector

pub struct BitVector { /* fields omitted */ }

Bitvector

Methods

impl BitVector[src]

pub fn new(bits: usize) -> Self[src]

Build a new empty bitvector

pub fn ones(bits: usize) -> Self[src]

new bitvector contains all elements

If bits % 64 > 0, the last u64 is guaranteed not to have any extra 1 bits.

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

return if this set is empty

if set does not contain any elements, return true; else return false.

This method is averagely faster than self.len() > 0.

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

the number of elements in set

pub fn clear(&mut self)[src]

Clear all elements from a bitvector

pub fn contains(&self, bit: usize) -> bool[src]

If bit belongs to set, return true, else return false.

Insert, remove and contains do not do bound check.

pub fn eq_left(&self, other: &BitVector, bit: usize) -> bool[src]

compare if the following is true:

self \cap {0, 1, ... , bit - 1} == other \cap {0, 1, ... ,bit - 1}

for example:

use bitvector::*;

let mut A = BitVector::new(11);
let mut B = BitVector::new(11);
for i in vec![0, 1, 3 ,5 ,7, 10] { A.insert(i); }
for i in vec![0, 1, 3, 4, 5, 7, 10] { B.insert(i); }


assert!(A.eq_left(&B, 1));  // [0             ]  = [0              ]
assert!(A.eq_left(&B, 2));  // [0, 1          ]  = [0, 1           ]
assert!(A.eq_left(&B, 3));  // [0, 1          ]  = [0, 1           ]
assert!(A.eq_left(&B, 4));  // [0, 1,   3     ]  = [0, 1,   3      ]
assert!(!A.eq_left(&B, 5)); // [0, 1,   3     ] != [0, 1,   3, 4   ]
assert!(!A.eq_left(&B, 6)); // [0, 1,   3,   5] != [0, 1,   3, 4, 5]

pub fn insert(&mut self, bit: usize) -> bool[src]

insert a new element to set

If value is inserted, return true, if value already exists in set, return false.

Insert, remove and contains do not do bound check.

pub fn remove(&mut self, bit: usize) -> bool[src]

remove an element from set

If value is removed, return true, if value doesn't exist in set, return false.

Insert, remove and contains do not do bound check.

pub fn insert_all(&mut self, all: &BitVector) -> bool[src]

import elements from another bitvector

If any new value is inserted, return true, else return false.

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

the max number of elements can be inserted into set

pub fn union(&self, other: &BitVector) -> BitVector[src]

set union

pub fn intersection(&self, other: &BitVector) -> BitVector[src]

set intersection

pub fn difference(&self, other: &BitVector) -> BitVector[src]

set difference

pub fn difference_d(&self, other: &BitVector) -> BitVector[src]

pub fn union_inplace(&mut self, other: &BitVector) -> &mut BitVector[src]

Union operator by modifying self

No extra memory allocation

pub fn intersection_inplace(&mut self, other: &BitVector) -> &mut BitVector[src]

Intersection operator by modifying self

No extra memory allocation

pub fn difference_inplace(&mut self, other: &BitVector) -> &mut BitVector[src]

Difference operator by modifying self

No extra memory allocation

pub fn difference_d_inplace(&mut self, other: &BitVector) -> &mut BitVector[src]

Important traits for BitVectorIter<'a>
pub fn iter<'a>(&'a self) -> BitVectorIter<'a>[src]

Return a iterator of element based on current bitvector, for example:

extern crate bitvector;
use bitvector::*;

fn main() {
    let mut bitvec = BitVector::new(5);
    bitvec.insert(2);
    bitvec.insert(3);
    // The bitvector becomes: 0x00 0x00 0x00 0x0C
    assert_eq!(bitvec.iter().collect::<Vec<_>>(), vec![2,3]);
    // collected vector will contains the real element not the bit.
}

Trait Implementations

impl IntoIterator for BitVector[src]

type Item = usize

The type of the elements being iterated over.

type IntoIter = BitVectorIntoIter

Which kind of iterator are we turning this into?

impl<'a> IntoIterator for &'a BitVector[src]

type Item = usize

The type of the elements being iterated over.

type IntoIter = BitVectorIter<'a>

Which kind of iterator are we turning this into?

impl<'a> IntoIterator for &'a mut BitVector[src]

type Item = usize

The type of the elements being iterated over.

type IntoIter = BitVectorIter<'a>

Which kind of iterator are we turning this into?

impl Clone for BitVector[src]

impl PartialEq<BitVector> for BitVector[src]

impl Debug for BitVector[src]

impl Display for BitVector[src]

impl<'a> BitAnd<&'a BitVector> for &'a BitVector[src]

type Output = BitVector

The resulting type after applying the & operator.

impl BitAnd<BitVector> for BitVector[src]

type Output = BitVector

The resulting type after applying the & operator.

impl<'a> BitOr<&'a BitVector> for &'a BitVector[src]

type Output = BitVector

The resulting type after applying the | operator.

impl BitOr<BitVector> for BitVector[src]

type Output = BitVector

The resulting type after applying the | operator.

impl<'a> BitXor<&'a BitVector> for &'a BitVector[src]

type Output = BitVector

The resulting type after applying the ^ operator.

impl BitXor<BitVector> for BitVector[src]

type Output = BitVector

The resulting type after applying the ^ operator.

impl<'a> BitAndAssign<&'a mut BitVector> for &'a mut BitVector[src]

impl BitAndAssign<BitVector> for BitVector[src]

impl<'a> BitOrAssign<&'a mut BitVector> for &'a mut BitVector[src]

impl BitOrAssign<BitVector> for BitVector[src]

impl<'a> BitXorAssign<&'a mut BitVector> for &'a mut BitVector[src]

impl BitXorAssign<BitVector> for BitVector[src]

impl FromIterator<u8> for BitVector[src]

impl FromIterator<u16> for BitVector[src]

impl FromIterator<u32> for BitVector[src]

impl FromIterator<u64> for BitVector[src]

impl FromIterator<usize> for BitVector[src]

impl FromIterator<i8> for BitVector[src]

impl FromIterator<i16> for BitVector[src]

impl FromIterator<i32> for BitVector[src]

impl FromIterator<i64> for BitVector[src]

impl FromIterator<isize> for BitVector[src]

impl FromIterator<bool> for BitVector[src]

Auto Trait Implementations

Blanket Implementations

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

impl<T> From<T> 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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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

type Error = !

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]