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:
parent
db5307a365
commit
dd812a2b2b
@ -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())]
|
||||
|
Loading…
Reference in New Issue
Block a user