IttyBitty

Struct IttyBitty 

Source
pub struct IttyBitty<const N: usize> { /* private fields */ }
Expand description

A memory-access optimized dynamically sized bitset.

IttyBitty<N> is backed by a [usize; N], but can spill to heap allocation.

Implementations§

Source§

impl<const N: usize> IttyBitty<N>

Source

pub const fn new() -> Self

Create an empty inline IttyBitty

Source

pub fn with_capacity(bits: usize) -> Self

Create an empty inline IttyBitty with enough capacity to hold bits

Source

pub fn capacity(&self) -> usize

Get the current capacity of the IttyBitty

Source

pub unsafe fn get_unchecked(&self, bit: usize) -> bool

Get the bit at bit without bounds checks.

§Safety

bit must be less than self::capacity().

Source

pub unsafe fn set_unchecked(&mut self, bit: usize, val: bool)

Set the bit at bit without bounds checks.

§Safety

bit must be less than self::capacity().

Source

pub fn get(&self, bit: usize) -> bool

Get the bit at bit. Returns false if beyond capacity.

Source

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

Set the bit at bit to value. Extends capacity as needed if value is true, no-op if false and beyond bounds.

Source

pub fn clear(&mut self)

Set all bits to false.

Source

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

Set bit and all bits beyond it to false.

Source

pub fn iter(&self) -> Iter<'_, N>

Iterate over true bits.

Source

pub fn iter_rev(&self) -> IterRev<'_, N>

Iterate over true bits backwards.

Source

pub fn next_set_bit(&self, bit: usize) -> usize

Gets the first true bit at or after bit.

Source

pub fn prev_set_bit(&self, bit: usize) -> usize

Gets the first true bit before bit.

Trait Implementations§

Source§

impl<const N: usize> Debug for IttyBitty<N>

Source§

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

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

impl<const N: usize> Default for IttyBitty<N>

Source§

fn default() -> Self

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

impl<const N: usize> Drop for IttyBitty<N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<const N: usize> Index<usize> for IttyBitty<N>

Source§

type Output = bool

The returned type after indexing.
Source§

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

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

impl<'a, const N: usize> IntoIterator for &'a IttyBitty<N>

Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, N>

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

fn into_iter(self) -> Iter<'a, N>

Creates an iterator from a value. Read more
Source§

impl<const N: usize> IntoIterator for IttyBitty<N>

Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<N>

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

fn into_iter(self) -> IntoIter<N>

Creates an iterator from a value. Read more
Source§

impl<const N: usize> PartialEq for IttyBitty<N>

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<const N: usize> Eq for IttyBitty<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for IttyBitty<N>

§

impl<const N: usize> RefUnwindSafe for IttyBitty<N>

§

impl<const N: usize> Send for IttyBitty<N>

§

impl<const N: usize> Sync for IttyBitty<N>

§

impl<const N: usize> Unpin for IttyBitty<N>

§

impl<const N: usize> UnwindSafe for IttyBitty<N>

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