Class CoordSet

java.lang.Object
com.github.tommyettinger.ds.ObjectSet<Coord>
com.github.yellowstonegames.grid.CoordSet
All Implemented Interfaces:
com.github.tommyettinger.ds.EnhancedCollection<Coord>, com.github.yellowstonegames.core.ISerializersNeeded, Iterable<Coord>, Collection<Coord>, Set<Coord>

public class CoordSet extends com.github.tommyettinger.ds.ObjectSet<Coord> implements com.github.yellowstonegames.core.ISerializersNeeded
A variant on jdkgdxds' ObjectSet class that only holds Coord items, and can do so more efficiently. This assumes all Coord keys are in the Coord pool; that is, Coord.expandPoolTo(int, int) has been called with the maximum values for Coord x and y. If you cannot be sure that the Coord pool will hold items placed into here, you should use a normal ObjectSet instead, since some optimizations here require Coord items to be in the pool.
If no initialCapacity is supplied, or if this must resize to enter a Coord, this will use a capacity at least as large as the Coord cache, as defined by Coord.getCacheWidth() by Coord.getCacheHeight(). While this means that any resizing will potentially make this use much more memory, it avoids a situation where some dense key sets could take hundreds of times longer than they should. It also usually doesn't use drastically more memory unless the Coord pool has been expanded quite a bit. If the Coord pool hasn't been expanded, each set should use about 1MB of memory or less when created with the default constructor.
This tends to perform significantly better with a high low factor, such as 0.9f, instead of a lower one like 0.5f . It also performs its best when the initial capacity is sufficient to hold every item this needs without resizing, but it typically only has to resize once if it has to resize at all.
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.github.tommyettinger.ds.ObjectSet

    com.github.tommyettinger.ds.ObjectSet.ObjectSetIterator<T>
  • Field Summary

    Fields inherited from class com.github.tommyettinger.ds.ObjectSet

    keyTable, loadFactor, mask, shift, size, threshold
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    CoordSet(int initialCapacity)
     
    CoordSet(int initialCapacity, float loadFactor)
     
    CoordSet(com.github.tommyettinger.ds.ObjectSet<? extends Coord> set)
     
    CoordSet(Coord[] array)
     
    CoordSet(Coord[] array, int offset, int length)
     
    CoordSet(Collection<? extends Coord> coll)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    equate(Object left, Object right)
     
     
    protected int
    place(Object item)
     
    protected void
    resize(int newSize)
     
    static CoordSet
    Constructs an empty set given the type as a generic type argument.
    static CoordSet
    with(Coord item)
    Creates a new CoordSet that holds only the given item, but can be resized.
    static CoordSet
    with(Coord... varargs)
    Creates a new CoordSet that holds only the given items, but can be resized.
    static CoordSet
    with(Coord item0, Coord item1)
    Creates a new CoordSet that holds only the given items, but can be resized.
    static CoordSet
    with(Coord item0, Coord item1, Coord item2)
    Creates a new CoordSet that holds only the given items, but can be resized.
    static CoordSet
    with(Coord item0, Coord item1, Coord item2, Coord item3)
    Creates a new CoordSet that holds only the given items, but can be resized.
    static CoordSet
    with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4)
    Creates a new CoordSet that holds only the given items, but can be resized.
    static CoordSet
    with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5)
    Creates a new CoordSet that holds only the given items, but can be resized.
    static CoordSet
    with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5, Coord item6)
    Creates a new CoordSet that holds only the given items, but can be resized.
    static CoordSet
    with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5, Coord item6, Coord item7)
    Creates a new CoordSet that holds only the given items, but can be resized.

    Methods inherited from class com.github.tommyettinger.ds.ObjectSet

    add, addAll, addAll, addAll, addAll, addResize, appendTo, clear, clear, contains, containsAll, containsAll, containsAll, containsAny, containsAny, containsAnyIterable, ensureCapacity, equals, first, get, getHashMultiplier, getLoadFactor, getTableSize, hashCode, isEmpty, iterator, locateKey, notEmpty, parse, parse, parse, remove, removeAll, removeAll, removeAll, retainAll, setHashMultiplier, setLoadFactor, shrink, size, toArray, toArray, toString, truncate, with, with, with, with, with, with, with, with, with

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface Collection

    parallelStream, removeIf, stream, toArray

    Methods inherited from interface com.github.tommyettinger.ds.EnhancedCollection

    add, add, add, addAll, addAllIterable, addLegible, addLegible, addVarargs, appendTo, appendTo, containsAll, containsAllIterable, containsAny, removeAll, removeAllIterable, removeEach, removeEach, removeEach, removeEachIterable, toString, toString, toString

    Methods inherited from interface Iterable

    forEach

    Methods inherited from interface Set

    spliterator
  • Constructor Details

    • CoordSet

      public CoordSet()
    • CoordSet

      public CoordSet(int initialCapacity)
    • CoordSet

      public CoordSet(int initialCapacity, float loadFactor)
    • CoordSet

      public CoordSet(com.github.tommyettinger.ds.ObjectSet<? extends Coord> set)
    • CoordSet

      public CoordSet(Collection<? extends Coord> coll)
    • CoordSet

      public CoordSet(Coord[] array, int offset, int length)
    • CoordSet

      public CoordSet(Coord[] array)
  • Method Details

    • place

      protected int place(Object item)
      Overrides:
      place in class com.github.tommyettinger.ds.ObjectSet<Coord>
    • equate

      protected boolean equate(Object left, Object right)
      Overrides:
      equate in class com.github.tommyettinger.ds.ObjectSet<Coord>
    • resize

      protected void resize(int newSize)
      Overrides:
      resize in class com.github.tommyettinger.ds.ObjectSet<Coord>
    • with

      public static CoordSet with()
      Constructs an empty set given the type as a generic type argument. This is usually less useful than just using the constructor, but can be handy in some code-generation scenarios when you don't know how many arguments you will have.
      Returns:
      a new set containing nothing
    • with

      public static CoordSet with(Coord item)
      Creates a new CoordSet that holds only the given item, but can be resized.
      Parameters:
      item - one Coord item
      Returns:
      a new CoordSet that holds the given item
    • with

      public static CoordSet with(Coord item0, Coord item1)
      Creates a new CoordSet that holds only the given items, but can be resized.
      Parameters:
      item0 - a Coord item
      item1 - a Coord item
      Returns:
      a new CoordSet that holds the given items
    • with

      public static CoordSet with(Coord item0, Coord item1, Coord item2)
      Creates a new CoordSet that holds only the given items, but can be resized.
      Parameters:
      item0 - a Coord item
      item1 - a Coord item
      item2 - a Coord item
      Returns:
      a new CoordSet that holds the given items
    • with

      public static CoordSet with(Coord item0, Coord item1, Coord item2, Coord item3)
      Creates a new CoordSet that holds only the given items, but can be resized.
      Parameters:
      item0 - a Coord item
      item1 - a Coord item
      item2 - a Coord item
      item3 - a Coord item
      Returns:
      a new CoordSet that holds the given items
    • with

      public static CoordSet with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4)
      Creates a new CoordSet that holds only the given items, but can be resized.
      Parameters:
      item0 - a Coord item
      item1 - a Coord item
      item2 - a Coord item
      item3 - a Coord item
      item4 - a Coord item
      Returns:
      a new CoordSet that holds the given items
    • with

      public static CoordSet with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5)
      Creates a new CoordSet that holds only the given items, but can be resized.
      Parameters:
      item0 - a Coord item
      item1 - a Coord item
      item2 - a Coord item
      item3 - a Coord item
      item4 - a Coord item
      item5 - a Coord item
      Returns:
      a new CoordSet that holds the given items
    • with

      public static CoordSet with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5, Coord item6)
      Creates a new CoordSet that holds only the given items, but can be resized.
      Parameters:
      item0 - a Coord item
      item1 - a Coord item
      item2 - a Coord item
      item3 - a Coord item
      item4 - a Coord item
      item5 - a Coord item
      item6 - a Coord item
      Returns:
      a new CoordSet that holds the given items
    • with

      public static CoordSet with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5, Coord item6, Coord item7)
      Creates a new CoordSet that holds only the given items, but can be resized.
      Parameters:
      item0 - a Coord item
      item1 - a Coord item
      item2 - a Coord item
      item3 - a Coord item
      item4 - a Coord item
      item5 - a Coord item
      item6 - a Coord item
      Returns:
      a new CoordSet that holds the given items
    • with

      @SafeVarargs public static CoordSet with(Coord... varargs)
      Creates a new CoordSet that holds only the given items, but can be resized. This overload will only be used when an array is supplied and the type of the items requested is the component type of the array, or if varargs are used and there are 9 or more arguments.
      Parameters:
      varargs - a Coord varargs or Coord array; remember that varargs allocate
      Returns:
      a new CoordSet that holds the given items
    • getSerializersNeeded

      public List<Class<?>> getSerializersNeeded()
      Specified by:
      getSerializersNeeded in interface com.github.yellowstonegames.core.ISerializersNeeded