BitVector

Struct BitVector 

Source
pub struct BitVector { /* private fields */ }
Expand description

Bitvector

Implementations§

Source§

impl BitVector

Source

pub fn new(bits: usize) -> Self

Build a new empty bitvector

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

the number of elements in set

Source

pub fn clear(&mut self)

Clear all elements from a bitvector

Source

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.

Source

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]
Source

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.

Source

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.

Source

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.

Source

pub fn capacity(&self) -> usize

the max number of elements can be inserted into set

Source

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

set union

Source

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

set intersection

Source

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

set difference

Source

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

Source

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

Union operator by modifying self

No extra memory allocation

Source

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

Intersection operator by modifying self

No extra memory allocation

Source

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

Difference operator by modifying self

No extra memory allocation

Source

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

Source

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> BitAnd for &'a BitVector

Source§

type Output = BitVector

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitAnd for BitVector

Source§

type Output = BitVector

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl<'a> BitAndAssign for &'a mut BitVector

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitAndAssign for BitVector

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl<'a> BitOr for &'a BitVector

Source§

type Output = BitVector

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOr for BitVector

Source§

type Output = BitVector

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl<'a> BitOrAssign for &'a mut BitVector

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl BitOrAssign for BitVector

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl<'a> BitXor for &'a BitVector

Source§

type Output = BitVector

The resulting type after applying the ^ operator.
Source§

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

Performs the ^ operation. Read more
Source§

impl BitXor for BitVector

Source§

type Output = BitVector

The resulting type after applying the ^ operator.
Source§

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

Performs the ^ operation. Read more
Source§

impl<'a> BitXorAssign for &'a mut BitVector

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl BitXorAssign for BitVector

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl Clone for BitVector

Source§

fn clone(&self) -> BitVector

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for BitVector

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for BitVector

Source§

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

Formats the value using the given formatter. Read more
Source§

impl FromIterator<bool> for BitVector

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<i16> for BitVector

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<i32> for BitVector

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<i64> for BitVector

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<i8> for BitVector

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<isize> for BitVector

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<u16> for BitVector

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<u32> for BitVector

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<u64> for BitVector

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<u8> for BitVector

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromIterator<usize> for BitVector

Source§

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

Creates a value from an iterator. Read more
Source§

impl<'a> IntoIterator for &'a BitVector

Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = BitVectorIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut BitVector

Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = BitVectorIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for BitVector

Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = BitVectorIntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for BitVector

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.