[−]Struct acute_ecs::systems::bit_set::BitSet
Implementations
impl BitSet<u32>
pub fn new() -> BitSet<u32>
pub fn with_capacity(nbits: usize) -> BitSet<u32>
Creates 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<u32>) -> BitSet<u32>
Creates 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]) -> BitSet<u32>
impl<B> BitSet<B> where
B: BitBlock,
B: BitBlock,
pub fn capacity(&self) -> usize
Returns 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)
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)
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>
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>
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)
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());
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); }
pub fn union(&'a self, other: &'a BitSet<B>) -> 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); }
pub fn intersection(&'a self, other: &'a BitSet<B>) -> Intersection<'a, B>ⓘNotable traits for Intersection<'a, B>
impl<'a, B> Iterator for Intersection<'a, B> where
B: BitBlock, type Item = usize;
Notable traits for Intersection<'a, B>
impl<'a, B> Iterator for Intersection<'a, B> where
B: BitBlock, type Item = usize;
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); }
pub fn difference(&'a self, other: &'a BitSet<B>) -> Difference<'a, B>ⓘNotable traits for Difference<'a, B>
impl<'a, B> Iterator for Difference<'a, B> where
B: BitBlock, type Item = usize;
Notable traits for Difference<'a, B>
impl<'a, B> Iterator for Difference<'a, B> where
B: BitBlock, type Item = usize;
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); }
pub fn symmetric_difference(
&'a self,
other: &'a BitSet<B>
) -> SymmetricDifference<'a, B>ⓘNotable traits for SymmetricDifference<'a, B>
impl<'a, B> Iterator for SymmetricDifference<'a, B> where
B: BitBlock, type Item = usize;
&'a self,
other: &'a BitSet<B>
) -> SymmetricDifference<'a, B>ⓘ
Notable traits for SymmetricDifference<'a, B>
impl<'a, B> Iterator for SymmetricDifference<'a, B> where
B: BitBlock, type Item = usize;
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: &BitSet<B>)
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: &BitSet<B>)
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: &BitSet<B>)
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: &BitSet<B>)
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
Returns the number of set bits in this set.
pub fn is_empty(&self) -> bool
Returns whether there are no bits set in this set
pub fn clear(&mut self)
Clears all bits in this set
pub fn contains(&self, value: usize) -> bool
Returns true
if this set contains the specified integer.
pub fn is_disjoint(&self, other: &BitSet<B>) -> bool
Returns 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: &BitSet<B>) -> bool
Returns true
if the set is a subset of another.
pub fn is_superset(&self, other: &BitSet<B>) -> bool
Returns true
if the set is a superset of another.
pub fn insert(&mut self, value: usize) -> bool
Adds 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
Removes a value from the set. Returns true
if the value was
present in the set.
Trait Implementations
impl<B> Clone for BitSet<B> where
B: BitBlock,
B: BitBlock,
fn clone(&self) -> BitSet<B>
fn clone_from(&mut self, other: &BitSet<B>)
impl<B> Debug for BitSet<B> where
B: BitBlock,
B: BitBlock,
impl<B> Default for BitSet<B> where
B: BitBlock,
B: BitBlock,
impl<B> Eq for BitSet<B> where
B: BitBlock,
B: BitBlock,
impl<B> Extend<usize> for BitSet<B> where
B: BitBlock,
B: BitBlock,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = usize>,
I: IntoIterator<Item = usize>,
fn extend_one(&mut self, item: A)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]
impl<B> FromIterator<usize> for BitSet<B> where
B: BitBlock,
B: BitBlock,
fn from_iter<I>(iter: I) -> BitSet<B> where
I: IntoIterator<Item = usize>,
I: IntoIterator<Item = usize>,
impl<B> Hash for BitSet<B> where
B: BitBlock,
B: BitBlock,
fn hash<H>(&self, state: &mut H) where
H: Hasher,
H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a, B> IntoIterator for &'a BitSet<B> where
B: BitBlock,
B: BitBlock,
type Item = usize
The type of the elements being iterated over.
type IntoIter = Iter<'a, B>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Iter<'a, B>ⓘ
impl<B> Ord for BitSet<B> where
B: BitBlock,
B: BitBlock,
fn cmp(&self, other: &BitSet<B>) -> Ordering
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<B> PartialEq<BitSet<B>> for BitSet<B> where
B: BitBlock,
B: BitBlock,
impl<B> PartialOrd<BitSet<B>> for BitSet<B> where
B: BitBlock,
B: BitBlock,
Auto Trait Implementations
impl<B> RefUnwindSafe for BitSet<B> where
B: RefUnwindSafe,
B: RefUnwindSafe,
impl<B> Send for BitSet<B> where
B: Send,
B: Send,
impl<B> Sync for BitSet<B> where
B: Sync,
B: Sync,
impl<B> Unpin for BitSet<B> where
B: Unpin,
B: Unpin,
impl<B> UnwindSafe for BitSet<B> where
B: UnwindSafe,
B: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Component for T where
T: 'static + Send + Sync,
T: 'static + Send + Sync,
impl<T> Downcast for T where
T: Any,
T: Any,
fn into_any(self: Box<T>) -> Box<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
impl<T> DowncastSync for T where
T: Send + Sync + Any,
T: Send + Sync + Any,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Resource for T where
T: 'static + Send + Sync,
T: 'static + Send + Sync,
impl<T> Tag for T where
T: 'static + Clone + PartialEq<T> + Send + Sync,
T: 'static + Clone + PartialEq<T> + Send + Sync,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,