Instance Method インスタンスメソッド

distance(from:to:)

Returns the distance between two indices. 2つのインデックス間の隔たりを返します。

Declaration 宣言

func distance(from start: ReversedCollection<Base>.Index, to end: ReversedCollection<Base>.Index) -> Int

Parameters パラメータ

start

A valid index of the collection. そのコレクションの有効なインデックス。

end

Another valid index of the collection. If end is equal to start, the result is zero. コレクションの別の有効なインデックス。endstartに等しいならば、結果はゼロです。

Return Value 戻り値

The distance between start and end. The result can be negative only if the collection conforms to the BidirectionalCollection protocol. startendの隔たり。結果は、そのコレクションがBidirectionalCollectionプロトコルに準拠する場合に限り、負であることができます。

Discussion 解説

Unless the collection conforms to the BidirectionalCollection protocol, start must be less than or equal to end. コレクションがBidirectionalCollectionプロトコルに準拠しない場合は、startendより少ないか等しくなければなりません。

Complexity: O(1) if the collection conforms to RandomAccessCollection; otherwise, O(k), where k is the resulting distance. 計算量:O(1)、もしコレクションがRandomAccessCollectionに準拠するならば;そうでなければ、O(k)、そこでkは結果の隔たりです。

Relationships 関係

From Protocol 由来プロトコル