Class CoordObjectMap<V>

java.lang.Object
com.github.tommyettinger.ds.ObjectObjectMap<Coord,V>
com.github.yellowstonegames.grid.CoordObjectMap<V>
All Implemented Interfaces:
com.github.yellowstonegames.core.ISerializersNeeded, Iterable<Map.Entry<Coord,V>>, Map<Coord,V>

public class CoordObjectMap<V> extends com.github.tommyettinger.ds.ObjectObjectMap<Coord,V> implements com.github.yellowstonegames.core.ISerializersNeeded
A variant on jdkgdxds' ObjectObjectMap class that only uses Coord keys, 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 keys placed into here, you should use a normal ObjectObjectMap instead, since some optimizations here require Coord keys 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.
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 key 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.ObjectObjectMap

    com.github.tommyettinger.ds.ObjectObjectMap.Entries<K,V>, com.github.tommyettinger.ds.ObjectObjectMap.Entry<K,V>, com.github.tommyettinger.ds.ObjectObjectMap.Keys<K,V>, com.github.tommyettinger.ds.ObjectObjectMap.MapIterator<K,V,I>, com.github.tommyettinger.ds.ObjectObjectMap.Values<K,V>
  • Field Summary

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

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

    Constructors
    Constructor
    Description
     
    CoordObjectMap(int initialCapacity)
     
    CoordObjectMap(int initialCapacity, float loadFactor)
     
    CoordObjectMap(com.github.tommyettinger.ds.ObjectObjectMap<? extends Coord, ? extends V> map)
     
    CoordObjectMap(Coord[] keys, V[] values)
     
    CoordObjectMap(Collection<? extends Coord> keys, Collection<? extends V> values)
     
    CoordObjectMap(Map<? extends Coord, ? extends V> map)
     
  • 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 <V> CoordObjectMap<V>
    with(Coord key0, V value0)
    Constructs a single-entry map given one key and one value.
    static <V> CoordObjectMap<V>
    with(Coord key0, V value0, Coord key1, V value1)
    Constructs a single-entry map given two key-value pairs.
    static <V> CoordObjectMap<V>
    with(Coord key0, V value0, Coord key1, V value1, Coord key2, V value2)
    Constructs a single-entry map given three key-value pairs.
    static <V> CoordObjectMap<V>
    with(Coord key0, V value0, Coord key1, V value1, Coord key2, V value2, Coord key3, V value3)
    Constructs a single-entry map given four key-value pairs.
    static <V> CoordObjectMap<V>
    with(Coord key0, V value0, Object... rest)
    Constructs a map given alternating keys and values.
    static <V> CoordObjectMap<V>
    Constructs an empty map given the types as generic type arguments.

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

    appendTo, appendTo, clear, clear, combine, combine, containsKey, containsValue, containsValue, ensureCapacity, entrySet, equals, equalsIdentity, findKey, findKey, get, getDefaultValue, getHashMultiplier, getLoadFactor, getOrDefault, getTableSize, hashCode, isEmpty, iterator, keySet, locateKey, notEmpty, parse, parse, parse, put, putAll, putAll, putAll, putAll, putAll, putAll, putLegible, putLegible, putLegible, putLegible, putOrDefault, putPairs, putResize, remove, replace, setDefaultValue, setHashMultiplier, setLoadFactor, shrink, size, toString, toString, toString, toString, truncate, values, with, with, with, with, with, with

    Methods inherited from class Object

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

    Methods inherited from interface Iterable

    forEach, spliterator
  • Constructor Details

    • CoordObjectMap

      public CoordObjectMap()
    • CoordObjectMap

      public CoordObjectMap(int initialCapacity)
    • CoordObjectMap

      public CoordObjectMap(int initialCapacity, float loadFactor)
    • CoordObjectMap

      public CoordObjectMap(com.github.tommyettinger.ds.ObjectObjectMap<? extends Coord, ? extends V> map)
    • CoordObjectMap

      public CoordObjectMap(Map<? extends Coord, ? extends V> map)
    • CoordObjectMap

      public CoordObjectMap(Coord[] keys, V[] values)
    • CoordObjectMap

      public CoordObjectMap(Collection<? extends Coord> keys, Collection<? extends V> values)
  • Method Details

    • place

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

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

      protected void resize(int newSize)
      Overrides:
      resize in class com.github.tommyettinger.ds.ObjectObjectMap<Coord,V>
    • withNothing

      public static <V> CoordObjectMap<V> withNothing()
      Constructs an empty map given the types as generic type arguments. 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.
      This needs to be named differently because of shadowing issues with the parent class.
      Type Parameters:
      V - the type of values
      Returns:
      a new map containing nothing
    • with

      public static <V> CoordObjectMap<V> with(Coord key0, V value0)
      Constructs a single-entry map given one key and one value. This is mostly useful as an optimization for with(Coord, Object, Object...) when there's no "rest" of the keys or values.
      Type Parameters:
      V - the type of value0
      Parameters:
      key0 - the first and only key
      value0 - the first and only value
      Returns:
      a new map containing just the entry mapping key0 to value0
    • with

      public static <V> CoordObjectMap<V> with(Coord key0, V value0, Coord key1, V value1)
      Constructs a single-entry map given two key-value pairs. This is mostly useful as an optimization for ObjectObjectMap.with(Object, Object, Object...) when there's no "rest" of the keys or values.
      Type Parameters:
      V - the type of value0
      Parameters:
      key0 - a Coord key
      value0 - a V value
      key1 - a Coord key
      value1 - a V value
      Returns:
      a new map containing entries mapping each key to the following value
    • with

      public static <V> CoordObjectMap<V> with(Coord key0, V value0, Coord key1, V value1, Coord key2, V value2)
      Constructs a single-entry map given three key-value pairs. This is mostly useful as an optimization for ObjectObjectMap.with(Object, Object, Object...) when there's no "rest" of the keys or values.
      Type Parameters:
      V - the type of value0
      Parameters:
      key0 - a Coord key
      value0 - a V value
      key1 - a Coord key
      value1 - a V value
      key2 - a Coord key
      value2 - a V value
      Returns:
      a new map containing entries mapping each key to the following value
    • with

      public static <V> CoordObjectMap<V> with(Coord key0, V value0, Coord key1, V value1, Coord key2, V value2, Coord key3, V value3)
      Constructs a single-entry map given four key-value pairs. This is mostly useful as an optimization for ObjectObjectMap.with(Object, Object, Object...) when there's no "rest" of the keys or values.
      Type Parameters:
      V - the type of value0
      Parameters:
      key0 - a Coord key
      value0 - a V value
      key1 - a Coord key
      value1 - a V value
      key2 - a Coord key
      value2 - a V value
      key3 - a Coord key
      value3 - a V value
      Returns:
      a new map containing entries mapping each key to the following value
    • with

      public static <V> CoordObjectMap<V> with(Coord key0, V value0, Object... rest)
      Constructs a map given alternating keys and values. This can be useful in some code-generation scenarios, or when you want to make a map conveniently by-hand and have it populated at the start. You can also use CoordObjectMap(Coord[], Object[]), which takes all keys and then all values. This needs all keys to be Coord and all values to have the same type, because it gets the value type from the first value parameter. Any keys that don't have Coord as their type or values that don't have V as their type have that entry skipped.
      Type Parameters:
      V - the type of values, inferred from value0
      Parameters:
      key0 - the first key; will be used to determine the type of all keys
      value0 - the first value; will be used to determine the type of all values
      rest - an array or varargs of alternating Coord, V, Coord, V... elements
      Returns:
      a new map containing the given keys and values
    • getSerializersNeeded

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