Struct bit_set::BitSet [−][src]
pub struct BitSet<B = u32> { /* fields omitted */ }
Methods
impl BitSet<u32>[src]
impl BitSet<u32>pub fn new() -> Self[src]
pub fn new() -> Selfpub fn with_capacity(nbits: usize) -> Self[src]
pub fn with_capacity(nbits: usize) -> SelfCreates a new BitSet with initially no contents, able to
hold nbits elements without resizing.
Examples
use bit_set::BitSet; let mut s = BitSet::with_capacity(100); assert!(s.capacity() >= 100);
pub fn from_bit_vec(bit_vec: BitVec) -> Self[src]
pub fn from_bit_vec(bit_vec: BitVec) -> SelfCreates a new BitSet from the given bit vector.
Examples
extern crate bit_vec; extern crate bit_set; fn main() { use bit_vec::BitVec; use bit_set::BitSet; let bv = BitVec::from_bytes(&[0b01100000]); let s = BitSet::from_bit_vec(bv); // Print 1, 2 in arbitrary order for x in s.iter() { println!("{}", x); } }
pub fn from_bytes(bytes: &[u8]) -> Self[src]
pub fn from_bytes(bytes: &[u8]) -> Selfimpl<B: BitBlock> BitSet<B>[src]
impl<B: BitBlock> BitSet<B>pub fn capacity(&self) -> usize[src]
pub fn capacity(&self) -> usizeReturns the capacity in bits for this bit vector. Inserting any element less than this amount will not trigger a resizing.
Examples
use bit_set::BitSet; let mut s = BitSet::with_capacity(100); assert!(s.capacity() >= 100);
pub fn reserve_len(&mut self, len: usize)[src]
pub fn reserve_len(&mut self, len: usize)Reserves capacity for the given BitSet to contain len distinct elements. In the case
of BitSet this means reallocations will not occur as long as all inserted elements
are less than len.
The collection may reserve more space to avoid frequent reallocations.
Examples
use bit_set::BitSet; let mut s = BitSet::new(); s.reserve_len(10); assert!(s.capacity() >= 10);
pub fn reserve_len_exact(&mut self, len: usize)[src]
pub fn reserve_len_exact(&mut self, len: usize)Reserves the minimum capacity for the given BitSet to contain len distinct elements.
In the case of BitSet this means reallocations will not occur as long as all inserted
elements are less than len.
Note that the allocator may give the collection more space than it requests. Therefore
capacity can not be relied upon to be precisely minimal. Prefer reserve_len if future
insertions are expected.
Examples
use bit_set::BitSet; let mut s = BitSet::new(); s.reserve_len_exact(10); assert!(s.capacity() >= 10);
pub fn into_bit_vec(self) -> BitVec<B>[src]
pub fn into_bit_vec(self) -> BitVec<B>Consumes this set to return the underlying bit vector.
Examples
use bit_set::BitSet; let mut s = BitSet::new(); s.insert(0); s.insert(3); let bv = s.into_bit_vec(); assert!(bv[0]); assert!(bv[3]);
pub fn get_ref(&self) -> &BitVec<B>[src]
pub fn get_ref(&self) -> &BitVec<B>Returns a reference to the underlying bit vector.
Examples
use bit_set::BitSet; let mut s = BitSet::new(); s.insert(0); let bv = s.get_ref(); assert_eq!(bv[0], true);
pub fn shrink_to_fit(&mut self)[src]
pub fn shrink_to_fit(&mut self)Truncates the underlying vector to the least length required.
Examples
use bit_set::BitSet; let mut s = BitSet::new(); s.insert(32183231); s.remove(32183231); // Internal storage will probably be bigger than necessary println!("old capacity: {}", s.capacity()); // Now should be smaller s.shrink_to_fit(); println!("new capacity: {}", s.capacity());
ⓘImportant traits for Iter<'a, B>pub fn iter(&self) -> Iter<B>[src]
pub fn iter(&self) -> Iter<B>Iterator over each usize stored in the BitSet.
Examples
use bit_set::BitSet; let s = BitSet::from_bytes(&[0b01001010]); // Print 1, 4, 6 in arbitrary order for x in s.iter() { println!("{}", x); }
ⓘImportant traits for Union<'a, B>pub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, B>[src]
pub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, B>Iterator over each usize stored in self union other.
See union_with for an efficient in-place version.
Examples
use bit_set::BitSet; let a = BitSet::from_bytes(&[0b01101000]); let b = BitSet::from_bytes(&[0b10100000]); // Print 0, 1, 2, 4 in arbitrary order for x in a.union(&b) { println!("{}", x); }
ⓘImportant traits for Intersection<'a, B>pub fn intersection<'a>(&'a self, other: &'a Self) -> Intersection<'a, B>[src]
pub fn intersection<'a>(&'a self, other: &'a Self) -> Intersection<'a, B>Iterator over each usize stored in self intersect other.
See intersect_with for an efficient in-place version.
Examples
use bit_set::BitSet; let a = BitSet::from_bytes(&[0b01101000]); let b = BitSet::from_bytes(&[0b10100000]); // Print 2 for x in a.intersection(&b) { println!("{}", x); }
ⓘImportant traits for Difference<'a, B>pub fn difference<'a>(&'a self, other: &'a Self) -> Difference<'a, B>[src]
pub fn difference<'a>(&'a self, other: &'a Self) -> Difference<'a, B>Iterator over each usize stored in the self setminus other.
See difference_with for an efficient in-place version.
Examples
use bit_set::BitSet; let a = BitSet::from_bytes(&[0b01101000]); let b = BitSet::from_bytes(&[0b10100000]); // Print 1, 4 in arbitrary order for x in a.difference(&b) { println!("{}", x); } // Note that difference is not symmetric, // and `b - a` means something else. // This prints 0 for x in b.difference(&a) { println!("{}", x); }
ⓘImportant traits for SymmetricDifference<'a, B>pub fn symmetric_difference<'a>(
&'a self,
other: &'a Self
) -> SymmetricDifference<'a, B>[src]
pub fn symmetric_difference<'a>(
&'a self,
other: &'a Self
) -> SymmetricDifference<'a, B>Iterator over each usize stored in the symmetric difference of self and other.
See symmetric_difference_with for
an efficient in-place version.
Examples
use bit_set::BitSet; let a = BitSet::from_bytes(&[0b01101000]); let b = BitSet::from_bytes(&[0b10100000]); // Print 0, 1, 4 in arbitrary order for x in a.symmetric_difference(&b) { println!("{}", x); }
pub fn union_with(&mut self, other: &Self)[src]
pub fn union_with(&mut self, other: &Self)Unions in-place with the specified other bit vector.
Examples
use bit_set::BitSet; let a = 0b01101000; let b = 0b10100000; let res = 0b11101000; let mut a = BitSet::from_bytes(&[a]); let b = BitSet::from_bytes(&[b]); let res = BitSet::from_bytes(&[res]); a.union_with(&b); assert_eq!(a, res);
pub fn intersect_with(&mut self, other: &Self)[src]
pub fn intersect_with(&mut self, other: &Self)Intersects in-place with the specified other bit vector.
Examples
use bit_set::BitSet; let a = 0b01101000; let b = 0b10100000; let res = 0b00100000; let mut a = BitSet::from_bytes(&[a]); let b = BitSet::from_bytes(&[b]); let res = BitSet::from_bytes(&[res]); a.intersect_with(&b); assert_eq!(a, res);
pub fn difference_with(&mut self, other: &Self)[src]
pub fn difference_with(&mut self, other: &Self)Makes this bit vector the difference with the specified other bit vector in-place.
Examples
use bit_set::BitSet; let a = 0b01101000; let b = 0b10100000; let a_b = 0b01001000; // a - b let b_a = 0b10000000; // b - a let mut bva = BitSet::from_bytes(&[a]); let bvb = BitSet::from_bytes(&[b]); let bva_b = BitSet::from_bytes(&[a_b]); let bvb_a = BitSet::from_bytes(&[b_a]); bva.difference_with(&bvb); assert_eq!(bva, bva_b); let bva = BitSet::from_bytes(&[a]); let mut bvb = BitSet::from_bytes(&[b]); bvb.difference_with(&bva); assert_eq!(bvb, bvb_a);
pub fn symmetric_difference_with(&mut self, other: &Self)[src]
pub fn symmetric_difference_with(&mut self, other: &Self)Makes this bit vector the symmetric difference with the specified other bit vector in-place.
Examples
use bit_set::BitSet; let a = 0b01101000; let b = 0b10100000; let res = 0b11001000; let mut a = BitSet::from_bytes(&[a]); let b = BitSet::from_bytes(&[b]); let res = BitSet::from_bytes(&[res]); a.symmetric_difference_with(&b); assert_eq!(a, res);
pub fn len(&self) -> usize[src]
pub fn len(&self) -> usizeReturns the number of set bits in this set.
pub fn is_empty(&self) -> bool[src]
pub fn is_empty(&self) -> boolReturns whether there are no bits set in this set
pub fn clear(&mut self)[src]
pub fn clear(&mut self)Clears all bits in this set
pub fn contains(&self, value: usize) -> bool[src]
pub fn contains(&self, value: usize) -> boolReturns true if this set contains the specified integer.
pub fn is_disjoint(&self, other: &Self) -> bool[src]
pub fn is_disjoint(&self, other: &Self) -> boolReturns true if the set has no elements in common with other.
This is equivalent to checking for an empty intersection.
pub fn is_subset(&self, other: &Self) -> bool[src]
pub fn is_subset(&self, other: &Self) -> boolReturns true if the set is a subset of another.
pub fn is_superset(&self, other: &Self) -> bool[src]
pub fn is_superset(&self, other: &Self) -> boolReturns true if the set is a superset of another.
pub fn insert(&mut self, value: usize) -> bool[src]
pub fn insert(&mut self, value: usize) -> boolAdds a value to the set. Returns true if the value was not already
present in the set.
pub fn remove(&mut self, value: usize) -> bool[src]
pub fn remove(&mut self, value: usize) -> boolRemoves a value from the set. Returns true if the value was
present in the set.
Trait Implementations
impl<B: BitBlock> Clone for BitSet<B>[src]
impl<B: BitBlock> Clone for BitSet<B>fn clone(&self) -> Self[src]
fn clone(&self) -> SelfReturns a copy of the value. Read more
fn clone_from(&mut self, other: &Self)[src]
fn clone_from(&mut self, other: &Self)Performs copy-assignment from source. Read more
impl<B: BitBlock> Default for BitSet<B>[src]
impl<B: BitBlock> Default for BitSet<B>impl<B: BitBlock> FromIterator<usize> for BitSet<B>[src]
impl<B: BitBlock> FromIterator<usize> for BitSet<B>fn from_iter<I: IntoIterator<Item = usize>>(iter: I) -> Self[src]
fn from_iter<I: IntoIterator<Item = usize>>(iter: I) -> SelfCreates a value from an iterator. Read more
impl<B: BitBlock> Extend<usize> for BitSet<B>[src]
impl<B: BitBlock> Extend<usize> for BitSet<B>fn extend<I: IntoIterator<Item = usize>>(&mut self, iter: I)[src]
fn extend<I: IntoIterator<Item = usize>>(&mut self, iter: I)Extends a collection with the contents of an iterator. Read more
impl<B: BitBlock> PartialOrd for BitSet<B>[src]
impl<B: BitBlock> PartialOrd for BitSet<B>fn partial_cmp(&self, other: &Self) -> Option<Ordering>[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool1.0.0[src]
fn lt(&self, other: &Rhs) -> boolThis method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &Rhs) -> bool1.0.0[src]
fn le(&self, other: &Rhs) -> boolThis method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn gt(&self, other: &Rhs) -> bool1.0.0[src]
fn gt(&self, other: &Rhs) -> boolThis method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, other: &Rhs) -> bool1.0.0[src]
fn ge(&self, other: &Rhs) -> boolThis method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl<B: BitBlock> Ord for BitSet<B>[src]
impl<B: BitBlock> Ord for BitSet<B>fn cmp(&self, other: &Self) -> Ordering[src]
fn cmp(&self, other: &Self) -> OrderingThis method returns an Ordering between self and other. Read more
fn max(self, other: Self) -> Self1.21.0[src]
fn max(self, other: Self) -> SelfCompares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self1.21.0[src]
fn min(self, other: Self) -> SelfCompares and returns the minimum of two values. Read more
impl<B: BitBlock> PartialEq for BitSet<B>[src]
impl<B: BitBlock> PartialEq for BitSet<B>fn eq(&self, other: &Self) -> bool[src]
fn eq(&self, other: &Self) -> boolThis method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
fn ne(&self, other: &Rhs) -> boolThis method tests for !=.
impl<B: BitBlock> Eq for BitSet<B>[src]
impl<B: BitBlock> Eq for BitSet<B>impl<B: BitBlock> Debug for BitSet<B>[src]
impl<B: BitBlock> Debug for BitSet<B>fn fmt(&self, fmt: &mut Formatter) -> Result[src]
fn fmt(&self, fmt: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl<B: BitBlock> Hash for BitSet<B>[src]
impl<B: BitBlock> Hash for BitSet<B>fn hash<H: Hasher>(&self, state: &mut H)[src]
fn hash<H: Hasher>(&self, state: &mut H)Feeds this value into the given [Hasher]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, Feeds a slice of this type into the given [Hasher]. Read more
impl<'a, B: BitBlock> IntoIterator for &'a BitSet<B>[src]
impl<'a, B: BitBlock> IntoIterator for &'a BitSet<B>