Class CoordObjectOrderedMap<V>
- All Implemented Interfaces:
com.github.tommyettinger.ds.Arrangeable, com.github.tommyettinger.ds.Ordered<Coord>, com.github.yellowstonegames.core.ISerializersNeeded, Iterable<Map.Entry<Coord,V>>, Map<Coord, V>
public class CoordObjectOrderedMap<V>
extends com.github.tommyettinger.ds.ObjectObjectOrderedMap<Coord,V>
implements com.github.yellowstonegames.core.ISerializersNeeded
A variant on jdkgdxds'
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
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.
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 ObjectObjectOrderedMap 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.ObjectObjectOrderedMap
com.github.tommyettinger.ds.ObjectObjectOrderedMap.OrderedMapEntries<K,V>, com.github.tommyettinger.ds.ObjectObjectOrderedMap.OrderedMapKeys<K, V>, com.github.tommyettinger.ds.ObjectObjectOrderedMap.OrderedMapValues<K, V> 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> 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.ObjectObjectOrderedMap
keysFields inherited from class com.github.tommyettinger.ds.ObjectObjectMap
defaultValue, keyTable, loadFactor, mask, shift, size, threshold, valueTable -
Constructor Summary
ConstructorsConstructorDescriptionCoordObjectOrderedMap(int initialCapacity) CoordObjectOrderedMap(int initialCapacity, float loadFactor) CoordObjectOrderedMap(int initialCapacity, float loadFactor, com.github.tommyettinger.ds.OrderType type) CoordObjectOrderedMap(int initialCapacity, com.github.tommyettinger.ds.OrderType type) CoordObjectOrderedMap(com.github.tommyettinger.ds.ObjectObjectOrderedMap<? extends Coord, ? extends V> map) CoordObjectOrderedMap(com.github.tommyettinger.ds.ObjectObjectOrderedMap<? extends Coord, ? extends V> map, com.github.tommyettinger.ds.OrderType type) CoordObjectOrderedMap(com.github.tommyettinger.ds.OrderType type) CoordObjectOrderedMap(Coord[] keys, V[] values) CoordObjectOrderedMap(Coord[] keys, V[] values, com.github.tommyettinger.ds.OrderType type) CoordObjectOrderedMap(Collection<? extends Coord> keys, Collection<? extends V> values) CoordObjectOrderedMap(Collection<? extends Coord> keys, Collection<? extends V> values, com.github.tommyettinger.ds.OrderType type) CoordObjectOrderedMap(Map<? extends Coord, ? extends V> map) CoordObjectOrderedMap(Map<? extends Coord, ? extends V> map, com.github.tommyettinger.ds.OrderType type) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanprotected intprotected voidresize(int newSize) static <V> CoordObjectOrderedMap<V> Constructs a single-entry map given one key and one value.static <V> CoordObjectOrderedMap<V> Constructs a single-entry map given two key-value pairs.static <V> CoordObjectOrderedMap<V> Constructs a single-entry map given three key-value pairs.static <V> CoordObjectOrderedMap<V> Constructs a single-entry map given four key-value pairs.static <V> CoordObjectOrderedMap<V> Constructs a map given alternating keys and values.static <V> CoordObjectOrderedMap<V> Constructs an empty map given the types as generic type arguments.Methods inherited from class com.github.tommyettinger.ds.ObjectObjectOrderedMap
alter, alterAt, appendTo, clear, clear, ensureCapacity, entrySet, 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, withMethods inherited from class com.github.tommyettinger.ds.ObjectObjectMap
appendTo, combine, combine, containsKey, containsValue, containsValue, equals, equalsIdentity, findKey, findKey, get, getDefaultValue, getHashMultiplier, getLoadFactor, getOrDefault, getTableSize, hashCode, isEmpty, locateKey, notEmpty, putAll, putAll, putAll, putAll, putAll, putAll, putLegible, putLegible, putLegible, putLegible, putPairs, putResize, replace, setDefaultValue, setHashMultiplier, setLoadFactor, shrink, size, toString, toString, toString, toStringMethods inherited from interface com.github.tommyettinger.ds.Arrangeable
rearrange, shuffle, sizeMethods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, forEach, merge, putIfAbsent, remove, replace, replaceAllMethods inherited from interface com.github.tommyettinger.ds.Ordered
getOrderType, random, random, reverse, selectRanked, selectRankedIndex, shuffle, swap
-
Constructor Details
-
CoordObjectOrderedMap
public CoordObjectOrderedMap(com.github.tommyettinger.ds.OrderType type) -
CoordObjectOrderedMap
public CoordObjectOrderedMap(int initialCapacity, com.github.tommyettinger.ds.OrderType type) -
CoordObjectOrderedMap
public CoordObjectOrderedMap(int initialCapacity, float loadFactor, com.github.tommyettinger.ds.OrderType type) -
CoordObjectOrderedMap
-
CoordObjectOrderedMap
-
CoordObjectOrderedMap
-
CoordObjectOrderedMap
public CoordObjectOrderedMap(Collection<? extends Coord> keys, Collection<? extends V> values, com.github.tommyettinger.ds.OrderType type) -
CoordObjectOrderedMap
public CoordObjectOrderedMap() -
CoordObjectOrderedMap
public CoordObjectOrderedMap(int initialCapacity) -
CoordObjectOrderedMap
public CoordObjectOrderedMap(int initialCapacity, float loadFactor) -
CoordObjectOrderedMap
-
CoordObjectOrderedMap
-
CoordObjectOrderedMap
-
CoordObjectOrderedMap
-
-
Method Details
-
place
-
equate
-
resize
-
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
Constructs a single-entry map given one key and one value. This is mostly useful as an optimization forwith(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 keyvalue0- the first and only value- Returns:
- a new map containing just the entry mapping key0 to value0
-
with
Constructs a single-entry map given two key-value pairs. This is mostly useful as an optimization forObjectObjectOrderedMap.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 keyvalue0- a V valuekey1- a Coord keyvalue1- a V value- Returns:
- a new map containing entries mapping each key to the following value
-
with
public static <V> CoordObjectOrderedMap<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 forObjectObjectOrderedMap.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 keyvalue0- a V valuekey1- a Coord keyvalue1- a V valuekey2- a Coord keyvalue2- a V value- Returns:
- a new map containing entries mapping each key to the following value
-
with
public static <V> CoordObjectOrderedMap<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 forObjectObjectOrderedMap.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 keyvalue0- a V valuekey1- a Coord keyvalue1- a V valuekey2- a Coord keyvalue2- a V valuekey3- a Coord keyvalue3- a V value- Returns:
- a new map containing entries mapping each key to the following value
-
with
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 useCoordObjectOrderedMap(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 keysvalue0- the first value; will be used to determine the type of all valuesrest- an array or varargs of alternating Coord, V, Coord, V... elements- Returns:
- a new map containing the given keys and values
-
getSerializersNeeded
-