pub struct IndexedVar<'a, K = IndexKey> { /* private fields */ }Expand description
Indexed variable: maps an IndexKey to a single-variable Expr, tagged with
the key type K its domain decodes to.
Constructed by crate::Model::indexed_var or the variable! macro. K is
a phantom marker, carried so the type of an indexed family is visible and
typed iteration via Self::keys is possible.
When the domain is a contiguous integer range (or a Cartesian product of
ranges) the family is stored densely (see [Storage]).
String, sparse, and filtered families fall back to a hash map.
Implementations§
Source§impl<'a, K> IndexedVar<'a, K>
impl<'a, K> IndexedVar<'a, K>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn is_dense(&self) -> bool
pub fn is_dense(&self) -> bool
Whether this family is stored densely (domain was a range or product of ranges).
pub fn iter(&self) -> impl Iterator<Item = (&IndexKey, &Expr<'a>)> + '_
pub fn get<Q: Into<IndexKey>>(&self, key: Q) -> Option<Expr<'a>>
Sourcepub fn at<const N: usize>(&self, coords: [usize; N]) -> Expr<'a>
pub fn at<const N: usize>(&self, coords: [usize; N]) -> Expr<'a>
Zero-allocation typed index by integer coordinates.
On a dense family this maps straight to a flat offset with no
IndexKey built. On a sparse family it falls back to building a key.
§Panics
Panics if the coordinates are out of range/not present.
Source§impl<'a, K: FromIndexKey> IndexedVar<'a, K>
impl<'a, K: FromIndexKey> IndexedVar<'a, K>
Trait Implementations§
Source§impl<'a, K> Clone for IndexedVar<'a, K>
impl<'a, K> Clone for IndexedVar<'a, K>
Source§impl<'a, K> Debug for IndexedVar<'a, K>
impl<'a, K> Debug for IndexedVar<'a, K>
Source§impl<'a, K> Index<&IndexKey> for IndexedVar<'a, K>
impl<'a, K> Index<&IndexKey> for IndexedVar<'a, K>
Auto Trait Implementations§
impl<'a, K = IndexKey> !RefUnwindSafe for IndexedVar<'a, K>
impl<'a, K = IndexKey> !Send for IndexedVar<'a, K>
impl<'a, K = IndexKey> !Sync for IndexedVar<'a, K>
impl<'a, K = IndexKey> !UnwindSafe for IndexedVar<'a, K>
impl<'a, K> Freeze for IndexedVar<'a, K>
impl<'a, K> Unpin for IndexedVar<'a, K>
impl<'a, K> UnsafeUnpin for IndexedVar<'a, 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