1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00

Precompute the width of the matrix.

This commit is contained in:
Rob Rix 2015-11-12 15:26:50 -05:00
parent dd812a2b2b
commit e1f38f64d0

View File

@ -11,13 +11,14 @@ public struct Matrix<A, I: ForwardIndexType> {
public let across: Range<I>
public let down: Range<I>
private let width: I.Distance
private let values: [Memo<A>]
public subscript (i: I, j: I) -> Memo<A>? {
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())]
return values[Int((i + j * width).toIntMax())]
}
@ -34,6 +35,7 @@ public struct Matrix<A, I: ForwardIndexType> {
self.across = across
self.down = down
self.values = values
self.width = across.count
}
}