1
1
mirror of https://github.com/github/semantic.git synced 2025-01-02 12:23:08 +03:00

Populate the matrix with a compute function.

This commit is contained in:
Rob Rix 2015-10-05 17:12:28 -04:00
parent c935e4a3d9
commit 81b6c172cf

View File

@ -1,4 +1,19 @@
struct Matrix<A> {
init(width: Int, height: Int, compute: (Int, Int) -> A) {
self.width = width
self.height = height
var values: [Memo<A>] = []
values.reserveCapacity(width * height)
for i in 0..<width {
for j in 0..<height {
values[i + j * height] = Memo<A> { compute(i, j) }
}
}
self.values = values
}
let width: Int
let height: Int