Struct tinybitset::TinyBitSet

source ·
pub struct TinyBitSet<T: BitBlock, const N: usize> { /* private fields */ }
Expand description

A small, fixed size bitset that stores its data inline.

Storage and indexing

The bitsets storage consists of N blocks of type T, where T is any of the unsigned integer types implementing BitBlock. Thus, the bitset has a fixed size of T::BITS * N bits can be freely converted to and from the array of blocks.

The bits are indexed from front to back within the array of blocks, and from least significant to most significant within each block. Thus, the bit with index i is stored in the (i / T::BITS)-th block in the (i % T::BITS)-th least significant bit.

Implementations§

source§

impl<T: BitBlock, const N: usize> TinyBitSet<T, N>

source

pub const CAPACITY: usize = _

Number of bits in the bitset.

source

pub const EMPTY: Self = _

Bitset with no bits set.

source

pub const ALL: Self = _

Bitset with all bits set.

source

pub const fn new() -> Self

Creates an empty bitset.

Equivalent to Self::EMPTY.

source

pub fn singleton(bit: usize) -> Self

Creates a bitset with exactly one bit set.

Panics

Panics if bit >= Self::CAPACITY.

source

pub const fn capacity(self) -> usize

Number of bits in the bitset.

Equivalent to Self::CAPACITY.

source

pub fn len(self) -> usize

Counts the number of bits that are set.

source

pub fn is_empty(self) -> bool

Returns whether no bits are set.

source

pub fn iter(self) -> IntoIter<T, N>

Iterates over the indices of set bits from lowest to highest.

source

pub fn iter_missing(self) -> IntoIter<T, N>

Iterates over the indices of unset bits from lowest to highest.

source

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

Set the given bit.

Panics

Panics if bit >= Self::CAPACITY.

source

pub fn inserted(self, bit: usize) -> Self

Return a new bitset with the given bit set.

Panics

Panics if bit >= Self::CAPACITY.

source

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

Unset the given bit.

Panics

Panics if bit >= Self::CAPACITY.

source

pub fn removed(self, bit: usize) -> Self

Return a new bitset with the given bit unset.

Panics

Panics if bit >= Self::CAPACITY.

source

pub fn toggle(&mut self, bit: usize)

Flip the given bit.

Panics

Panics if bit >= Self::CAPACITY.

source

pub fn toggled(self, bit: usize) -> Self

Return a new bitset with the given bit flipped.

Panics

Panics if bit >= Self::CAPACITY.

source

pub fn assign(&mut self, bit: usize, value: bool)

Sets the given bit to the given value.

Panics

Panics if bit >= Self::CAPACITY.

source

pub fn assigned(self, bit: usize, value: bool) -> Self

Return a new bitset with the given bit set to the given value.

Panics

Panics if bit >= Self::CAPACITY.

Trait Implementations§

source§

impl<T: BitBlock, const N: usize> Binary for TinyBitSet<T, N>

source§

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

Formats the value using the given formatter.
source§

impl<T: BitBlock, const N: usize> BitAnd for TinyBitSet<T, N>

source§

fn bitand(self, rhs: Self) -> Self::Output

Returns a bitset with all bits that are set in both self and rhs.

§

type Output = TinyBitSet<T, N>

The resulting type after applying the & operator.
source§

impl<T: BitBlock, const N: usize> BitAndAssign for TinyBitSet<T, N>

source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
source§

impl<T: BitBlock, const N: usize> BitOr for TinyBitSet<T, N>

source§

fn bitor(self, rhs: Self) -> Self::Output

Returns a bitset with all bits that are set in either self or rhs.

§

type Output = TinyBitSet<T, N>

The resulting type after applying the | operator.
source§

impl<T: BitBlock, const N: usize> BitOrAssign for TinyBitSet<T, N>

source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
source§

impl<T: BitBlock, const N: usize> BitXor for TinyBitSet<T, N>

source§

fn bitxor(self, rhs: Self) -> Self::Output

Returns a bitset with all bits that are set in exactly one of self and rhs.

§

type Output = TinyBitSet<T, N>

The resulting type after applying the ^ operator.
source§

impl<T: BitBlock, const N: usize> BitXorAssign for TinyBitSet<T, N>

source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
source§

impl<T: Clone + BitBlock, const N: usize> Clone for TinyBitSet<T, N>

source§

fn clone(&self) -> TinyBitSet<T, N>

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<T: BitBlock, const N: usize> Debug for TinyBitSet<T, N>

source§

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

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

impl<T: BitBlock, const N: usize> Default for TinyBitSet<T, N>

source§

fn default() -> Self

Returns Self::EMPTY.

source§

impl<T: BitBlock, const N: usize> Display for TinyBitSet<T, N>

source§

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

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

