Struct bitvector::BitVector [] [src]

pub struct BitVector { /* fields omitted */ }

Bitvector

Methods

impl BitVector
[src]

Build a new empty bitvector

new bitvector contains all elements

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

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.

the number of elements in set

Clear all elements from a bitvector

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

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] 

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.

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.

import elements from another bitvector

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

the max number of elements can be inserted into set

set union

set intersection

set difference

Union operator by modifying self

No extra memory allocation

Intersection operator by modifying self

No extra memory allocation

Difference operator by modifying self

No extra memory allocation

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for BitVector
[src]

Formats the value using the given formatter.

impl Display for BitVector
[src]

Formats the value using the given formatter. Read more

impl PartialEq for BitVector
[src]

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

This method tests for !=.

impl FromIterator<bool> for BitVector
[src]

Creates a value from an iterator. Read more

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

The resulting type after applying the & operator

The method for the & operator

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

The method for the &= operator

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

The resulting type after applying the | operator

The method for the | operator

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

The method for the |= operator

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

The resulting type after applying the ^ operator

The method for the ^ operator

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

The method for the ^= operator

impl BitAnd for BitVector
[src]

The resulting type after applying the & operator

The method for the & operator

impl BitAndAssign for BitVector
[src]

The method for the &= operator

impl BitOr for BitVector
[src]

The resulting type after applying the | operator

The method for the | operator

impl BitOrAssign for BitVector
[src]

The method for the |= operator

impl BitXor for BitVector
[src]

The resulting type after applying the ^ operator

The method for the ^ operator

impl BitXorAssign for BitVector
[src]

The method for the ^= operator