-
-
Notifications
You must be signed in to change notification settings - Fork 9
Grid
Grid
represents the type of an ownership managed 2D array.
Type | Size | Possible Values | Memory Management Model | File |
---|---|---|---|---|
Grid |
24 bytes | Grids of a Single Type | Ownership | 2.7/Grid.adept |
record <$T> Grid (data *$T, w, h int, ownership Ownership)
record GridCoord (x, y int)
where
$T is any valid type
Name | Type | Description |
---|---|---|
data |
*$T |
Pointer to raw array of items |
w |
int |
Width of grid |
h |
int |
Height of grid |
ownership |
Ownership |
Whether this grid is responsible for freeing data
|
func __defer__(this *<$T> Grid)
func __pass__(grid POD <$T> Grid) <$T> Grid
func __array__(this *<$T> Grid) *$T
func __length__(this *<$T> Grid) usize
func __access__(this *<$T> Grid, index usize) *$T
func __assign__(this *<$T> Grid, other POD <$T> Grid)
func __equals__(a, b POD GridCoord) bool
Like Lists
, Grids are automatically freed when they run out of scope.
In order to pass grids around to other scopes, you can use the commit()
method. my_grid.commit()
gives up any ownership held by my_grid
and returns a copy with the original's ownership.
-
func Grid(w, h int, square $T) <$T> Grid
Constructs a
Grid
with a default element. -
func GridCoord(index usize, w, _h int) GridCoord
Constructs a
GridCoord
by converting an index into the correspondingx
andy
. -
func commit(this *<$T> Grid) <$T> Grid
Changes the ownership of a
Grid
to beOwnership::REFERENCE
. If the grid previously had ownership, then a grid value will be returned withOwnership::GIVEN
, otherwise the original grid will be returned. This method is used for transferring ownership of internal array data of grids to other grids. -
func donate(this *<$T> Grid) <$T> Grid
If the grid has ownership, then the grid's ownership will be changed to
Ownership::DONOR
and a grid value will be returned withOwnership::GIVEN
, otherwise the original grid will be returned. This method is used for transferring ownership of internal array data of grids to other grids. If ownership was transferred, then the subject value will be completely invalidated and will be unable to be used afterwards. -
func give(this *<$T> Grid) <$T> Grid
Like
commit(
), except requires ownership. Not having ownership will cause a runtime error. -
func isValid(this *<$T> Grid, coord GridCoord) bool
Returns whether a given
GridCoord
is within the bounds of aGrid
. -
func flipY(this *<$T> Grid) void
Flips a
Grid
upside-down.
#default Grid_bounds_checks true
#default Grid_error_on_donor_usage true