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>
impl<K> Set<K>
Sourcepub fn filter<F>(&self, f: F) -> Self
pub fn filter<F>(&self, f: F) -> Self
Filter keys with a predicate. Preserves the original variant where possible.
Sourcepub fn filter_typed<F>(&self, pred: F) -> Self
pub fn filter_typed<F>(&self, pred: F) -> Self
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);pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn is_range(&self) -> bool
pub fn is_range(&self) -> bool
Whether the backing representation is the integer-range variant.
Sourcepub fn is_strings(&self) -> bool
pub fn is_strings(&self) -> bool
Whether the backing representation is the string-list variant.
Source§impl Set<usize>
impl Set<usize>
Sourcepub fn range<T: PrimInt>(r: Range<T>) -> Self
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.
Sourcepub fn from_ints<T, I>(iter: I) -> Selfwhere
T: PrimInt,
I: IntoIterator<Item = T>,
pub fn from_ints<T, I>(iter: I) -> Selfwhere
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.
Trait Implementations§
Source§impl<'a, K> IntoIterator for &'a Set<K>
impl<'a, K> IntoIterator for &'a Set<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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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