Class CoordOrderedSet

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

public class CoordOrderedSet extends com.github.tommyettinger.ds.ObjectOrderedSet<Coord> implements com.github.yellowstonegames.core.ISerializersNeeded
A variant on jdkgdxds' ObjectOrderedSet 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 ObjectOrderedSet 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, plus size proportional to ObjectSet.size() for the order.
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.ObjectOrderedSet

    com.github.tommyettinger.ds.ObjectOrderedSet.ObjectOrderedSetIterator<K>

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

    com.github.tommyettinger.ds.ObjectSet.ObjectSetIterator<T>

    Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.Arrangeable

    com.github.tommyettinger.ds.Arrangeable.ArrangeableList<T>

    Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.Ordered

    com.github.tommyettinger.ds.Ordered.OfBoolean, com.github.tommyettinger.ds.Ordered.OfByte, com.github.tommyettinger.ds.Ordered.OfChar, com.github.tommyettinger.ds.Ordered.OfDouble, com.github.tommyettinger.ds.Ordered.OfFloat, com.github.tommyettinger.ds.Ordered.OfInt, com.github.tommyettinger.ds.Ordered.OfLong, com.github.tommyettinger.ds.Ordered.OfShort
  • Field Summary

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

    items

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

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

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

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

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

    add, add, addAll, addAll, alter, alterAt, appendTo, clear, clear, ensureCapacity, first, getAt, hashCode, iterator, order, parse, parse, parse, remove, removeAt, removeRange, sort, sort, toString, toString, truncate, with, with, with, with, with, with, with, with, with

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

    addAll, addAll, addAll, addAll, addResize, contains, containsAll, containsAll, containsAll, containsAny, containsAny, containsAnyIterable, equals, get, getHashMultiplier, getLoadFactor, getTableSize, isEmpty, locateKey, notEmpty, removeAll, removeAll, removeAll, retainAll, setHashMultiplier, setLoadFactor, shrink, size, toArray, toArray

    Methods inherited from class Object

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

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

    rearrange, shuffle, size

    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

    Methods inherited from interface Iterable

    forEach

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

    getOrderType, random, random, reverse, selectRanked, selectRankedIndex, shuffle, swap

    Methods inherited from interface Set

    spliterator
  • Constructor Details

    • CoordOrderedSet

      public CoordOrderedSet(com.github.tommyettinger.ds.OrderType type)
    • CoordOrderedSet

      public CoordOrderedSet(int initialCapacity, float loadFactor, com.github.tommyettinger.ds.OrderType type)
    • CoordOrderedSet

      public CoordOrderedSet(int initialCapacity, com.github.tommyettinger.ds.OrderType type)
    • CoordOrderedSet

      public CoordOrderedSet(com.github.tommyettinger.ds.ObjectOrderedSet<? extends Coord> set, com.github.tommyettinger.ds.OrderType type)
    • CoordOrderedSet

      public CoordOrderedSet(Collection<? extends Coord> coll, com.github.tommyettinger.ds.OrderType type)
    • CoordOrderedSet

      public CoordOrderedSet(Coord[] array, int offset, int length, com.github.tommyettinger.ds.OrderType type)
    • CoordOrderedSet

      public CoordOrderedSet(Coord[] items, com.github.tommyettinger.ds.OrderType type)
    • CoordOrderedSet

      public CoordOrderedSet()
    • CoordOrderedSet

      public CoordOrderedSet(int initialCapacity, float loadFactor)
    • CoordOrderedSet

      public CoordOrderedSet(int initialCapacity)
    • CoordOrderedSet

      public CoordOrderedSet(com.github.tommyettinger.ds.ObjectOrderedSet<? extends Coord> set)
    • CoordOrderedSet

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

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

      public CoordOrderedSet(Coord[] items)
  • 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 CoordOrderedSet 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 CoordOrderedSet with(Coord item)
      Creates a new CoordOrderedSet that holds only the given item, but can be resized.
      Parameters:
      item - one Coord item
      Returns:
      a new CoordOrderedSet that holds the given item
    • with

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

      public static CoordOrderedSet with(Coord item0, Coord item1, Coord item2)
      Creates a new CoordOrderedSet 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 CoordOrderedSet that holds the given items
    • with

      public static CoordOrderedSet with(Coord item0, Coord item1, Coord item2, Coord item3)
      Creates a new CoordOrderedSet 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 CoordOrderedSet that holds the given items
    • with

      public static CoordOrderedSet with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4)
      Creates a new CoordOrderedSet 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 CoordOrderedSet that holds the given items
    • with

      public static CoordOrderedSet with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5)
      Creates a new CoordOrderedSet 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 CoordOrderedSet that holds the given items
    • with

      public static CoordOrderedSet with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5, Coord item6)
      Creates a new CoordOrderedSet 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 CoordOrderedSet that holds the given items
    • with

      public static CoordOrderedSet with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5, Coord item6, Coord item7)
      Creates a new CoordOrderedSet 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 CoordOrderedSet that holds the given items
    • with

      public static CoordOrderedSet with(Coord... varargs)
      Creates a new CoordOrderedSet 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 CoordOrderedSet that holds the given items
    • getSerializersNeeded

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