pub struct BitVector { /* private fields */ }Expand description
Bitvector
Implementations§
Source§impl BitVector
impl BitVector
Sourcepub fn ones(bits: usize) -> Self
pub 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.
Sourcepub fn is_empty(&self) -> bool
pub 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.
Sourcepub fn contains(&self, bit: usize) -> bool
pub 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.
Sourcepub fn eq_left(&self, other: &BitVector, bit: usize) -> bool
pub 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]Sourcepub fn insert(&mut self, bit: usize) -> bool
pub 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.
Sourcepub fn remove(&mut self, bit: usize) -> bool
pub 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.
Sourcepub fn insert_all(&mut self, all: &BitVector) -> bool
pub fn insert_all(&mut self, all: &BitVector) -> bool
import elements from another bitvector
If any new value is inserted, return true, else return false.
Sourcepub fn intersection(&self, other: &BitVector) -> BitVector
pub fn intersection(&self, other: &BitVector) -> BitVector
set intersection
Sourcepub fn difference(&self, other: &BitVector) -> BitVector
pub fn difference(&self, other: &BitVector) -> BitVector
set difference
pub fn difference_d(&self, other: &BitVector) -> BitVector
Sourcepub fn union_inplace(&mut self, other: &BitVector) -> &mut BitVector
pub fn union_inplace(&mut self, other: &BitVector) -> &mut BitVector
Union operator by modifying self
No extra memory allocation
Sourcepub fn intersection_inplace(&mut self, other: &BitVector) -> &mut BitVector
pub fn intersection_inplace(&mut self, other: &BitVector) -> &mut BitVector
Intersection operator by modifying self
No extra memory allocation
Sourcepub fn difference_inplace(&mut self, other: &BitVector) -> &mut BitVector
pub fn difference_inplace(&mut self, other: &BitVector) -> &mut BitVector
Difference operator by modifying self
No extra memory allocation
pub fn difference_d_inplace(&mut self, other: &BitVector) -> &mut BitVector
Sourcepub fn iter<'a>(&'a self) -> BitVectorIter<'a> ⓘ
pub 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§
Source§impl<'a> BitAndAssign for &'a mut BitVector
impl<'a> BitAndAssign for &'a mut BitVector
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl BitAndAssign for BitVector
impl BitAndAssign for BitVector
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl<'a> BitOrAssign for &'a mut BitVector
impl<'a> BitOrAssign for &'a mut BitVector
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl BitOrAssign for BitVector
impl BitOrAssign for BitVector
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl<'a> BitXorAssign for &'a mut BitVector
impl<'a> BitXorAssign for &'a mut BitVector
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read moreSource§impl BitXorAssign for BitVector
impl BitXorAssign for BitVector
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read more