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 Int, offsetBy distance: Int, limitedBy limit: Int) -> 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. 計算量:O(1)、もしコレクションがRandomAccessCollectionに準拠するならば;そうでなければ、O(k)、そこでkdistanceの値の絶対値です。