Class CoordIntOrderedMap

java.lang.Object
com.github.tommyettinger.ds.ObjectIntMap<Coord>
com.github.tommyettinger.ds.ObjectIntOrderedMap<Coord>
com.github.yellowstonegames.grid.CoordIntOrderedMap
All Implemented Interfaces:
com.github.tommyettinger.ds.Arrangeable, com.github.tommyettinger.ds.Ordered<Coord>, com.github.yellowstonegames.core.ISerializersNeeded, Iterable<com.github.tommyettinger.ds.ObjectIntMap.Entry<Coord>>

public class CoordIntOrderedMap extends com.github.tommyettinger.ds.ObjectIntOrderedMap<Coord> implements com.github.yellowstonegames.core.ISerializersNeeded
A variant on jdkgdxds' ObjectIntOrderedMap 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 ObjectIntOrderedMap 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.
You can create a CoordIntOrderedMap with fromArray2D(int[][], int, int) if you have a 2D int array and want to get the positions within some range of values.
  • Nested Class Summary

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

    com.github.tommyettinger.ds.ObjectIntOrderedMap.OrderedMapEntries<K>, com.github.tommyettinger.ds.ObjectIntOrderedMap.OrderedMapKeys<K>, com.github.tommyettinger.ds.ObjectIntOrderedMap.OrderedMapValues<K>

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

    com.github.tommyettinger.ds.ObjectIntMap.Entries<K>, com.github.tommyettinger.ds.ObjectIntMap.Entry<K>, com.github.tommyettinger.ds.ObjectIntMap.EntryIterator<K>, com.github.tommyettinger.ds.ObjectIntMap.KeyIterator<K>, com.github.tommyettinger.ds.ObjectIntMap.Keys<K>, com.github.tommyettinger.ds.ObjectIntMap.MapIterator<K>, com.github.tommyettinger.ds.ObjectIntMap.ValueIterator<K>, com.github.tommyettinger.ds.ObjectIntMap.Values<K>

    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.ObjectIntOrderedMap

    keys

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

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

    Constructors
    Constructor
    Description
     
    CoordIntOrderedMap(int initialCapacity)
     
    CoordIntOrderedMap(int initialCapacity, float loadFactor)
     
    CoordIntOrderedMap(int initialCapacity, float loadFactor, com.github.tommyettinger.ds.OrderType type)
     
    CoordIntOrderedMap(int initialCapacity, com.github.tommyettinger.ds.OrderType type)
     
    CoordIntOrderedMap(com.github.tommyettinger.ds.ObjectIntMap<? extends Coord> map)
     
    CoordIntOrderedMap(com.github.tommyettinger.ds.ObjectIntMap<? extends Coord> map, com.github.tommyettinger.ds.OrderType type)
     
    CoordIntOrderedMap(com.github.tommyettinger.ds.ObjectIntOrderedMap<? extends Coord> map)
     
    CoordIntOrderedMap(com.github.tommyettinger.ds.ObjectIntOrderedMap<? extends Coord> other, int offset, int count)
     
    CoordIntOrderedMap(com.github.tommyettinger.ds.ObjectIntOrderedMap<? extends Coord> other, int offset, int count, com.github.tommyettinger.ds.OrderType type)
     
    CoordIntOrderedMap(com.github.tommyettinger.ds.ObjectIntOrderedMap<? extends Coord> map, com.github.tommyettinger.ds.OrderType type)
     
    CoordIntOrderedMap(com.github.tommyettinger.ds.OrderType type)
     
    CoordIntOrderedMap(Coord[] keys, int[] values)
     
    CoordIntOrderedMap(Coord[] keys, int[] values, com.github.tommyettinger.ds.OrderType type)
     
    CoordIntOrderedMap(Collection<? extends Coord> keys, com.github.tommyettinger.ds.PrimitiveCollection.OfInt values)
     
    CoordIntOrderedMap(Collection<? extends Coord> keys, com.github.tommyettinger.ds.PrimitiveCollection.OfInt values, com.github.tommyettinger.ds.OrderType type)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    equate(Object left, Object right)
     
    fromArray2D(int[][] array, int min, int max)
    Given a 2D int array (which should usually be rectangular), this finds the positions with values between min (inclusive) and max (also inclusive), and places them in a newly-allocated CoordIntOrderedMap.
     
    protected int
    place(Object item)
     
    protected void
    resize(int newSize)
     
    with(Coord key0, Number value0)
    Constructs a single-entry map given one key and one value.
    with(Coord key0, Number value0, Coord key1, Number value1)
    Constructs a map given alternating keys and values.
    with(Coord key0, Number value0, Coord key1, Number value1, Coord key2, Number value2)
    Constructs a map given alternating keys and values.
    with(Coord key0, Number value0, Coord key1, Number value1, Coord key2, Number value2, Coord key3, Number value3)
    Constructs a map given alternating keys and values.
    with(Coord key0, Number value0, Object... rest)
    Constructs a map given alternating keys and values.
    Constructs an empty map.
    Constructs an empty map given the key type as a generic type argument.
    withPrimitive(Coord key0, int value0)
    Constructs a single-entry map given one key and one value.
    withPrimitive(Coord key0, int value0, Coord key1, int value1)
    Constructs a map given alternating keys and values.
    withPrimitive(Coord key0, int value0, Coord key1, int value1, Coord key2, int value2)
    Constructs a map given alternating keys and values.
    withPrimitive(Coord key0, int value0, Coord key1, int value1, Coord key2, int value2, Coord key3, int value3)
    Constructs a map given alternating keys and values.

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

    alter, alterAt, appendTo, clear, clear, ensureCapacity, entrySet, getAndIncrement, getAt, iterator, keyAt, keySet, order, parse, parse, parse, put, put, putAll, putAll, putAll, putOrDefault, remove, removeAt, removeRange, setAt, sort, sort, sortByValue, truncate, values, with, with, with, with, with, with, withPrimitive, withPrimitive, withPrimitive, withPrimitive

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

    appendTo, combine, combine, computeIfAbsent, containsKey, containsValue, equals, findKey, forEach, get, getDefaultValue, getHashMultiplier, getLoadFactor, getOrDefault, getTableSize, hashCode, isEmpty, locateKey, notEmpty, putAll, putAll, putAll, putAll, putAll, putIfAbsent, putLegible, putLegible, putLegible, putLegible, putPairs, putResize, remove, replace, replace, replaceAll, setDefaultValue, setHashMultiplier, setLoadFactor, shrink, size, toString, toString, toString, toString

    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 Iterable

    forEach, spliterator

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

    getOrderType, random, random, reverse, selectRanked, selectRankedIndex, shuffle, swap
  • Constructor Details

    • CoordIntOrderedMap

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

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

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

      public CoordIntOrderedMap(com.github.tommyettinger.ds.ObjectIntOrderedMap<? extends Coord> map, com.github.tommyettinger.ds.OrderType type)
    • CoordIntOrderedMap

      public CoordIntOrderedMap(com.github.tommyettinger.ds.ObjectIntMap<? extends Coord> map, com.github.tommyettinger.ds.OrderType type)
    • CoordIntOrderedMap

      public CoordIntOrderedMap(Coord[] keys, int[] values, com.github.tommyettinger.ds.OrderType type)
    • CoordIntOrderedMap

      public CoordIntOrderedMap(Collection<? extends Coord> keys, com.github.tommyettinger.ds.PrimitiveCollection.OfInt values, com.github.tommyettinger.ds.OrderType type)
    • CoordIntOrderedMap

      public CoordIntOrderedMap(com.github.tommyettinger.ds.ObjectIntOrderedMap<? extends Coord> other, int offset, int count, com.github.tommyettinger.ds.OrderType type)
    • CoordIntOrderedMap

      public CoordIntOrderedMap()
    • CoordIntOrderedMap

      public CoordIntOrderedMap(int initialCapacity)
    • CoordIntOrderedMap

      public CoordIntOrderedMap(int initialCapacity, float loadFactor)
    • CoordIntOrderedMap

      public CoordIntOrderedMap(com.github.tommyettinger.ds.ObjectIntOrderedMap<? extends Coord> map)
    • CoordIntOrderedMap

      public CoordIntOrderedMap(com.github.tommyettinger.ds.ObjectIntMap<? extends Coord> map)
    • CoordIntOrderedMap

      public CoordIntOrderedMap(Coord[] keys, int[] values)
    • CoordIntOrderedMap

      public CoordIntOrderedMap(Collection<? extends Coord> keys, com.github.tommyettinger.ds.PrimitiveCollection.OfInt values)
    • CoordIntOrderedMap

      public CoordIntOrderedMap(com.github.tommyettinger.ds.ObjectIntOrderedMap<? extends Coord> other, int offset, int count)
  • Method Details

    • place

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

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

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

      public static CoordIntOrderedMap withNothing()
      Constructs an empty map. 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.
      Returns:
      a new map containing nothing
    • with

      public static CoordIntOrderedMap with(Coord key0, Number value0)
      Constructs a single-entry map given one key and one value. This is mostly useful as an optimization for with(Coord, Number, Object...) when there's no "rest" of the keys or values. Like the more-argument with(), this will convert its Number value to a primitive int, regardless of which Number type was used.
      Parameters:
      key0 - the first and only key
      value0 - the first and only value; will be converted to primitive int
      Returns:
      a new map containing just the entry mapping key0 to value0
    • with

      public static CoordIntOrderedMap with(Coord key0, Number value0, Coord key1, Number value1)
      Constructs a map given alternating keys and values. This is mostly useful as an optimization for with(Coord, Number, Object...) when there's no "rest" of the keys or values. Like the more-argument with(), this will convert its Number values to primitive ints, regardless of which Number type was used.
      Parameters:
      key0 - a Coord key
      value0 - a Number for a value; will be converted to primitive int
      key1 - a Coord key
      value1 - a Number for a value; will be converted to primitive int
      Returns:
      a new map containing the given key-value pairs
    • with

      public static CoordIntOrderedMap with(Coord key0, Number value0, Coord key1, Number value1, Coord key2, Number value2)
      Constructs a map given alternating keys and values. This is mostly useful as an optimization for with(Coord, Number, Object...) when there's no "rest" of the keys or values. Like the more-argument with(), this will convert its Number values to primitive ints, regardless of which Number type was used.
      Parameters:
      key0 - a Coord key
      value0 - a Number for a value; will be converted to primitive int
      key1 - a Coord key
      value1 - a Number for a value; will be converted to primitive int
      key2 - a Coord key
      value2 - a Number for a value; will be converted to primitive int
      Returns:
      a new map containing the given key-value pairs
    • with

      public static CoordIntOrderedMap with(Coord key0, Number value0, Coord key1, Number value1, Coord key2, Number value2, Coord key3, Number value3)
      Constructs a map given alternating keys and values. This is mostly useful as an optimization for with(Coord, Number, Object...) when there's no "rest" of the keys or values. Like the more-argument with(), this will convert its Number values to primitive ints, regardless of which Number type was used.
      Parameters:
      key0 - a Coord key
      value0 - a Number for a value; will be converted to primitive int
      key1 - a Coord key
      value1 - a Number for a value; will be converted to primitive int
      key2 - a Coord key
      value2 - a Number for a value; will be converted to primitive int
      key3 - a Coord key
      value3 - a Number for a value; will be converted to primitive int
      Returns:
      a new map containing the given key-value pairs
    • with

      public static CoordIntOrderedMap with(Coord key0, Number 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 CoordIntOrderedMap(Coord[], int[]), which takes all keys and then all values. This needs all keys to have the same type, because it gets a generic type from the first key parameter. All values must be some type of boxed Number, such as Integer or Double, and will be converted to primitive ints. Any keys that don't have Coord as their type or values that aren't Numbers have that entry skipped.
      Parameters:
      key0 - the first key; will be used to determine the type of all keys
      value0 - the first value; will be converted to primitive int
      rest - an array or varargs of alternating Coord, Number, Coord, Number... elements, inferred from key0
      Returns:
      a new map containing the given keys and values
    • withPrimitive

      public static CoordIntOrderedMap withPrimitive()
      Constructs an empty map given the key 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 map containing nothing
    • withPrimitive

      public static CoordIntOrderedMap withPrimitive(Coord key0, int value0)
      Constructs a single-entry map given one key and one value. This is mostly useful as an optimization for with(Coord, Number, Object...) when there's no "rest" of the keys or values. Unlike with(), this takes unboxed int as its value type, and will not box it.
      Parameters:
      key0 - a Coord for a key
      value0 - a int for a value
      Returns:
      a new map containing just the entry mapping key0 to value0
    • withPrimitive

      public static CoordIntOrderedMap withPrimitive(Coord key0, int value0, Coord key1, int value1)
      Constructs a map given alternating keys and values. This is mostly useful as an optimization for with(Coord, Number, Object...) when there's no "rest" of the keys or values. Unlike with(), this takes unboxed int as its value type, and will not box it.
      Parameters:
      key0 - a Coord key
      value0 - a int for a value
      key1 - a Coord key
      value1 - a int for a value
      Returns:
      a new map containing the given key-value pairs
    • withPrimitive

      public static CoordIntOrderedMap withPrimitive(Coord key0, int value0, Coord key1, int value1, Coord key2, int value2)
      Constructs a map given alternating keys and values. This is mostly useful as an optimization for with(Coord, Number, Object...) when there's no "rest" of the keys or values. Unlike with(), this takes unboxed int as its value type, and will not box it.
      Parameters:
      key0 - a Coord key
      value0 - a int for a value
      key1 - a Coord key
      value1 - a int for a value
      key2 - a Coord key
      value2 - a int for a value
      Returns:
      a new map containing the given key-value pairs
    • withPrimitive

      public static CoordIntOrderedMap withPrimitive(Coord key0, int value0, Coord key1, int value1, Coord key2, int value2, Coord key3, int value3)
      Constructs a map given alternating keys and values. This is mostly useful as an optimization for with(Coord, Number, Object...) when there's no "rest" of the keys or values. Unlike with(), this takes unboxed int as its value type, and will not box it.
      Parameters:
      key0 - a Coord key
      value0 - a int for a value
      key1 - a Coord key
      value1 - a int for a value
      key2 - a Coord key
      value2 - a int for a value
      key3 - a Coord key
      value3 - a int for a value
      Returns:
      a new map containing the given key-value pairs
    • fromArray2D

      public static CoordIntOrderedMap fromArray2D(int[][] array, int min, int max)
      Given a 2D int array (which should usually be rectangular), this finds the positions with values between min (inclusive) and max (also inclusive), and places them in a newly-allocated CoordIntOrderedMap. You may want to sort this by value, using ObjectIntOrderedMap.sortByValue(IntComparator), so the highest or lowest int values beint to the first or last items in the order.
      Parameters:
      array - a usually-rectangular 2D int array
      min - the inclusive minimum value
      max - the inclusive maximum value
      Returns:
      a new CoordIntOrderedMap containing all positions with in-range values, mapped to those values.
    • getSerializersNeeded

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