Package net.mtrop.doom.struct.map
Class SparseGridIndex<T>
java.lang.Object
net.mtrop.doom.struct.map.SparseGridIndex<T>
- Type Parameters:
T
- the value type.
- All Implemented Interfaces:
Iterable<Map.Entry<SparseGridIndex.Pair,
,T>> Sizable
- Direct Known Subclasses:
SparseQueueGridIndex
public class SparseGridIndex<T>
extends Object
implements Iterable<Map.Entry<SparseGridIndex.Pair,T>>, Sizable
This is a grid that contains a grid of Object data generally used for maps and lookups.
This map is sparse, which means it uses as little memory as possible, which can increase the lookup time in most cases.
- Author:
- Matthew Tropiano
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreates a new sparse grid of an unspecified width and height. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
data
List of grid codes.
-
-
Constructor Details
-
SparseGridIndex
public SparseGridIndex()Creates a new sparse grid of an unspecified width and height.- Throws:
IllegalArgumentException
- if capacity is negative or ratio is 0 or less.
-
-
Method Details
-
clear
public void clear()Clears everything from the grid. -
set
Sets an object at a particular part of the grid.- Parameters:
x
- the grid position x to set info.y
- the grid position y to set info.object
- the object to set. Can be null.
-
get
Gets the object at a particular part of the grid.- Parameters:
x
- the grid position x to get info.y
- the grid position y to get info.- Returns:
- the object at that set of coordinates or null if not object.
-
toString
-
iterator
-
size
public int size() -
isEmpty
public boolean isEmpty()Description copied from interface:Sizable
Returns if this object contains no objects. The general policy of this method is that this returns true if and only ifSizable.size()
returns 0.
-