struct ReverseIndex<Base : BidirectionalIndexType>
Inheritance |
BidirectionalIndexType, Equatable, ForwardIndexType, ReverseIndexType, _Incrementable
View Protocol Hierarchy →
|
---|---|
Associated Types | |
Import | import Swift |
Initializers
Instance Variables
The successor position in the underlying (un-reversed) collection.
If self
is advance(c.reverse.startIndex, n)
, then:
- self.base
is advance(c.endIndex, -n)
.
- if n
!= c.count
, then c.reverse[self]
is
equivalent to [self.base.predecessor()]
.
Declaration
var base: Base { get }
Instance Methods
Returns the result of advancing self
by n
positions.
Returns:
- If n > 0
, the result of applying successor
to self
n
times.
- If n < 0
, the result of applying predecessor
to self
-n
times.
- Otherwise, self
.
Requires: n >= 0
if only conforming to ForwardIndexType
Complexity:
- O(1) if conforming to RandomAccessIndexType
- O(abs(n)
) otherwise
Declaration
func advancedBy(n: ReverseIndex<Base>.Distance) -> ReverseIndex<Base>
Declared In
BidirectionalIndexType
, ForwardIndexType
Returns the result of advancing self
by n
positions, or until it
equals limit
.
Returns:
- If n > 0
, the result of applying successor
to self
n
times
but not past limit
.
- If n < 0
, the result of applying predecessor
to self
-n
times
but not past limit
.
- Otherwise, self
.
Requires: n >= 0
if only conforming to ForwardIndexType
.
Complexity:
- O(1) if conforming to RandomAccessIndexType
- O(abs(n)
) otherwise
Declaration
func advancedBy(n: ReverseIndex<Base>.Distance, limit: ReverseIndex<Base>) -> ReverseIndex<Base>
Declared In
BidirectionalIndexType
, ForwardIndexType
Measure the distance between self
and end
.
Requires:
- start
and end
are part of the same sequence when conforming to
RandomAccessSequenceType
.
- end
is reachable from self
by incrementation otherwise.
Complexity:
- O(1) if conforming to RandomAccessIndexType
- O(n
) otherwise, where n
is the function's result.
Declaration
func distanceTo(end: ReverseIndex<Base>) -> ReverseIndex<Base>.Distance
Declared In
BidirectionalIndexType
, ForwardIndexType
Returns the previous consecutive value before self
.
Requires: The previous value is representable.
Declaration
func predecessor() -> ReverseIndex<Base>
Declared In
BidirectionalIndexType
Returns the next consecutive value after self
.
Requires: The next value is representable.
Declaration
func successor() -> ReverseIndex<Base>
Declared In
BidirectionalIndexType
A wrapper for a
BidirectionalIndexType
that reverses its direction of traversal.