-
-
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> Gridfunc __array__(this *<$T> Grid) *$Tfunc __length__(this *<$T> Grid) usizefunc __access__(this *<$T> Grid, index usize) *$Tfunc __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> GridConstructs a
Gridwith a default element. -
func GridCoord(index usize, w, _h int) GridCoordConstructs a
GridCoordby converting an index into the correspondingxandy. -
func commit(this *<$T> Grid) <$T> GridChanges the ownership of a
Gridto 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> GridIf the grid has ownership, then the grid's ownership will be changed to
Ownership::DONORand 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> GridLike
commit(), except requires ownership. Not having ownership will cause a runtime error. -
func isValid(this *<$T> Grid, coord GridCoord) boolReturns whether a given
GridCoordis within the bounds of aGrid. -
func flipY(this *<$T> Grid) voidFlips a
Gridupside-down.
#default Grid_bounds_checks true
#default Grid_error_on_donor_usage true