[][src]Struct bittyset::BitSet

pub struct BitSet<T = usize> { /* fields omitted */ }

A BitSet type based on bit vectors.

T is an unsigned integer type for the underlying bit vector.

Implementations

impl<T> BitSet<T> where
    T: BitBlock
[src]

pub fn new() -> Self[src]

Creates a new empty BitSet.

Examples

use bittyset::BitSet;

let set = <BitSet>::new();
assert!(set.is_empty());

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

Creates a new empty BitSet with the given capacity for the underlying bit vector.

Note that the actual capacity of the created BitSet may be greater than the given capacity, to make best use of the space of the underlying bit vector.

Examples

use bittyset::BitSet;

let set = BitSet::<u8>::with_capacity(5);
assert_eq!(set.capacity(), 8);

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

Returns the capacity of the underlying bit vector.

Examples

use bittyset::BitSet;

let mut set = BitSet::<u8>::with_capacity(14);
assert_eq!(set.capacity(), 16);

pub fn reserve(&mut self, additional: usize)[src]

Reserves capacity for at least additional more bits for the underlying bit vector.

Examples

use bittyset::bitset;

let mut set = bitset![1];
set.reserve(10);
assert!(set.capacity() >= 11);

pub fn reserve_exact(&mut self, additional: usize)[src]

Reserve capacity for exactly additional more bits for the underlying bit vector.

Examples

use bittyset::bitset;

let mut set = bitset![1];
set.reserve_exact(10);
assert!(set.capacity() >= 11);

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of the underlying bit vector as much as possible.

Examples

use bittyset::BitSet;

let mut set = BitSet::<u8>::with_capacity(30);
set.extend([1, 2, 3].iter().cloned());
assert_eq!(set.capacity(), 32);
set.shrink_to_fit();
assert!(set.capacity() >= 8);

pub fn iter(&self) -> Iter<'_, T>

Notable traits for Iter<'a, T>

impl<'a, T> Iterator for Iter<'a, T> where
    T: BitBlock
type Item = usize;
[src]

Iterates over the BitSet, producing usizes representing the elements in the set, in ascending order.

Examples

use bittyset::bitset;

let set1 = bitset![7,3,5,18];
let vec1 = set1.iter().collect::<Vec<usize>>();

assert_eq!(vec1, vec![3,5,7,18]);

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

Returns the number of elements in the set.

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

Returns whether the set is empty.

pub fn clear(&mut self)[src]

Clear the set, removing all elements.

Note that this method has no effect on the allocated capacity of the underlying bit vector.

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

Returns whether the given value is present in the set.

Examples

use bittyset::bitset;

let mut set1 = bitset![7,3,5,18];

assert!(set1.contains(18));
assert!(!set1.contains(4));

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

Adds a value to the set.

If the set did not have this value present, true is returned.

If the set did have this value present, false is returned.

Examples

use bittyset::bitset;

let mut set1 = bitset![7,3,5,18];

assert!(set1.insert(13));
assert!(!set1.insert(5));

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

Removes a value from the set. Returns whether the value was present in the set.

Examples

use bittyset::bitset;

let mut set1 = bitset![7,3,5,18];

assert!(set1.remove(3));
assert!(!set1.remove(13));

pub fn union(&self, other: &Self) -> Self[src]

Computes the union of the set and other.

A corresponding BitOr implementation is also available, i.e. a | b.

Examples

use bittyset::bitset;

let set1 = bitset![7,3,5,18];
let set2 = bitset![3,1,6,7,24];
let set3 = bitset![1,3,5,6,7,18,24];

assert_eq!(set1.union(&set2), set3);
assert_eq!(set1 | set2, set3);

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

Computes the union of the set and other and then assigns the output to the set.

A corresponding BitOrAssign implementation is also available, i.e. a |= b.

Examples

use bittyset::bitset;

let mut set1 = bitset![7,3,5,18];
let set2 = bitset![3,1,6,7,24];
let set3 = bitset![1,3,5,6,7,18,24];

set1.union_with(&set2);

assert_eq!(set1, set3);

pub fn intersection(&self, other: &Self) -> Self[src]

Computes the intersection of the set and other.

A corresponding BitAnd implementation is also available, i.e. a & b.

Examples

use bittyset::bitset;

let set1 = bitset![7,3,5,18];
let set2 = bitset![3,1,6,7,24];
let set3 = bitset![3,7];

assert_eq!(set1.intersection(&set2), set3);
assert_eq!(set1 & set2, set3);

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

Computes the intersection of the set and other and then assigns the output to the set.

A corresponding BitAndAssign implementation is also available, i.e. a &= b.

Examples

use bittyset::bitset;

let mut set1 = bitset![7,3,5,18];
let set2 = bitset![3,1,6,7,24];
let set3 = bitset![3,7];

set1.intersect_with(&set2);

assert_eq!(set1, set3);

pub fn difference(&self, other: &Self) -> Self[src]

Computes the difference of the set and other.

A corresponding Sub implementation is also available, i.e. a - b.

Examples

use bittyset::bitset;

let set1 = bitset![7,3,5,18];
let set2 = bitset![3,1,6,7,24];
let set3 = bitset![5,18];

assert_eq!(set1.difference(&set2), set3);
assert_eq!(set1 - set2, set3);

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

