1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 16:02:43 +03:00

Test that we aren’t at the endIndex instead of testing containment.

This should be O(1) for all index types.
This commit is contained in:
Rob Rix 2015-11-12 15:20:51 -05:00
parent db5307a365
commit dd812a2b2b

View File

@ -14,7 +14,7 @@ public struct Matrix<A, I: ForwardIndexType> {
private let values: [Memo<A>]
public subscript (i: I, j: I) -> Memo<A>? {
guard across.contains(i) && down.contains(j) else { return nil }
guard i != across.endIndex && j != down.endIndex else { return nil }
let i = across.startIndex.distanceTo(i)
let j = down.startIndex.distanceTo(j)
return values[Int((i + j * across.count).toIntMax())]