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

formIndex(_:offsetBy:limitedBy:)

Offsets the given index by the specified distance, or so that it equals the given limiting index. 与えられたインデックスをこの指定された隔たりで補います、またはそれでそれは与えられた限界インデックスと等しくなります。

Declaration 宣言

func formIndex(_ i: inout Index, offsetBy distance: Int, limitedBy limit: Index) -> Bool

Parameters パラメータ

i

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

distance

The distance to offset i. distance must not be negative unless the collection conforms to the BidirectionalCollection protocol. iを補う間隔。distanceは、そのコレクションがBidirectionalCollectionプロトコルに準拠するのでない限り、負であってはなりません。

limit

A valid index of the collection to use as a limit. If distance > 0, a limit that is less than i has no effect. Likewise, if distance < 0, a limit that is greater than i has no effect. 限度として使うためのそのコレクションの有効なインデックス。distance > 0ならば、iより少ない限度は効果を持ちません。同様に、distance < 0ならば、iより大きい限度は効果を持ちません。

Return Value 戻り値

true if i has been offset by exactly distance steps without going beyond limit; otherwise, false. When the return value is false, the value of i is equal to limit. true、もしiが正確にdistance幅だけlimitを越えていくことなく補われたならば;そうでなければ、falseです。戻り値がfalseの場合、iの値はlimitに等しいです。

Discussion 解説

The value passed as distance must not offset i beyond the bounds of the collection, unless the index passed as limit prevents offsetting beyond those bounds. distanceとして渡される値は、このコレクションの境界を越えてiを補ってはなりません、limitとして渡されるインデックスがそれら境界を越えて補うのを防止するのでない限りは。

Complexity: O(1) if the collection conforms to RandomAccessCollection; otherwise, O(k), where k is the absolute value of distance. 計算量:もしコレクションがRandomAccessCollectionに準拠するならば、O(1);そうでなければ、O(k)、そこでkdistanceの値の絶対値です。