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:
parent
c935e4a3d9
commit
81b6c172cf
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user