Computes the difference of the set and other and then assigns the output to the set.

A corresponding SubAssign implementation is also available, i.e. a -= b.

Examples

use bittyset::bitset;

let mut set1 = bitset![7,3,5,18];
let set2 = bitset![3,1,6,7,24];
let set3 = bitset![5,18];

set1.difference_with(&set2);

assert_eq!(set1, set3);

pub fn symmetric_difference(&self, other: &Self) -> Self[src]

Computes the symmetric difference of the set and other.

A corresponding BitXor implementation is also available, i.e. a ^ b.

Examples

use bittyset::bitset;

let set1 = bitset![7,3,5,18];
let set2 = bitset![3,1,6,7,24];
let set3 = bitset![1,5,6,18,24];

assert_eq!(set1.symmetric_difference(&set2), set3);
assert_eq!(set1 ^ set2, set3);

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

Computes the symmetric difference of the set and other and then assigns the output to the set.

A corresponding BitXorAssign implementation is also available, i.e. a ^= b.

Examples

use bittyset::bitset;

let mut set1 = bitset![7,3,5,18];
let set2 = bitset![3,1,6,7,24];
let set3 = bitset![1,5,6,18,24];

set1.symmetric_difference_with(&set2);

assert_eq!(set1, set3);

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

Returns whether the set is a subset of other.

Examples

use bittyset::bitset;

let set1 = bitset![7,3,5,18];
let set2 = bitset![3,5,7,18,41];

assert!(set1.is_subset(&set2));
assert!(!set2.is_subset(&set1));

pub fn is_proper_subset(&self, other: &Self) -> bool[src]

Returns whether the set is a proper subset of other.

Examples

use bittyset::bitset;

let set1 = bitset![7,3,5,18];
let set2 = bitset![3,5,7,18,41];

assert!(set1.is_proper_subset(&set2));
assert!(!set2.is_proper_subset(&set1));
assert!(!set1.is_proper_subset(&set1));

Trait Implementations

impl<'a, T: BitBlock> BitAnd<&'a BitSet<T>> for &'a BitSet<T>[src]

type Output = BitSet<T>

The resulting type after applying the & operator.

impl<T: BitBlock> BitAnd<BitSet<T>> for BitSet<T>[src]

type Output = BitSet<T>

The resulting type after applying the & operator.

impl<'a, T: BitBlock> BitAndAssign<&'a BitSet<T>> for BitSet<T>[src]

impl<T: BitBlock> BitAndAssign<BitSet<T>> for BitSet<T>[src]

impl<'a, T: BitBlock> BitOr<&'a BitSet<T>> for &'a BitSet<T>[src]

type Output = BitSet<T>

The resulting type after applying the | operator.

impl<T: BitBlock> BitOr<BitSet<T>> for BitSet<T>[src]

type Output = BitSet<T>

The resulting type after applying the | operator.

impl<'a, T: BitBlock> BitOrAssign<&'a BitSet<T>> for BitSet<T>[src]

impl<T: BitBlock> BitOrAssign<BitSet<T>> for BitSet<T>[src]

impl<'a, T: BitBlock> BitXor<&'a BitSet<T>> for &'a BitSet<T>[src]

type Output = BitSet<T>

The resulting type after applying the ^ operator.

impl<T: BitBlock> BitXor<BitSet<T>> for BitSet<T>[src]

type Output = BitSet<T>

The resulting type after applying the ^ operator.

impl<'a, T: BitBlock> BitXorAssign<&'a BitSet<T>> for BitSet<T>[src]

impl<T: BitBlock> BitXorAssign<BitSet<T>> for BitSet<T>[src]

impl<T: Clone> Clone for BitSet<T>[src]

impl<T> Debug for BitSet<T> where
    T: BitBlock
[src]

impl<T: Default> Default for BitSet<T>[src]

impl<T: BitBlock> Eq for BitSet<T>[src]

impl<T: BitBlock> Extend<usize> for BitSet<T>[src]

impl<T: BitBlock> FromIterator<usize> for BitSet<T>[src]

impl<T: BitBlock> Hash for BitSet<T>[src]

impl<'a, T> IntoIterator for &'a BitSet<T> where
    T: BitBlock
[src]

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

type Item = usize

The type of the elements being iterated over.

impl<T: BitBlock> PartialEq<BitSet<T>> for BitSet<T>[src]

impl<'a, T: BitBlock> Sub<&'a BitSet<T>> for &'a BitSet<T>[src]

type Output = BitSet<T>

The resulting type after applying the - operator.

impl<T: BitBlock> Sub<BitSet<T>> for BitSet<T>[src]

type Output = BitSet<T>

The resulting type after applying the - operator.

impl<'a, T: BitBlock> SubAssign<&'a BitSet<T>> for BitSet<T>[src]

impl<T: BitBlock> SubAssign<BitSet<T>> for BitSet<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for BitSet<T> where
    T: RefUnwindSafe

impl<T> Send for BitSet<T> where
    T: Send

impl<T> Sync for BitSet<T> where
    T: Sync

impl<T> Unpin for BitSet<T> where
    T: Unpin

impl<T> UnwindSafe for BitSet<T> where
    T: UnwindSafe

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, 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.