Package civitas.celestis.util.grid
Interface DynamicGrid<E>
- Type Parameters:
E- The type of element this grid should hold
- All Superinterfaces:
BaseGrid<E>,Grid<E>,Iterable<E>,Serializable
- All Known Implementing Classes:
HashGrid
A grid whose size can be changed without requiring re-instantiation.
Dynamic grids use composite data structures as opposed to primitive arrays,
and thus have more overhead in terms of memory consumption.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclean()Cleans this grid, removing all instance ofnull.voidCleans this grid, then trims it to its minimum possible size.voidclear()Clears all entries within this grid, removing them from memory.static <E> DynamicGrid<E>of(E[][] values) Creates a new dynamic grid from a two-dimensional array of values.booleanremove(int r, int c) Removes the element from the specified position.voidsetSize(int rows, int columns) Forcefully sets the size of this grid, without regard to the data's integrity.voidtrim()Trims this grid, reducing its size to the minimum possible size required to hold all elements.Methods inherited from interface civitas.celestis.util.grid.Grid
array, collect, columns, contains, containsAll, equals, fill, fillEmpty, fillRange, forEach, forEach, get, getOrDefault, iterator, map, mapToDouble, mapToFloat, mapToInt, mapToLong, merge, replaceAll, resize, rows, set, set, setRange, size, stream, subGrid, toString, transpose, update, updateMethods inherited from interface java.lang.Iterable
spliterator
-
Method Details
-
of
Creates a new dynamic grid from a two-dimensional array of values.- Type Parameters:
E- The type of element to contain- Parameters:
values- The values of which to contain in the grid- Returns:
- The constructed grid instance
-
clear
void clear()Clears all entries within this grid, removing them from memory. This differs from filling the grid withnullin that it reduces the footprint of this grid. This is the equivalent of setting this grid's size to{0, 0}, then resizing it back to its original size. -
remove
boolean remove(int r, int c) Removes the element from the specified position. This differs from setting the value tonullin that it physically removes the entry corresponding to the specified index, as opposed to simply setting the value tonull.- Parameters:
r- The index of the row to removec- The index of the column to remove- Returns:
trueif there was a value (includingnull) at the specified position, and thus the state of this grid has changed as a result of this operation
-
clean
void clean()Cleans this grid, removing all instance ofnull. This does not trim the grid to its minimum possible size.- See Also:
-
trim
void trim()Trims this grid, reducing its size to the minimum possible size required to hold all elements. This does not cleannullvalues.- See Also:
-
cleanAndTrim
void cleanAndTrim()Cleans this grid, then trims it to its minimum possible size. In other words, this performsclean(), thentrimsthe grid.- See Also:
-
setSize
void setSize(int rows, int columns) Forcefully sets the size of this grid, without regard to the data's integrity. If this operation results in the reduction of this grid's size, all elements which are now outside the bounds of this grid will be removed.- Parameters:
rows- The number rows to resize tocolumns- The number of columns to resize to
-