Struct bitmagic::BVector[][src]

pub struct BVector { /* fields omitted */ }

A bitvector

Implementations

impl BVector[src]

pub fn new() -> BVector[src]

Create a new bit-vector container with runtime compression of bits

pub fn with_capacity(capacity: usize) -> BVector[src]

Create a new bit-vector container with capacity (maximum number of allowed bits).

BitMagic recommends ALWAYS setting the size to maximum, so it is preferable to use new instead.

pub fn grow(&mut self, bits: usize)[src]

Grow capacity to bits, all new bits initialized to zero

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

Return the length of the BVector in bits.

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

Check if any bits are set

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

Return true if the bit is enabled in the BVector, false otherwise.

Note: bits outside the capacity are always disabled.

Note: Also available with index syntax: bvector[bit].

pub fn clear(&mut self)[src]

Clear all bits.

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

Enable bit.

Panics if bit is out of bounds.

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

Enable bit, and return its previous value.

Panics if bit is out of bounds.

pub fn toggle(&mut self, bit: usize)[src]

Toggle bit (inverting its state).

Panics if bit is out of bounds

pub fn set(&mut self, bit: usize, enabled: bool)[src]

Panics if bit is out of bounds.

pub fn copy_bit(&mut self, from: usize, to: usize)[src]

Copies boolean value from specified bit to the specified bit.

Panics if to is out of bounds.

pub fn count_ones<T: IndexRange>(&self, range: T) -> usize[src]

Count the number of set bits in the given bit range.

Use .. to count the whole content of the bitset.

Panics if the range extends past the end of the bitset.

pub fn set_range<T: IndexRange>(&mut self, range: T, enabled: bool)[src]

Sets every bit in the given range to the given state (enabled)

Use .. to set the whole bitset.

Panics if the range extends past the end of the bitset.

pub fn insert_range<T: IndexRange>(&mut self, range: T)[src]

Enables every bit in the given range.

Use .. to make the whole bitset ones.

Panics if the range extends past the end of the bitset.

pub fn toggle_range<T: IndexRange>(&mut self, range: T)[src]

Toggles (inverts) every bit in the given range.

Use .. to toggle the whole bitset.

Panics if the range extends past the end of the bitset.

pub fn ones(&self) -> Ones<'_>[src]

Iterates over all enabled bits.

Iterator element is the index of the 1 bit, type usize.

pub fn intersection<'a>(&'a self, other: &'a BVector) -> Intersection<'a>[src]

Returns a lazy iterator over the intersection of two BVectors

pub fn union<'a>(&'a self, other: &'a BVector) -> Union<'a>[src]

Returns a lazy iterator over the union of two BVectors.

pub fn difference<'a>(&'a self, other: &'a BVector) -> Difference<'a>[src]

Returns a lazy iterator over the difference of two BVectors. The difference of a and b is the elements of a which are not in b.

pub fn symmetric_difference<'a>(
    &'a self,
    other: &'a BVector
) -> SymmetricDifference<'a>
[src]

Returns a lazy iterator over the symmetric difference of two BVectors. The symmetric difference of a and b is the elements of one, but not both, sets.

pub fn union_with(&mut self, other: &BVector)[src]

In-place union of two BVectors.

On calling this method, self’s capacity may be increased to match other’s.

pub fn intersect_with(&mut self, other: &BVector)[src]

In-place intersection of two BVectors.

On calling this method, self’s capacity will remain the same as before.

pub fn difference_with(&mut self, other: &BVector)[src]

In-place difference of two BVectors.

On calling this method, self’s capacity will remain the same as before.

pub fn symmetric_difference_with(&mut self, other: &BVector)[src]

In-place symmetric difference of two BVectors.

On calling this method, self’s capacity may be increased to match other’s.

pub fn is_disjoint(&self, other: &BVector) -> bool[src]

Returns true if self has no elements in common with other. This is equivalent to checking for an empty intersection.

pub fn is_subset(&self, other: &BVector) -> bool[src]

Returns true if the set is a subset of another, i.e. other contains at least all the values in self.

pub fn is_superset(&self, other: &BVector) -> bool[src]

Returns true if the set is a superset of another, i.e. self contains at least all the values in other.

impl BVector[src]

pub fn serialize<W>(&self, wtr: W) -> Result<(), Box<dyn Error>> where
    W: Write
[src]

Serialize bit vector

pub fn deserialize<R>(rdr: R) -> Result<Self, Box<dyn Error>> where
    R: Read
[src]

Deserialize bit vector

pub fn intersection_count(&self, other: &BVector) -> usize[src]

Size of the intersection of two BVectors.

Equivalent to the population count of AND of two bit vectors

pub fn union_count(&self, other: &BVector) -> usize[src]

Size of the union of two BVectors.

Equivalent to the population count of OR of two bit vectors

pub fn difference_count(&self, other: &BVector) -> usize[src]

Size of the difference of two BVectors.

Equivalent to the population count of SUB of two bit vectors

pub fn symmetric_difference_count(&self, other: &BVector) -> usize[src]

Size of the symmetric difference of two BVectors.

Equivalent to the population count of XOR of two bit vectors

Trait Implementations

impl Binary for BVector[src]

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

type Output = BVector

The resulting type after applying the & operator.

impl<'a> BitAndAssign<&'_ BVector> for BVector[src]

impl<'a> BitAndAssign<BVector> for BVector[src]

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

type Output = BVector

The resulting type after applying the | operator.

impl<'a> BitOrAssign<&'_ BVector> for BVector[src]

impl<'a> BitOrAssign<BVector> for BVector[src]

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

type Output = BVector

The resulting type after applying the ^ operator.

impl<'a> BitXorAssign<&'_ BVector> for BVector[src]

impl<'a> BitXorAssign<BVector> for BVector[src]

impl Clone for BVector[src]

impl Debug for BVector[src]

impl Default for BVector[src]

impl Display for BVector[src]

impl Drop for BVector[src]

impl Extend<usize> for BVector[src]

Sets the bit at index i to true for each item i in the input src.

impl FromIterator<usize> for BVector[src]

Return a BVector containing bits set to true for every bit index in the iterator, other bits are set to false.

impl Index<usize> for BVector[src]

Return true if the bit is enabled in the bitset, or false otherwise.

Note: bits outside the capacity are always disabled, and thus indexing a BVector will not panic.

type Output = bool

The returned type after indexing.

impl PartialEq<BVector> for BVector[src]

impl PartialOrd<BVector> for BVector[src]

Auto Trait Implementations

impl RefUnwindSafe for BVector

impl !Send for BVector

impl !Sync for BVector

impl Unpin for BVector

impl UnwindSafe for BVector

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

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

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 = Infallible

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.