Struct Bitset

Source
pub struct Bitset<N, B = usize>
where B: Primitive, N: CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>,
{ /* private fields */ }
Expand description

A set of unsigned integers whose size is fixed at compile-time.

A Bitset can only store unsigned integers less than N, where N is a compile-time integer from typenum. A Bitset uses a single bit to indicate the presence or absence of each value.

Implementations§

Source§

impl<N, B> Bitset<N, B>
where B: Primitive, N: Unsigned + CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>,

Source

pub fn new() -> Self

Returns an empty bitset.

Source

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

Returns true if the bitset contains a value.

Panics if value >= N.

Source

pub fn insert(&mut self, value: usize)

Inserts a value into the bitset.

If that value already exists in the bitset, this function has no effect.

Panics if value >= N.

Source

pub fn remove(&mut self, value: usize)

Removes a value from the bitset.

If that value does not already exist in the bitset, this function has no effect.

Panics if value >= N.

Source

pub fn is_empty(&self) -> bool

Returns true if the bitset contains no bits.

Source

pub fn len(&self) -> usize

Returns the number of values contained in the bitset.

Source

pub fn iter(&self) -> impl '_ + Iterator<Item = usize> + Clone

Returns an iterator over the values in the bitset.

Source

pub fn clear(&mut self)

Clears the bitset, removing all values.

Source

pub fn union<'a>(&'a self, other: &'a Self) -> impl 'a + Iterator<Item = usize>

Returns an iterator over self | other.

Source

pub fn intersection<'a>( &'a self, other: &'a Self, ) -> impl 'a + Iterator<Item = usize>

Returns an iterator over self & other.

Source

pub fn symmetric_difference<'a>( &'a self, other: &'a Self, ) -> impl 'a + Iterator<Item = usize>

Returns an iterator over self ^ other.

Source

pub fn difference<'a>( &'a self, other: &'a Self, ) -> impl 'a + Iterator<Item = usize>

Returns an iterator over self - other.

Source

pub fn is_disjoint(&self, other: &Self) -> bool

Returns true if self has no elements in common with other.

This is more efficient than self.intersection(other).next().is_none().

Source

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

Returns true if every element in self exists in other.

Source

pub fn is_superset(&self, other: &Self) -> bool

Returns true if every element in other exists in self.

Trait Implementations§

Source§

impl<'a, 'b, N, B> BitAnd<&'b Bitset<N, B>> for &'a Bitset<N, B>
where B: Primitive, N: Unsigned + CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>, Bitset<N, B>: Clone,

Intersection

Source§

type Output = Bitset<N, B>

The resulting type after applying the & operator.
Source§

fn bitand(self, other: &'b Bitset<N, B>) -> Self::Output

Performs the & operation. Read more
Source§

impl<N, B> BitAndAssign<&Bitset<N, B>> for Bitset<N, B>
where B: Primitive, N: Unsigned + CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>,

Intersection

Source§

fn bitand_assign(&mut self, other: &Self)

Performs the &= operation. Read more
Source§

impl<'a, 'b, N, B> BitOr<&'b Bitset<N, B>> for &'a Bitset<N, B>
where B: Primitive, N: Unsigned + CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>, Bitset<N, B>: Clone,

Union

Source§

type Output = Bitset<N, B>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: &'b Bitset<N, B>) -> Self::Output

Performs the | operation. Read more
Source§

impl<N, B> BitOrAssign<&Bitset<N, B>> for Bitset<N, B>
where B: Primitive, N: Unsigned + CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>,

Union

Source§

fn bitor_assign(&mut self, other: &Self)

Performs the |= operation. Read more
Source§

impl<'a, 'b, N, B> BitXor<&'b Bitset<N, B>> for &'a Bitset<N, B>
where B: Primitive, N: Unsigned + CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>, Bitset<N, B>: Clone,

Symmetric Difference

Source§

type Output = Bitset<N, B>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: &'b Bitset<N, B>) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<N, B> BitXorAssign<&Bitset<N, B>> for Bitset<N, B>
where B: Primitive, N: Unsigned + CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>,

Symmetric Difference

Source§

fn bitxor_assign(&mut self, other: &Self)

Performs the ^= operation. Read more
Source§

impl<N, B> Clone for Bitset<N, B>
where B: Primitive, N: CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>,

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<N, B> Debug for Bitset<N, B>
where B: Primitive, N: Unsigned + CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<N, B> Default for Bitset<N, B>
where B: Primitive, N: CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<N, B> FromIterator<usize> for Bitset<N, B>
where B: Primitive, N: Unsigned + CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>,

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = usize>,

Creates a value from an iterator. Read more
Source§

impl<N, B> PartialEq for Bitset<N, B>
where B: Primitive, N: CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b, N, B> Sub<&'b Bitset<N, B>> for &'a Bitset<N, B>
where B: Primitive, N: Unsigned + CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>, Bitset<N, B>: Clone,

Difference

Source§

type Output = Bitset<N, B>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &'b Bitset<N, B>) -> Self::Output

Performs the - operation. Read more
Source§

impl<N, B> SubAssign<&Bitset<N, B>> for Bitset<N, B>
where B: Primitive, N: Unsigned + CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>,

Difference

Source§

fn sub_assign(&mut self, other: &Self)

Performs the -= operation. Read more
Source§

impl<N, B> Copy for Bitset<N, B>
where B: Primitive, N: CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>, GenericArray<B, <N as CeilDiv<B::Size>>::Output>: Copy,

Source§

impl<N, B> Eq for Bitset<N, B>
where B: Primitive, N: CeilDiv<B::Size>, <N as CeilDiv<B::Size>>::Output: ArrayLength<B>,

Auto Trait Implementations§

§

impl<N, B> Freeze for Bitset<N, B>
where <N as CeilDiv<<B as Primitive>::Size>>::Output: Sized, <<N as CeilDiv<<B as Primitive>::Size>>::Output as ArrayLength<B>>::ArrayType: Freeze,

§

impl<N, B> RefUnwindSafe for Bitset<N, B>
where <N as CeilDiv<<B as Primitive>::Size>>::Output: Sized, <<N as CeilDiv<<B as Primitive>::Size>>::Output as ArrayLength<B>>::ArrayType: RefUnwindSafe,

§

impl<N, B> Send for Bitset<N, B>
where <N as CeilDiv<<B as Primitive>::Size>>::Output: Sized, B: Send,

§

impl<N, B> Sync for Bitset<N, B>
where <N as CeilDiv<<B as Primitive>::Size>>::Output: Sized, B: Sync,

§

impl<N, B> Unpin for Bitset<N, B>
where <N as CeilDiv<<B as Primitive>::Size>>::Output: Sized, <<N as CeilDiv<<B as Primitive>::Size>>::Output as ArrayLength<B>>::ArrayType: Unpin,

§

impl<N, B> UnwindSafe for Bitset<N, B>
where <N as CeilDiv<<B as Primitive>::Size>>::Output: Sized, <<N as CeilDiv<<B as Primitive>::Size>>::Output as ArrayLength<B>>::ArrayType: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.