Skip to main content

Set

Struct Set 

Source
pub struct Set<K = IndexKey> { /* private fields */ }
Expand description

A finite, ordered index set, parameterized by the type K its keys decode to.

K is a phantom marker: the runtime representation is the same erased payload regardless of K, so carrying the key type costs nothing at runtime. It exists so the variable!/constraint!/sum! macros can infer the closure parameter type from the set instead of requiring an annotation.

Supports integer ranges (K = usize), string lists (K = String), and arbitrary tuple lists (built via Set::product / the &a * &b operator.

axes is Some exactly when the set is a dense integer grid and records the per-axis extents. It is None for string sets, sparse/from_ints sets, and any filtered set.

Implementations§

Source§

impl<K> Set<K>

Source

pub fn tuples<I, T>(iter: I) -> Self
where I: IntoIterator<Item = T>, T: Into<IndexTuple>,

Build a tuple set directly from an iterator of keys.

Source

pub fn filter<F>(&self, f: F) -> Self
where F: FnMut(&IndexKey) -> bool,

Filter keys with a predicate. Preserves the original variant where possible.

Source

pub fn filter_typed<F>(&self, pred: F) -> Self
where K: FromIndexKey, F: FnMut(K) -> bool,

Filter keys with a predicate over the typed, by-value decoded key.

Unlike Self::filter (which hands the closure a raw IndexKey), the key is decoded to K first, so a product set yields native tuples and no manual as_tuple().unwrap() unpacking is needed. The receiver’s K pins the closure parameter, so it usually needs no annotation.

use oximo_core::Set;
let plants = Set::strings(["seattle", "san-diego"]);
// No-self-loop arcs; keys decoded to `(String, String)`.
let arcs = (&plants * &plants).filter_typed(|(p, q)| p != q);
assert_eq!(arcs.len(), 2);
Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn is_range(&self) -> bool

Whether the backing representation is the integer-range variant.

Source

pub fn is_strings(&self) -> bool

Whether the backing representation is the string-list variant.

Source

pub fn is_tuples(&self) -> bool

Whether the backing representation is the tuple-list variant.

Source

pub fn product<B>(a: &Set<K>, b: &Set<B>) -> Set<<K as KeyCat<B>>::Out>
where K: KeyCat<B>,

Cartesian product of two sets. Inner tuple keys are flattened so a product (a * b) * c yields 3-element tuples, not nested 2-tuples.

§Panics

Panics if a.len() * b.len() overflows usize.

Source§

impl Set<usize>

Source

pub fn range<T: PrimInt>(r: Range<T>) -> Self

Build an integer index set from a range over any primitive integer type. Accepts Range<i64>, Range<i32>, Range<usize>, etc.

The keys decode to usize. Negative elements are accepted into the payload but panic when decoded to usize.

§Panics

Panics if either range bound does not fit in i64.

Source

pub fn from_ints<T, I>(iter: I) -> Self
where T: PrimInt, I: IntoIterator<Item = T>,

Build an integer index set from an iterator of any primitive integer type. Useful when keys are sparse or computed.

§Panics

Panics if any element does not fit in i64.

Source§

impl Set<String>

Source

pub fn strings<I, S>(iter: I) -> Self
where I: IntoIterator<Item = S>, S: Into<SmolStr>,

Source§

impl<K> Set<K>

Source

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

Source

pub fn par_iter(&self) -> impl ParallelIterator<Item = IndexKey> + '_

Trait Implementations§

Source§

impl<K> Clone for Set<K>

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<K> Debug for Set<K>

Source§

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

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

impl<'a, K> IntoIterator for &'a Set<K>

Source§

type Item = IndexKey

The type of the elements being iterated over.
Source§

type IntoIter = SetIter<'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<A, B> Mul<&Set<B>> for &Set<A>
where A: KeyCat<B>,

Source§

type Output = Set<<A as KeyCat<B>>::Out>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Set<B>) -> Self::Output

Performs the * operation. Read more
Source§

impl<K: FromIndexKey> SumDomain<K> for Set<K>

Source§

fn keys(&self) -> impl Iterator<Item = K> + '_

Auto Trait Implementations§

§

impl<K> Freeze for Set<K>

§

impl<K> RefUnwindSafe for Set<K>

§

impl<K> Send for Set<K>

§

impl<K> Sync for Set<K>

§

impl<K> Unpin for Set<K>

§

impl<K> UnsafeUnpin for Set<K>

§

impl<K> UnwindSafe for Set<K>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.