A sparse grid implementation backed by a SplayTreeMap.
Every element in the grid that is empty is not stored in the map, and instead is assumed to be the default value; this allows the grid to use less memory than a dense grid implementation and grow in size efficiently, suitable for grids where most elements are empty or full grid iteration is not a common operation, such as map editors.
Performance
SplayTreeGrid is optimized for sparse grids, sacrificing runtime speed for memory efficiency.
| Operation | Time Complexity | 
|---|---|
get | 
O(log n) | 
set | 
O(log n) | 
isEmpty | 
O(1) | 
nonEmptyEntries | 
O(m)^1 | 
rows or columns | 
O(m log n)^1 | 
^1: Where m is the number of non-empty entries in the grid.
- Mixed in types
 - 
    
- Grid<
E>  
 - Grid<
 
Constructors
- SplayTreeGrid.filled(int width, int height, {required E empty})
 - 
          Creates a new splay tree grid with the given 
widthandheight.factory - 
          SplayTreeGrid.from(Grid<
E> other, {E? empty}) - 
          Creates a new splay tree grid from an existing grid.
            factory
 - SplayTreeGrid.generate(int width, int height, E generator(Pos), {required E empty})
 - 
          Creates a new splay tree grid with the given 
widthandheight.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
 - 
  nonEmptyEntries
  → Iterable<
(Pos, E)>  - 
  Entries in the grid that are not equal to empty, in row-major order.
  no setter
 - 
  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 
widthandheight.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