pub struct Bounds<I> {
pub offset: I,
pub extent: I,
}Expand description
Bounds associated with an index type.
This is a description of the bounds of a multidimensional array, through the definition of
an offset and an extent. Bounds can also be used to describe the bounds of an
index list, which can be used to ensure that a collection of indices are all in bounds,
and therefore bounds checks can be eliminated up front, prior to iteration.
In general, Bounds is expected to be used with either integers like usize for
one-dimensional arrays or tuples like (usize, usize) for multidimensional arrays.
For data structures, the offset is typically zero along each dimension, and the extent
describes the “length” of the array along each dimension.
Offset primarily exists in order for index lists to more tightly describe their bounds, which can be used, for example, to ensure that index lists with disjoint bounds contain disjoint indices. However, a data structure can have non-zero offset.
Fields§
§offset: IThe offset of the bounds.
extent: IThe extent of the bounds.
Implementations§
Source§impl<I: RecordIndex> Bounds<I>
impl<I: RecordIndex> Bounds<I>
Sourcepub fn contains_bounds(&self, other: &Bounds<I>) -> bool
pub fn contains_bounds(&self, other: &Bounds<I>) -> bool
Check if these bounds contain other.
Sourcepub fn contains_index(&self, index: I) -> bool
pub fn contains_index(&self, index: I) -> bool
Check if these bounds contain the given index.
Sourcepub fn enclose_index(&mut self, index: I)
pub fn enclose_index(&mut self, index: I)
Expand these bounds — if needed — so that the given index is contained in the updated bounds.
Sourcepub fn bounds_for_index(index: I) -> Self
pub fn bounds_for_index(index: I) -> Self
Constructs bounds large enough to hold only exactly the given index.