Skip to content
Dickson Law edited this page Apr 12, 2023 · 5 revisions

Classes

Grid(width, height, ...)

A data structure that stores entries in a compact unit of set width and height, and allows access by x-y coordinates. Equivalent to DS Grids.

GridDiskIterator(grid, xm, ym, r)

An iterator class designed to efficiently loop through the given disk region of the grid in linear time, skippping any points past the boundaries of the grid. It stores its current grid position in x and y, and its current value in value.

  • hasNext(): Return whether there are more values to iterate.
  • next(): Iterate to the next value.
  • set(val): Set the current value in the grid to the given value.

GridRegionIterator(grid, x1, y1, x2, y2)

An iterator class designed to efficiently loop through the given rectangular region of the grid in linear time, skipping any points past the boundaries of the grid. It stores its current grid position in x and y, and its current value in value.

  • hasNext(): Return whether there are more values to iterate.
  • next(): Iterate to the next value.
  • set(val): Set the current value in the grid to the given value.

Ported Methods

New Methods

  • clone(): Return a shallow clone of the grid.
  • cloneDeep(): Same as clone(), but also making deep copies of everything in the grid.
  • copyDeep(sourceGrid): Same as copy(sourceGrid), but with deep copies of everything in the source.
  • diskIterator(xm, ym, r): Return a new GridDiskIterator set to track a disk region in this grid.
  • forEach(func): Call the method or script func for each value in the grid. On each iteration, it will be passed the current value followed by the current X and Y positions.
  • forEachInDisk(func, xm, ym, r): Call the method or script func for each value in the disk on the grid. On each iteration, it will be passed the current value followed by the current X and Y positions.
  • forEachInRegion(func, x1, y1, x2, y2): Call the method or script func for each value in the region on the grid. On each iteration, it will be passed the current value followed by the current X and Y positions.
  • iterator(): Return a new GridRegionIterator set to track the entire grid.
  • mapEach(func): Set each value v in the grid to func(v).
  • mapEachInDisk(func, xm, ym, r): Set each value v in the disk on the grid to func(v).
  • mapEachInRegion(func, x1, y1, x2, y2): Set each value v in the region on the grid to func(v).
  • regionIterator(x1, y1, x2, y2): Return a new GridRegionIterator set to track a rectangular region in this grid.
  • shuffleRows(): Shuffle the rows of the grid, keeping those on the same row together.
  • to2dArray(): Return the grid's contents in 2D array form. Note that this is a shallow conversion --- other grids nested inside will remain as grids in the returned array.

Clone this wiki locally