A dense grid implementation using a 1-dimension List to store elements.
This implementation is the default grid type returned by the constructors in the Grid interface. It is a row-major dense grid, where each row is stored contiguously in memory; the most common layout for a grid, and is often the most efficient for most use-cases.
Performance
ListGrid is optimized for dense grids, sacrificing memory efficiency for runtime speed.
Operation | Time Complexity |
---|---|
get |
O(1) |
set |
O(1) |
isEmpty |
O(n) |
rows or columns |
O(n) |
- Mixed in types
-
- Grid<
E>
- Grid<
Constructors
- ListGrid.filled(int width, int height, {required E empty, E? fill})
-
Creates a new list grid with the given
width
andheight
.factory -
ListGrid.from(Grid<
E> other, {E? empty}) -
Creates a new list grid from an existing grid.
factory
-
ListGrid.fromCells(Iterable<
E> elements, {required int width, E? empty}) -
Creates a new list grid from
elements
in row-major order.factory -
ListGrid.fromRows(Iterable<
Iterable< rows, {E? empty})E> > -
Creates a new list grid from a 2D list of rows of columns.
factory
- ListGrid.generate(int width, int height, E generator(Pos pos), {required E empty})
-
Creates a new list grid with the given
width
andheight
.factory -
ListGrid.withList(List<
E> elements, {required int width, required E empty}) -
Creates a new grid backed by the provided
elements
in row-major order.factory
Properties
- bottomLeft → Pos
-
The bottom-left position of the grid.
no setterinherited
- bottomRight → Pos
-
The bottom-right position of the grid.
no setterinherited
- bounds → Rect
-
Bounds of the grid, anchored at the topLeft position.
no setterinherited
-
cells
→ Iterable<
(Pos, E)> -
An iterable of positions and elements in the grid, in row-major order.
no setterinherited
-
columns
→ Iterable<
Iterable< E> > -
Columns of the grid.
no setterinherited
- empty → E
-
The default element for the grid, or the "empty" element.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- height ↔ int
-
Number of rows in the grid, and the upper bound for the y-coordinate.
getter/setter pairinherited
- isEmpty → bool
-
Whether the grid is zero-length or is entirely filled with empty.
no setterinherited
- isNotEmpty → bool
-
Whether the grid contains at least one element that is not empty.
no setterinherited
- length → int
-
Total number of elements in the grid.
no setterinherited
-
rows
→ Iterable<
Iterable< E> > -
Rows of the grid.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- topLeft → Pos
-
The top-left position of the grid.
no setterinherited
- topRight → Pos
-
The top-right position of the grid.
no setterinherited
- width ↔ int
-
Number of columns in the grid, and the upper bound for the x-coordinate.
getter/setter pairinherited
Methods
-
asUnweighted(
{Iterable< Pos> directions = Direction.cardinal}) → Walkable<Pos> -
Returns a view of this grid as an unweighted walkable.
inherited
-
asWeighted(
{required double weight(E, E, Pos), Iterable< Pos> directions = Direction.cardinal}) → WeightedWalkable<Pos> -
Returns a view of this grid as a weighted walkable.
inherited
-
clear(
[Rect? bounds]) → void -
Clears the grid, setting all elements to empty.
inherited
-
containsPos(
Pos pos) → bool -
Returns whether a position is within the bounds of the grid.
inherited
-
copyFrom(
Grid< E> src, {Rect? source, Pos target = Pos.zero}) → void -
Copies the elements from another grid into this grid.
inherited
-
fill(
E fill, [Rect? bounds]) → void -
Fills the grid with the given element.
inherited
-
get(
Pos pos) → E -
Returns the element at a position in the grid.
inherited
-
getUnchecked(
Pos pos) → E -
Returns the element at a position in the grid.
inherited
-
getUnsafe(
Pos pos) → E -
Returns the element at a position in the grid.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resize(
int width, int height) → void -
Resizes the grid to the given
width
andheight
.inherited -
set(
Pos pos, E value) → void -
Sets the element at a position in the grid.
inherited
-
setUnchecked(
Pos pos, E value) → void -
Sets the element at a position in the grid.
inherited
-
setUnsafe(
Pos pos, E value) → void -
Sets the element at a position in the grid.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
Pos pos) → E -
Returns the element at a position in the grid.
inherited
-
operator []=(
Pos pos, E value) → void -
Sets the element at a position in the grid.
inherited