Struct bitvector::BitVector [] [src]

pub struct BitVector {
    // some fields omitted
}

Bitvector

Methods

impl BitVector
[src]

fn new(bits: usize) -> Self

Build a new empty bitvector

fn ones(bits: usize) -> Self

new bitvector contains all elements

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

fn is_empty(&self) -> bool

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.

fn len(&self) -> usize

the number of elements in set

fn clear(&mut self)

Clear all elements from a bitvector

fn contains(&self, bit: usize) -> bool

If bit belongs to set, return true, else return false. Insert, remove and contains do not do bound check.

fn eq_left(&self, other: &BitVector, bit: usize) -> bool

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] 

fn insert(&mut self, bit: usize) -> bool

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.

fn remove(&mut self, bit: usize) -> bool

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.

fn insert_all(&mut self, all: &BitVector) -> bool

import elements from another bitvector

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

fn capacity(&self) -> usize

the max number of elements can be inserted into set

fn union(&self, other: &BitVector) -> BitVector

set union

fn intersection(&self, other: &BitVector) -> BitVector

set intersection

fn difference(&self, other: &BitVector) -> BitVector

set difference

fn difference_d(&self, other: &BitVector) -> BitVector

fn union_inplace(&mut self, other: &BitVector) -> &mut BitVector

Union operator by modifying self

No extra memory allocation

fn intersection_inplace(&mut self, other: &BitVector) -> &mut BitVector

Intersection operator by modifying self

No extra memory allocation

fn difference_inplace(&mut self, other: &BitVector) -> &mut BitVector

Difference operator by modifying self

No extra memory allocation

fn difference_d_inplace(&mut self, other: &BitVector) -> &mut BitVector

fn iter<'a>(&'a self) -> BitVectorIter<'a>

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 Debug for BitVector
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Clone for BitVector
[src]

fn clone(&self) -> BitVector

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

impl Display for BitVector
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.

impl PartialEq for BitVector
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl FromIterator<bool> for BitVector
[src]

fn from_iter<I>(iter: I) -> BitVector where I: IntoIterator<Item=bool>

Creates a value from an iterator. Read more

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

type Output = BitVector

The resulting type after applying the & operator

fn bitand(self, rhs: Self) -> BitVector

The method for the & operator

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

fn bitand_assign(&mut self, rhs: Self)

The method for the & operator

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

type Output = BitVector

The resulting type after applying the | operator

fn bitor(self, rhs: Self) -> BitVector

The method for the | operator

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

fn bitor_assign(&mut self, rhs: Self)

The method for the |= operator

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

type Output = BitVector

The resulting type after applying the ^ operator

fn bitxor(self, rhs: Self) -> BitVector

The method for the ^ operator

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

fn bitxor_assign(&mut self, rhs: Self)

The method for the ^= operator

impl BitAnd for BitVector
[src]

type Output = BitVector

The resulting type after applying the & operator

fn bitand(self, rhs: Self) -> BitVector

The method for the & operator

impl BitAndAssign for BitVector
[src]

fn bitand_assign(&mut self, rhs: Self)

The method for the & operator

impl BitOr for BitVector
[src]

type Output = BitVector

The resulting type after applying the | operator

fn bitor(self, rhs: Self) -> BitVector

The method for the | operator

impl BitOrAssign for BitVector
[src]

fn bitor_assign(&mut self, rhs: Self)

The method for the |= operator

impl BitXor for BitVector
[src]

type Output = BitVector

The resulting type after applying the ^ operator

fn bitxor(self, rhs: Self) -> BitVector

The method for the ^ operator

impl BitXorAssign for BitVector
[src]

fn bitxor_assign(&mut self, rhs: Self)

The method for the ^= operator