Struct BitSet
pub struct BitSet<B = u32> { /* private fields */ }
Implementations
impl BitSet<u32>
fn new() -> SelfCreates a new empty
BitSet.Examples
use BitSet; let mut s = new;fn with_capacity(nbits: usize) -> SelfCreates a new
BitSetwith initially no contents, able to holdnbitselements without resizing.Examples
use BitSet; let mut s = with_capacity; assert!;fn from_bit_vec(bit_vec: BitVec) -> SelfCreates a new
BitSetfrom the given bit vector.Examples
extern crate bit_vec; extern crate bit_set;fn from_bytes(bytes: &[u8]) -> Self
impl<B: BitBlock> BitSet<B>
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 BitSet; let mut s = with_capacity; assert!;fn reserve_len(&mut self, len: usize)Reserves capacity for the given
BitSetto containlendistinct elements. In the case ofBitSetthis means reallocations will not occur as long as all inserted elements are less thanlen.The collection may reserve more space to avoid frequent reallocations.
Examples
use BitSet; let mut s = new; s.reserve_len; assert!;fn reserve_len_exact(&mut self, len: usize)Reserves the minimum capacity for the given
BitSetto containlendistinct elements. In the case ofBitSetthis means reallocations will not occur as long as all inserted elements are less thanlen.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_lenif future insertions are expected.Examples
use BitSet; let mut s = new; s.reserve_len_exact; assert!;fn into_bit_vec(self) -> BitVec<B>Consumes this set to return the underlying bit vector.
Examples
use BitSet; let mut s = new; s.insert; s.insert; let bv = s.into_bit_vec; assert!; assert!;fn get_ref(&self) -> &BitVec<B>Returns a reference to the underlying bit vector.
Examples
use BitSet; let mut set = new; set.insert; let bv = set.get_ref; assert_eq!;fn get_mut(&mut self) -> &mut BitVec<B>Returns a mutable reference to the underlying bit vector.
Examples
use BitSet; let mut set = new; set.insert; set.insert; assert!; assert!; assert!;fn shrink_to_fit(&mut self)Truncates the underlying vector to the least length required.
Examples
use BitSet; let mut s = new; s.insert; s.remove; // Internal storage will probably be bigger than necessary println!; assert!; // Now should be smaller s.shrink_to_fit; println!;fn iter(&self) -> Iter<'_, B>Iterator over each usize stored in the
BitSet.Examples
use BitSet; let s = from_bytes; // Print 1, 4, 6 in arbitrary order for x in s.iterfn union<'a>(&'a self, other: &'a Self) -> Union<'a, B>Iterator over each usize stored in
selfunionother. Seeunion_withfor an efficient in-place version.Examples
use BitSet; let a = from_bytes; let b = from_bytes; // Print 0, 1, 2, 4 in arbitrary order for x in a.unionfn intersection<'a>(&'a self, other: &'a Self) -> Intersection<'a, B>Iterator over each usize stored in
selfintersectother. Seeintersect_withfor an efficient in-place version.Examples
use BitSet; let a = from_bytes; let b = from_bytes; // Print 2 for x in a.intersectionfn difference<'a>(&'a self, other: &'a Self) -> Difference<'a, B>Iterator over each usize stored in the
selfsetminusother. Seedifference_withfor an efficient in-place version.Examples
use BitSet; let a = from_bytes; let b = from_bytes; // Print 1, 4 in arbitrary order for x in a.difference // Note that difference is not symmetric, // and `b - a` means something else. // This prints 0 for x in b.differencefn symmetric_difference<'a>(&'a self, other: &'a Self) -> SymmetricDifference<'a, B>Iterator over each usize stored in the symmetric difference of
selfandother. Seesymmetric_difference_withfor an efficient in-place version.Examples
use BitSet; let a = from_bytes; let b = from_bytes; // Print 0, 1, 4 in arbitrary order for x in a.symmetric_differencefn union_with(&mut self, other: &Self)Unions in-place with the specified other bit vector.
Examples
use BitSet; let a = 0b01101000; let b = 0b10100000; let res = 0b11101000; let mut a = from_bytes; let b = from_bytes; let res = from_bytes; a.union_with; assert_eq!;fn intersect_with(&mut self, other: &Self)Intersects in-place with the specified other bit vector.
Examples
use BitSet; let a = 0b01101000; let b = 0b10100000; let res = 0b00100000; let mut a = from_bytes; let b = from_bytes; let res = from_bytes; a.intersect_with; assert_eq!;fn difference_with(&mut self, other: &Self)Makes this bit vector the difference with the specified other bit vector in-place.
Examples
use BitSet; let a = 0b01101000; let b = 0b10100000; let a_b = 0b01001000; // a - b let b_a = 0b10000000; // b - a let mut bva = from_bytes; let bvb = from_bytes; let bva_b = from_bytes; let bvb_a = from_bytes; bva.difference_with; assert_eq!; let bva = from_bytes; let mut bvb = from_bytes; bvb.difference_with; assert_eq!;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 BitSet; let a = 0b01101000; let b = 0b10100000; let res = 0b11001000; let mut a = from_bytes; let b = from_bytes; let res = from_bytes; a.symmetric_difference_with; assert_eq!;fn len(&self) -> usizeReturns the number of set bits in this set.
fn is_empty(&self) -> boolReturns whether there are no bits set in this set
fn clear(&mut self)Clears all bits in this set
fn contains(&self, value: usize) -> boolReturns
trueif this set contains the specified integer.fn is_disjoint(&self, other: &Self) -> boolReturns
trueif the set has no elements in common withother. This is equivalent to checking for an empty intersection.fn is_subset(&self, other: &Self) -> boolReturns
trueif the set is a subset of another.fn is_superset(&self, other: &Self) -> boolReturns
trueif the set is a superset of another.fn insert(&mut self, value: usize) -> boolAdds a value to the set. Returns
trueif the value was not already present in the set.fn remove(&mut self, value: usize) -> boolRemoves a value from the set. Returns
trueif the value was present in the set.fn truncate(&mut self, element: usize)Excludes
elementand all greater elements from theBitSet.
Trait Implementations
impl<B: BitBlock> Clone for BitSet<B>
fn clone(&self) -> Selffn clone_from(&mut self, other: &Self)
impl<B: BitBlock> Debug for BitSet<B>
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result
impl<B: BitBlock> Default for BitSet<B>
fn default() -> Self
impl<B: BitBlock> Eq for BitSet<B>
impl<B: BitBlock> Extend<usize> for BitSet<B>
fn extend<I: IntoIterator<Item = usize>>(&mut self, iter: I)
impl<B: BitBlock> FromIterator<usize> for BitSet<B>
fn from_iter<I: IntoIterator<Item = usize>>(iter: I) -> Self
impl<B: BitBlock> Hash for BitSet<B>
fn hash<H: Hasher>(&self, state: &mut H)
impl<B: BitBlock> Ord for BitSet<B>
fn cmp(&self, other: &Self) -> Ordering
impl<B: BitBlock> PartialEq for BitSet<B>
fn eq(&self, other: &Self) -> bool
impl<B: BitBlock> PartialOrd for BitSet<B>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Auto Trait Implementations
impl<B> Freeze for BitSet<B>
where
BitVec<B>: Freeze,
impl<B> RefUnwindSafe for BitSet<B>
where
BitVec<B>: RefUnwindSafe,
impl<B> Send for BitSet<B>
where
BitVec<B>: Send,
impl<B> Sync for BitSet<B>
where
BitVec<B>: Sync,
impl<B> Unpin for BitSet<B>
where
BitVec<B>: Unpin,
impl<B> UnsafeUnpin for BitSet<B>
where
BitVec<B>: UnsafeUnpin,
impl<B> UnwindSafe for BitSet<B>
where
BitVec<B>: UnwindSafe,
Blanket Implementations
impl<T> Any for BitSet<B>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for BitSet<B>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for BitSet<B>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for BitSet<B>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for BitSet<B>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for BitSet<B>
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for BitSet<B>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for BitSet<B>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for BitSet<B>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>