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
  • Field Details

  • 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

      public void set(int x, int y, T object)
      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

      public T get(int x, int y)
      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

      public String toString()
      Overrides:
      toString in class Object
    • iterator

      Specified by:
      iterator in interface Iterable<T>
    • size

      public int size()
      Specified by:
      size in interface Sizable
      Returns:
      the amount of individual objects that this object contains.
    • 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 if Sizable.size() returns 0.
      Specified by:
      isEmpty in interface Sizable
      Returns:
      true if so, false otherwise.