Skip to content
Isaac Shelton edited this page Sep 8, 2023 · 1 revision

Grid

Grid represents the type of an ownership managed 2D array.

Specifications

Type Size Possible Values Memory Management Model File
Grid 24 bytes Grids of a Single Type Ownership 2.7/Grid.adept

Definition

record <$T> Grid (data *$T, w, h int, ownership Ownership)

record GridCoord (x, y int)

where

$T is any valid type

Fields

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

Value Management Definitions

  • 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

Memory Management

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.

Functions

  • func Grid(w, h int, square $T) <$T> Grid

    Constructs a Grid with a default element.

    [view src]

  • func GridCoord(index usize, w, _h int) GridCoord

    Constructs a GridCoord by converting an index into the corresponding x and y.

    [view src]

  • func commit(this *<$T> Grid) <$T> Grid

    Changes the ownership of a Grid to be Ownership::REFERENCE. If the grid previously had ownership, then a grid value will be returned with Ownership::GIVEN, otherwise the original grid will be returned. This method is used for transferring ownership of internal array data of grids to other grids.

    [view src]

  • 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 with Ownership::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.

    [view src]

  • func give(this *<$T> Grid) <$T> Grid

    Like commit(), except requires ownership. Not having ownership will cause a runtime error.

    [view src]

  • func isValid(this *<$T> Grid, coord GridCoord) bool

    Returns whether a given GridCoord is within the bounds of a Grid.

    [view src]

  • func flipY(this *<$T> Grid) void

    Flips a Grid upside-down.

    [view src]

Settings

#default Grid_bounds_checks        true
#default Grid_error_on_donor_usage true
Clone this wiki locally