crow/col/mut-grid.crow
(source)
mut-grid
[t
] record
mut
(has non-public fields)
Mutable grid (matrix) type.
This is intended for data that happens to fall in a grid; it may not be ideal for linear algebra.
This is row-major, meaning rows are stored contiguously.
So, iteration functions typically start with the top row left-to-right,
then the second row left-to-right, etc.
Grid elements are mutable, but changing the width or height is not supported.
coord
record
Coordinate in a grid.
x
is the column index. The leftmost column is 0; the rightmost column is width - 1
.y
is the row index. The top row is 0; the bottom row is height - 1
.
new
coord
() bare
Same as 0, 0
.
==
bool
(a
coord
, b
coord
) bare
show
string
(a
coord
)
"<x, y>"
has-coord
[t
] bool
(a
t
mut-grid
, coord
coord
) bare
true
if coord
is a valid coordinate (within the width and height of the grid).
row
[t
] t
mut-slice
(a
t
mut-grid
, y
nat64
)
Returns the entire row y
.
This is O(1).
Throws if y
is out of range.
new
[t
] t
mut-grid
()
New empty grid with width and height 0.
size
[t
] nat64
(a
t
mut-grid
) bare
Number of elements in the grid (width * height).
make
[t
] t
mut-grid
(width
nat64
, height
nat64
, f
mut
t
((nat64
, nat64
) tuple2
))
Creates a new grid with the given width and height, setting every element to f[x, y]
.
copy
[t
] t
mut-grid
(a
t
mut-grid
)
Copy elements to a new grid.
subscript
[t
] t
(a
t
mut-grid
, coord
coord
) bare
set-subscript
[t
] void
(a
t
mut-grid
, coord
coord
, value
t
) bare
show
[t
] string
(a
t
mut-grid
) t
show
show
Returns a string with one line for each row.
Each row will have a space in between columns.
This makes no attempt to add padding to ensure columns line up. (TODO?)
mut-grid-rows
[t
] record
mut
(has non-public fields)
rows
[t
] t
mut-grid-rows
(a
t
mut-grid
)
size
[t
] nat64
(a
t
mut-grid-rows
)
iterate
[t
] bool
(a
t
mut-grid-rows
, f
mut
bool
(t
mut-slice
))
iterate
[t
] bool
(a
t
mut-grid
, f
mut
bool
(t
))
with-coords
[t
] record
mut
, nominal
inner
t
mut-grid