RandomAccessIndexType

protocol RandomAccessIndexType

An index that can be offset by an arbitrary number of positions, and can measure the distance to any reachable value, in O(1).

Inheritance BidirectionalIndexType, Comparable, Equatable, ForwardIndexType, Strideable, _BidirectionalIndexType, _Comparable, _ForwardIndexType, _Incrementable, _RandomAccessIndexType, _Strideable View Protocol Hierarchy →
Associated Types
Distance : _SignedIntegerType = Int

A type that can represent the number of steps between pairs of Self values where one value is reachable from the other.

Reachability is defined by the ability to produce one value from the other via zero or more applications of successor.

_DisabledRangeIndex = _DisabledRangeIndex_

A type that can represent the number of steps between pairs of Self values where one value is reachable from the other.

Reachability is defined by the ability to produce one value from the other via zero or more applications of successor.

Stride : SignedNumberType

A type that can represent the distance between two values of Self

Import import Swift

Instance Methods

func <(_:rhs:) Required

A strict total order over instances of Self

Declaration

func <(lhs: Self, rhs: Self) -> Bool

Declared In

_Comparable
func <=(_:rhs:)

Declaration

func <=(lhs: Self, rhs: Self) -> Bool

Declared In

Comparable
func ==(_:rhs:) Required

Return true if lhs is equal to rhs.

Equality implies substitutability. When x == y, x and y are interchangeable in any code that only depends on their values.

Class instance identity as distinguished by triple-equals === is notably not part of an instance's value. Exposing other non-value aspects of Equatable types is discouraged, and any that are exposed should be explicitly pointed out in documentation.

Equality is an equivalence relation

  • x == x is true
  • x == y implies y == x
  • x == y and y == z implies x == z

Inequality is the inverse of equality, i.e. !(x == y) iff x != y

Declaration

func ==(lhs: Self, rhs: Self) -> Bool

Declared In

Equatable
func >(_:rhs:)

Declaration

func >(lhs: Self, rhs: Self) -> Bool

Declared In

Comparable
func >=(_:rhs:)

Declaration

func >=(lhs: Self, rhs: Self) -> Bool

Declared In

Comparable
func advancedBy(_:) Required

Return self offset by n steps.

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.

Complexity: O(1)

Axioms:

x.advancedBy(0) == x
x.advancedBy(1) == x.successor()
x.advancedBy(-1) == x.predecessor()
x.distanceTo(x.advancedBy(m)) == m

Declaration

func advancedBy(n: Self.Distance) -> Self

Declared In

_RandomAccessIndexType, _Strideable
func distanceTo(_:) Required

Return the minimum number of applications of successor or predecessor required to reach other from self.

Complexity: O(1).

Axioms:

x.distanceTo(x.successor())) == 1
x.distanceTo(x.predecessor())) == -1
x.advancedBy(x.distanceTo(y)) == y

Declaration

func distanceTo(other: Self) -> Self.Distance

Declared In

_RandomAccessIndexType, _Strideable
func predecessor() Required

Return the previous consecutive value in a discrete sequence.

If self has a well-defined successor, self.successor().predecessor() == self. If self has a well-defined predecessor, self.predecessor().successor() == self.

Requires: self has a well-defined predecessor.

Declaration

func predecessor() -> Self

Declared In

_BidirectionalIndexType
func successor() Required

Return the next consecutive value in a discrete sequence of Self values

Requires: self has a well-defined successor.

Declaration

func successor() -> Self

Declared In

_Incrementable