impl<T: BitBlock, const N: usize> From<[T; N]> for TinyBitSet<T, N>

source§

fn from(blocks: [T; N]) -> Self

Create a bitset from the underlying bit blocks.

See TinyBitSet for more information on how the bits are indexed.

source§

impl<T: BitBlock> From<T> for TinyBitSet<T, 1>

source§

fn from(block: T) -> Self

Create a bitset from the underlying bit block.

source§

impl<T: BitBlock, const N: usize> From<TinyBitSet<T, N>> for [T; N]

source§

fn from(bitset: TinyBitSet<T, N>) -> Self

Convert the bitset into the underlying bit blocks.

See TinyBitSet for more information on how the bits are indexed.

source§

impl From<TinyBitSet<u128, 1>> for u128

source§

fn from(bitset: TinyBitSet<u128, 1>) -> Self

Convert the bitset into the underlying bit block.

Due to the orphan rule, this cannot be covered by a blanket implementation and is thus separately implemented for all primitive integer types.

source§

impl From<TinyBitSet<u16, 1>> for u16

source§

fn from(bitset: TinyBitSet<u16, 1>) -> Self

Convert the bitset into the underlying bit block.

Due to the orphan rule, this cannot be covered by a blanket implementation and is thus separately implemented for all primitive integer types.

source§

impl From<TinyBitSet<u32, 1>> for u32

source§

fn from(bitset: TinyBitSet<u32, 1>) -> Self

Convert the bitset into the underlying bit block.

Due to the orphan rule, this cannot be covered by a blanket implementation and is thus separately implemented for all primitive integer types.

source§

impl From<TinyBitSet<u64, 1>> for u64

source§

fn from(bitset: TinyBitSet<u64, 1>) -> Self

Convert the bitset into the underlying bit block.

Due to the orphan rule, this cannot be covered by a blanket implementation and is thus separately implemented for all primitive integer types.

source§

impl From<TinyBitSet<u8, 1>> for u8

source§

fn from(bitset: TinyBitSet<u8, 1>) -> Self

Convert the bitset into the underlying bit block.

Due to the orphan rule, this cannot be covered by a blanket implementation and is thus separately implemented for all primitive integer types.

source§

impl<T: BitBlock, const N: usize> FromIterator<usize> for TinyBitSet<T, N>

source§

fn from_iter<I: IntoIterator<Item = usize>>(iter: I) -> Self

Creates a bitset with an iterator of indices of set bits.

Panics

Panics if any of the indices are out of range.

source§

impl<T: Hash + BitBlock, const N: usize> Hash for TinyBitSet<T, N>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: BitBlock, const N: usize> Index<usize> for TinyBitSet<T, N>

§

type Output = bool

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T: BitBlock, const N: usize> IntoIterator for &TinyBitSet<T, N>

§

type Item = usize

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T, N>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T: BitBlock, const N: usize> IntoIterator for TinyBitSet<T, N>

§

type Item = usize

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T, N>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T: BitBlock, const N: usize> LowerHex for TinyBitSet<T, N>

source§

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

Formats the value using the given formatter.
source§

impl<T: BitBlock, const N: usize> Not for TinyBitSet<T, N>

source§

fn not(self) -> Self::Output

Returns a bitset with all bits flipped.

§

type Output = TinyBitSet<T, N>

The resulting type after applying the ! operator.
source§

impl<T: Ord + BitBlock, const N: usize> Ord for TinyBitSet<T, N>

source§

fn cmp(&self, other: &TinyBitSet<T, N>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T: PartialEq + BitBlock, const N: usize> PartialEq for TinyBitSet<T, N>

source§

fn eq(&self, other: &TinyBitSet<T, N>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd + BitBlock, const N: usize> PartialOrd for TinyBitSet<T, N>

source§

fn partial_cmp(&self, other: &TinyBitSet<T, N>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: BitBlock, const N: usize> UpperHex for TinyBitSet<T, N>

source§

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

Formats the value using the given formatter.
source§

impl<T: Copy + BitBlock, const N: usize> Copy for TinyBitSet<T, N>

source§

impl<T: Eq + BitBlock, const N: usize> Eq for TinyBitSet<T, N>

source§

impl<T: BitBlock, const N: usize> StructuralEq for TinyBitSet<T, N>

source§

impl<T: BitBlock, const N: usize> StructuralPartialEq for TinyBitSet<T, N>

Auto Trait Implementations§

§

impl<T, const N: usize> RefUnwindSafe for TinyBitSet<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for TinyBitSet<T, N>
where T: Send,

§

impl<T, const N: usize> Sync for TinyBitSet<T, N>
where T: Sync,

§

impl<T, const N: usize> Unpin for TinyBitSet<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for TinyBitSet<T, N>
where T: 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> 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> ToOwned for T
where T: Clone,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.