Struct bitarray_set::BitArraySet
[−]
[src]
pub struct BitArraySet<B: BitsIn, NBits: Unsigned + NonZero> where NBits: Add<B::Output>, NBits::Output: Sub<B1>, NBits::Output::Output: Div<B::Output>, NBits::Output::Output::Output: ArrayLength<B> {
// some fields omitted
}
Methods
impl<B: BitsIn + BitBlock + Default, NBits: Unsigned + NonZero> BitArraySet<B, NBits> where NBits: Add<B::Output>, NBits::Output: Sub<B1>, NBits::Output::Output: Div<B::Output>, NBits::Output::Output::Output: ArrayLength<B>
[src]
fn new() -> Self
Creates a new empty BitArraySet
.
Examples
extern crate typenum; use typenum::{Unsigned, U8}; use bitarray_set::BitArraySet; let mut s = BitArraySet::<u32, U8>::new();
fn from_bit_array(bit_array: BitArray<B, NBits>) -> Self
Creates a new BitArraySet
from the given bit array.
Examples
extern crate typenum; extern crate bit_array; extern crate bitarray_set; use typenum::{Unsigned, U8}; use bit_array::BitArray; use bitarray_set::BitArraySet; fn main() { let bv = BitArray::<u32, U8>::from_bytes(&[0b01100000]); let s = BitArraySet::from_bit_array(bv); // Print 1, 2 in arbitrary order for x in s.iter() { println!("{}", x); } }
fn from_bytes(bytes: &[u8]) -> Self
fn into_bit_array(self) -> BitArray<B, NBits>
Consumes this set to return the underlying bit array.
Examples
extern crate typenum; use typenum::{Unsigned, U8}; use bitarray_set::BitArraySet; let mut s = BitArraySet::<u32, U8>::new(); s.insert(0); s.insert(3); let bv = s.into_bit_array(); assert!(bv[0]); assert!(bv[3]);
fn get_ref(&self) -> &BitArray<B, NBits>
Returns a reference to the underlying bit array.
Examples
extern crate typenum; use typenum::{Unsigned, U8}; use bitarray_set::BitArraySet; let mut s = BitArraySet::<u32, U8>::new(); s.insert(0); let bv = s.get_ref(); assert_eq!(bv[0], true);
fn iter(&self) -> Iter<B>
Iterator over each usize stored in the BitArraySet
.
Examples
extern crate typenum; use typenum::{Unsigned, U8}; use bitarray_set::BitArraySet; let s = BitArraySet::<u32, U8>::from_bytes(&[0b01001010]); // Print 1, 4, 6 in arbitrary order for x in s.iter() { println!("{}", x); }
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
extern crate typenum; use typenum::{Unsigned, U8}; use bitarray_set::BitArraySet; let a = BitArraySet::<u32, U8>::from_bytes(&[0b01101000]); let b = BitArraySet::<u32, U8>::from_bytes(&[0b10100000]); // Print 0, 1, 2, 4 in arbitrary order for x in a.union(&b) { println!("{}", x); }
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
extern crate typenum; use typenum::{Unsigned, U8}; use bitarray_set::BitArraySet; let a = BitArraySet::<u32, U8>::from_bytes(&[0b01101000]); let b = BitArraySet::<u32, U8>::from_bytes(&[0b10100000]); // Print 2 for x in a.intersection(&b) { println!("{}", x); }
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
extern crate typenum; use typenum::{Unsigned, U8}; use bitarray_set::BitArraySet; let a = BitArraySet::<u32, U8>::from_bytes(&[0b01101000]); let b = BitArraySet::<u32, U8>::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); }
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
extern crate typenum; use typenum::{Unsigned, U8}; use bitarray_set::BitArraySet; let a = BitArraySet::<u32, U8>::from_bytes(&[0b01101000]); let b = BitArraySet::<u32, U8>::from_bytes(&[0b10100000]); // Print 0, 1, 4 in arbitrary order for x in a.symmetric_difference(&b) { println!("{}", x); }
fn union_with(&mut self, other: &Self)
Unions in-place with the specified other bit array.
Examples
extern crate typenum; use typenum::{Unsigned, U8}; use bitarray_set::BitArraySet; let a = 0b01101000; let b = 0b10100000; let res = 0b11101000; let mut a = BitArraySet::<u32, U8>::from_bytes(&[a]); let b = BitArraySet::<u32, U8>::from_bytes(&[b]); let res = BitArraySet::<u32, U8>::from_bytes(&[res]); a.union_with(&b); assert_eq!(a, res);
fn intersect_with(&mut self, other: &Self)
Intersects in-place with the specified other bit array.
Examples
extern crate typenum; use typenum::{Unsigned, U8}; use bitarray_set::BitArraySet; let a = 0b01101000; let b = 0b10100000; let res = 0b00100000; let mut a = BitArraySet::<u32, U8>::from_bytes(&[a]); let b = BitArraySet::<u32, U8>::from_bytes(&[b]); let res = BitArraySet::<u32, U8>::from_bytes(&[res]); a.intersect_with(&b); assert_eq!(a, res);
fn difference_with(&mut self, other: &Self)
Makes this bit array the difference with the specified other bit array in-place.
Examples
extern crate typenum; use typenum::{Unsigned, U8}; use bitarray_set::BitArraySet; let a = 0b01101000; let b = 0b10100000; let a_b = 0b01001000; // a - b let b_a = 0b10000000; // b - a let mut bva = BitArraySet::<u32, U8>::from_bytes(&[a]); let bvb = BitArraySet::<u32, U8>::from_bytes(&[b]); let bva_b = BitArraySet::<u32, U8>::from_bytes(&[a_b]); let bvb_a = BitArraySet::<u32, U8>::from_bytes(&[b_a]); bva.difference_with(&bvb); assert_eq!(bva, bva_b); let bva = BitArraySet::<u32, U8>::from_bytes(&[a]); let mut bvb = BitArraySet::<u32, U8>::from_bytes(&[b]); bvb.difference_with(&bva); assert_eq!(bvb, bvb_a);
fn symmetric_difference_with(&mut self, other: &Self)
Makes this bit array the symmetric difference with the specified other bit array in-place.
Examples
extern crate typenum; use typenum::{Unsigned, U8}; use bitarray_set::BitArraySet; let a = 0b01101000; let b = 0b10100000; let res = 0b11001000; let mut a = BitArraySet::<u32, U8>::from_bytes(&[a]); let b = BitArraySet::<u32, U8>::from_bytes(&[b]); let res = BitArraySet::<u32, U8>::from_bytes(&[res]); a.symmetric_difference_with(&b); assert_eq!(a, res);
fn len(&self) -> usize
Returns the number of set bits in this set.
fn is_empty(&self) -> bool
Returns whether there are no bits set in this set
fn clear(&mut self)
Clears all bits in this set
fn contains(&self, value: usize) -> bool
Returns true
if this set contains the specified integer.
fn is_disjoint(&self, other: &Self) -> bool
Returns true
if the set has no elements in common with other
.
This is equivalent to checking for an empty intersection.
fn is_subset(&self, other: &Self) -> bool
Returns true
if the set is a subset of another.
fn is_superset(&self, other: &Self) -> bool
Returns true
if the set is a superset of another.
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.
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: BitsIn + BitBlock + Default, NBits: Unsigned + NonZero> Clone for BitArraySet<B, NBits> where NBits: Add<B::Output>, NBits::Output: Sub<B1>, NBits::Output::Output: Div<B::Output>, NBits::Output::Output::Output: ArrayLength<B>
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, other: &Self)
Performs copy-assignment from source
. Read more
impl<B: BitsIn + BitBlock + Default, NBits: Unsigned + NonZero> Default for BitArraySet<B, NBits> where NBits: Add<B::Output>, NBits::Output: Sub<B1>, NBits::Output::Output: Div<B::Output>, NBits::Output::Output::Output: ArrayLength<B>
[src]
impl<B: BitsIn + BitBlock + Default, NBits: Unsigned + NonZero> FromIterator<usize> for BitArraySet<B, NBits> where NBits: Add<B::Output>, NBits::Output: Sub<B1>, NBits::Output::Output: Div<B::Output>, NBits::Output::Output::Output: ArrayLength<B>
[src]
fn from_iter<I: IntoIterator<Item=usize>>(iter: I) -> Self
Creates a value from an iterator. Read more
impl<B: BitsIn + BitBlock + Default + BitAnd + BitOr, NBits: Unsigned + NonZero> Extend<usize> for BitArraySet<B, NBits> where NBits: Add<B::Output>, NBits::Output: Sub<B1>, NBits::Output::Output: Div<B::Output>, NBits::Output::Output::Output: ArrayLength<B>
[src]
fn extend<I: IntoIterator<Item=usize>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
impl<B: BitsIn + BitBlock + Default, NBits: Unsigned + NonZero> PartialOrd for BitArraySet<B, NBits> where NBits: Add<B::Output>, NBits::Output: Sub<B1>, NBits::Output::Output: Div<B::Output>, NBits::Output::Output::Output: ArrayLength<B>
[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) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<B: BitsIn + BitBlock + Default, NBits: Unsigned + NonZero> Ord for BitArraySet<B, NBits> where NBits: Add<B::Output>, NBits::Output: Sub<B1>, NBits::Output::Output: Div<B::Output>, NBits::Output::Output::Output: ArrayLength<B>
[src]
fn cmp(&self, other: &Self) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl<B: BitsIn + BitBlock + Default, NBits: Unsigned + NonZero> PartialEq for BitArraySet<B, NBits> where NBits: Add<B::Output>, NBits::Output: Sub<B1>, NBits::Output::Output: Div<B::Output>, NBits::Output::Output::Output: ArrayLength<B>
[src]
fn eq(&self, other: &Self) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl<B: BitsIn + BitBlock + Default, NBits: Unsigned + NonZero> Eq for BitArraySet<B, NBits> where NBits: Add<B::Output>, NBits::Output: Sub<B1>, NBits::Output::Output: Div<B::Output>, NBits::Output::Output::Output: ArrayLength<B>
[src]
impl<B: BitsIn + BitBlock + Default, NBits: Unsigned + NonZero> Debug for BitArraySet<B, NBits> where NBits: Add<B::Output>, NBits::Output: Sub<B1>, NBits::Output::Output: Div<B::Output>, NBits::Output::Output::Output: ArrayLength<B>
[src]
impl<B: BitsIn + BitBlock + Default, NBits: Unsigned + NonZero> Hash for BitArraySet<B, NBits> where NBits: Add<B::Output>, NBits::Output: Sub<B1>, NBits::Output::Output: Div<B::Output>, NBits::Output::Output::Output: ArrayLength<B>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0
Feeds a slice of this type into the state provided.