Skip to main content

IndexSet

Enum IndexSet 

Source
pub enum IndexSet {
    Small(u32),
    Medium(u64),
    Large(u128),
    Heap(Vec<u64>),
}
Expand description

A compact bitset for tracking slot indices in CSE.

Uses stack-optimized representations for small sizes (up to 32, 64, and 128 bits) and falls back to a heap-allocated Vec<u64> for larger sets.

Variants§

§

Small(u32)

Up to 32 bits stored inline.

§

Medium(u64)

33–64 bits stored inline.

§

Large(u128)

65–128 bits stored inline.

§

Heap(Vec<u64>)

More than 128 bits, stored as a heap-allocated vector of 64-bit chunks.

Implementations§

Source§

impl IndexSet

Source

pub fn singleton(slot: usize) -> Self

Create a set containing exactly one slot index.

§Examples
let s = IndexSet::singleton(5);
assert!(s.contains(5));
assert!(!s.contains(4));
Source

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

Insert or remove a slot index.

Automatically promotes the representation when the slot exceeds the current variant’s capacity.

§Examples
let mut s = IndexSet::default();
s.insert(1, true);
assert!(s.contains(1));
s.insert(1, false);
assert!(!s.contains(1));
Source

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

Returns true if the two sets have no elements in common.

§Examples
let a = IndexSet::singleton(0);
let b = IndexSet::singleton(1);
assert!(a.is_disjoint(&b));
let c = IndexSet::singleton(0);
assert!(!a.is_disjoint(&c));
Source

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

Returns true if the given slot index is present in the set.

§Examples
let s = IndexSet::singleton(3);
assert!(s.contains(3));
assert!(!s.contains(0));
Source

pub fn iter(&self) -> IndexSetIter<'_> ⓘ

Iterate over all slot indices present in the set, in ascending order.

§Examples
let mut s = IndexSet::singleton(2);
s.insert(5, true);
let slots: Vec<usize> = s.iter().collect();
assert_eq!(slots, vec![2, 5]);
Source

pub fn count_ones(&self) -> usize

Returns the number of slot indices in the set (population count).

§Examples
let mut s = IndexSet::singleton(0);
s.insert(2, true);
s.insert(5, true);
assert_eq!(s.count_ones(), 3);
Source

pub fn is_empty(&self) -> bool

Returns true if the set contains no elements.

§Examples
let mut s: IndexSet = Default::default();
assert!(s.is_empty());
s.insert(0, true);
assert!(!s.is_empty());
Source

pub fn minimized(self) -> Self

Shrink to the smallest variant that can hold the current bits.

Returns self for chaining; see also minimize.

§Examples
let s = IndexSet::Large(0).minimized();
assert!(matches!(s, IndexSet::Small(_)));
Source

pub fn minimize(&mut self)

Shrink to the smallest variant that can hold the current bits.

Mutates self; see also minimized.

§Examples
let mut s = IndexSet::Large(0);
s.minimize();
assert!(matches!(s, IndexSet::Small(_)));

Trait Implementations§

Source§

impl BitAnd for IndexSet

Source§

type Output = IndexSet

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitAndAssign for IndexSet

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitOr for IndexSet

Source§

type Output = IndexSet

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOrAssign for IndexSet

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl Clone for IndexSet

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for IndexSet

Source§

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

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

impl Default for IndexSet

Source§

fn default() -> Self

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

impl Eq for IndexSet

Source§

impl From<ArithIndexSet> for IndexSet

Source§

fn from(set: ArithIndexSet) -> Self

Converts to this type from the input type.
Source§

impl From<IndexSet> for ArithIndexSet

Source§

fn from(set: IndexSet) -> Self

Converts to this type from the input type.
Source§

impl From<IndexSet> for Vec<u64>

Source§

fn from(set: IndexSet) -> Self

Converts to this type from the input type.
Source§

impl Hash for IndexSet

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<'a> IntoIterator for &'a IndexSet

Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = IndexSetIter<'a>

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 Ord for IndexSet

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for IndexSet

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for IndexSet

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Shl<usize> for IndexSet

Source§

type Output = IndexSet

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: usize) -> Self

Performs the << operation. Read more
Source§

impl ShlAssign<usize> for IndexSet

Source§

fn shl_assign(&mut self, rhs: usize)

Performs the <<= operation. Read more
Source§

impl Shr<usize> for IndexSet

Source§

type Output = IndexSet

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: usize) -> Self

Performs the >> operation. Read more
Source§

impl ShrAssign<usize> for IndexSet

Source§

fn shr_assign(&mut self, rhs: usize)

Performs the >>= operation. Read more

Auto Trait Implementations§

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.