1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 08:25:19 +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>] private let values: [Memo<A>]
public subscript (i: I, j: I) -> 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 i = across.startIndex.distanceTo(i)
let j = down.startIndex.distanceTo(j) let j = down.startIndex.distanceTo(j)
return values[Int((i + j * across.count).toIntMax())] return values[Int((i + j * across.count).toIntMax())]