pub struct Range<'id, Proof = Unknown> { /* private fields */ }
Expand description
A branded range.
Range<'id>
only indexes the container instantiated with the exact same
particular lifetime for the parameter 'id
at its inception from
the scope()
function.
The Range
may carry a proof of nonemptiness (type parameter Proof
),
which enables further methods.
The range is delimited by a start index and an end index. Some methods
will use offsets relative the the start of a range, others will use
“absolute indices” which are offsets relative to the base Container
itself.
Implementations§
Source§impl<'id, P> Range<'id, P>
impl<'id, P> Range<'id, P>
Sourcepub fn nonempty(&self) -> Result<Range<'id, NonEmpty>, IndexingError>
pub fn nonempty(&self) -> Result<Range<'id, NonEmpty>, IndexingError>
Try to create a proof that the Range is nonempty; return
a Result
where the Ok
branch carries a non-empty Range.
Sourcepub fn split_in_half(self) -> (Range<'id>, Range<'id, P>)
pub fn split_in_half(self) -> (Range<'id>, Range<'id, P>)
Split the range in half, with the upper middle index landing in the
latter half. Proof of length P
transfers to the latter half.
Sourcepub fn split_at(&self, index: usize) -> (Range<'id>, Range<'id>, bool)
pub fn split_at(&self, index: usize) -> (Range<'id>, Range<'id>, bool)
Split to length index
; if past the end, return false and clamp to the end
index
is a relative index.
Sourcepub fn subdivide(&self, n: usize) -> Subdivide<'id> ⓘ
pub fn subdivide(&self, n: usize) -> Subdivide<'id> ⓘ
Return an iterator that divides the range in n
parts, in as
even length chunks as possible.
Sourcepub fn join<Q>(
&self,
other: Range<'id, Q>,
) -> Result<Range<'id, <(P, Q) as ProofAdd>::Sum>, IndexingError>
pub fn join<Q>( &self, other: Range<'id, Q>, ) -> Result<Range<'id, <(P, Q) as ProofAdd>::Sum>, IndexingError>
Join together two adjacent ranges (they must be exactly touching, and in left to right order).
Sourcepub fn join_cover<Q>(&self, other: Range<'id, Q>) -> Range<'id, P>
pub fn join_cover<Q>(&self, other: Range<'id, Q>) -> Range<'id, P>
Extend the range to the end of other
, including any space in between
The following example exists only to check that it fails to compile:
// Bug from https://github.com/bluss/indexing/issues/12
use indexing::scope;
let array = [0, 1, 2, 3, 4, 5];
scope(&array[..], |arr| {
let left = arr.vet_range(0..2).unwrap();
let left = left.nonempty().unwrap();
let (_, right) = arr.range().frontiers();
let joined = right.join_cover(left);
let ix = joined.first();
arr[ix]; //~ ERROR: Can't index by ix, because it's an edge index
});
Sourcepub fn join_cover_both<Q>(
&self,
other: Range<'id, Q>,
) -> Range<'id, <(P, Q) as ProofAdd>::Sum>
pub fn join_cover_both<Q>( &self, other: Range<'id, Q>, ) -> Range<'id, <(P, Q) as ProofAdd>::Sum>
Extend the range to start and end of other
, including any space in between
pub fn as_range(&self) -> Range<usize>
Sourcepub fn frontiers(&self) -> (Range<'id>, Range<'id>)
pub fn frontiers(&self) -> (Range<'id>, Range<'id>)
Return two empty ranges, at the front and the back of the range respectively
Sourcepub fn forward_by(&self, index: &mut Index<'id>, offset: usize) -> bool
pub fn forward_by(&self, index: &mut Index<'id>, offset: usize) -> bool
Increment index
, if doing so would still be before the end of the range
Return true
if the index was incremented.
Sourcepub fn forward_range_by<Q>(&self, r: Range<'id, Q>, offset: usize) -> Range<'id>
pub fn forward_range_by<Q>(&self, r: Range<'id, Q>, offset: usize) -> Range<'id>
Increment r
, clamping to the end of self
.
pub fn no_proof(&self) -> Range<'id>
Source§impl<'id, P> Range<'id, P>
impl<'id, P> Range<'id, P>
Sourcepub fn first(&self) -> Index<'id, P>
pub fn first(&self) -> Index<'id, P>
Return the first index in the range (The index is accessible if the range
is NonEmpty
).
Sourcepub fn upper_middle(&self) -> Index<'id, P>
pub fn upper_middle(&self) -> Index<'id, P>
Return the middle index, rounding up.
Produces mid
where mid = start + len / 2
.
Sourcepub fn past_the_end(self) -> Index<'id, Unknown>
pub fn past_the_end(self) -> Index<'id, Unknown>
Return the index past the end of the range.
Source§impl<'id> Range<'id, NonEmpty>
impl<'id> Range<'id, NonEmpty>
Sourcepub fn lower_middle(&self) -> Index<'id>
pub fn lower_middle(&self) -> Index<'id>
Return the middle index, rounding down.
Produces mid
where mid = start + (len - 1)/ 2
.
pub fn last(&self) -> Index<'id>
pub fn tail(self) -> Range<'id>
pub fn init(&self) -> Range<'id>
pub fn advance_(&self) -> Result<Range<'id, NonEmpty>, IndexingError>
Sourcepub fn advance(&mut self) -> bool
pub fn advance(&mut self) -> bool
Increase the range’s start, if the result is still a non-empty range.
Return true
if stepped successfully, false
if the range would be empty.
Sourcepub fn advance_by(&mut self, offset: usize) -> bool
pub fn advance_by(&mut self, offset: usize) -> bool
Increase the range’s start, if the result is still a non-empty range.
Return true
if stepped successfully, false
if the range would be empty.
Sourcepub fn advance_back(&mut self) -> bool
pub fn advance_back(&mut self) -> bool
Decrease the range’s end, if the result is still a non-empty range.
Return true
if stepped successfully, false
if the range would be empty.
Trait Implementations§
Source§impl<'id, T, Array, P, M> Index<Range<'id, P>> for Container<'id, Array, M>where
Array: Contiguous<Item = T>,
&self[r]
where r
is a Range<'id>
.
impl<'id, T, Array, P, M> Index<Range<'id, P>> for Container<'id, Array, M>where
Array: Contiguous<Item = T>,
&self[r]
where r
is a Range<'id>
.
Source§impl<'id, Array, P, M> IndexMut<Range<'id, P>> for Container<'id, Array, M>where
Array: ContiguousMut,
&mut self[r]
where r
is a Range<'id>
.
impl<'id, Array, P, M> IndexMut<Range<'id, P>> for Container<'id, Array, M>where
Array: ContiguousMut,
&mut self[r]
where r
is a Range<'id>
.
Source§impl<'id> IntoCheckedRange<'id> for Range<'id>
impl<'id> IntoCheckedRange<'id> for Range<'id>
Source§impl<'id> IntoCheckedRange<'id> for Range<'id, NonEmpty>
impl<'id> IntoCheckedRange<'id> for Range<'id, NonEmpty>
Source§impl<'id, P> IntoIterator for Range<'id, P>
impl<'id, P> IntoIterator for Range<'id, P>
Source§impl<'id, P> Ord for Range<'id, P>
Compare the order of two ranges.
impl<'id, P> Ord for Range<'id, P>
Compare the order of two ranges.
Ranges compare like an ordered pair of indices, and the proof parameter does not matter.
Source§impl<'id, P, Q> PartialOrd<Range<'id, Q>> for Range<'id, P>
Compare the order of two ranges.
impl<'id, P, Q> PartialOrd<Range<'id, Q>> for Range<'id, P>
Compare the order of two ranges.
Ranges compare like an ordered pair of indices, and the proof parameter does not matter.