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