Class CoordFloatMap
java.lang.Object
com.github.tommyettinger.ds.ObjectFloatMap<Coord>
com.github.yellowstonegames.grid.CoordFloatMap
- All Implemented Interfaces:
com.github.yellowstonegames.core.ISerializersNeeded, Iterable<com.github.tommyettinger.ds.ObjectFloatMap.Entry<Coord>>
public class CoordFloatMap
extends com.github.tommyettinger.ds.ObjectFloatMap<Coord>
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.
You can create a CoordFloatMap with
ObjectFloatMap 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 ObjectFloatMap 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 CoordFloatMap with
fromArray2D(float[][], float, float) if you have a 2D float 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.ObjectFloatMap
com.github.tommyettinger.ds.ObjectFloatMap.Entries<K>, com.github.tommyettinger.ds.ObjectFloatMap.Entry<K>, com.github.tommyettinger.ds.ObjectFloatMap.EntryIterator<K>, com.github.tommyettinger.ds.ObjectFloatMap.KeyIterator<K>, com.github.tommyettinger.ds.ObjectFloatMap.Keys<K>, com.github.tommyettinger.ds.ObjectFloatMap.MapIterator<K>, com.github.tommyettinger.ds.ObjectFloatMap.ValueIterator<K>, com.github.tommyettinger.ds.ObjectFloatMap.Values<K> -
Field Summary
Fields inherited from class com.github.tommyettinger.ds.ObjectFloatMap
defaultValue, keyTable, loadFactor, mask, shift, size, threshold, valueTable -
Constructor Summary
ConstructorsConstructorDescriptionCoordFloatMap(int initialCapacity) CoordFloatMap(int initialCapacity, float loadFactor) CoordFloatMap(com.github.tommyettinger.ds.ObjectFloatMap<? extends Coord> map) CoordFloatMap(Coord[] keys, float[] values) CoordFloatMap(Collection<? extends Coord> keys, com.github.tommyettinger.ds.PrimitiveCollection.OfFloat values) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanstatic CoordFloatMapfromArray2D(float[][] array, float min, float max) Given a 2D float 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 CoordFloatMap.protected intprotected voidresize(int newSize) static CoordFloatMapConstructs a single-entry map given one key and one value.static CoordFloatMapConstructs a map given alternating keys and values.static CoordFloatMapConstructs a map given alternating keys and values.static CoordFloatMapwith(Coord key0, Number value0, Coord key1, Number value1, Coord key2, Number value2, Coord key3, Number value3) Constructs a map given alternating keys and values.static CoordFloatMapConstructs a map given alternating keys and values.static CoordFloatMapConstructs an empty map.static CoordFloatMapConstructs an empty map given the key type as a generic type argument.static CoordFloatMapwithPrimitive(Coord key0, float value0) Constructs a single-entry map given one key and one value.static CoordFloatMapwithPrimitive(Coord key0, float value0, Coord key1, float value1) Constructs a map given alternating keys and values.static CoordFloatMapwithPrimitive(Coord key0, float value0, Coord key1, float value1, Coord key2, float value2) Constructs a map given alternating keys and values.static CoordFloatMapwithPrimitive(Coord key0, float value0, Coord key1, float value1, Coord key2, float value2, Coord key3, float value3) Constructs a map given alternating keys and values.Methods inherited from class com.github.tommyettinger.ds.ObjectFloatMap
appendTo, appendTo, clear, clear, combine, combine, computeIfAbsent, containsKey, containsValue, containsValue, ensureCapacity, entrySet, equals, findKey, findKey, forEach, get, getAndIncrement, getDefaultValue, getHashMultiplier, getLoadFactor, getOrDefault, getTableSize, hashCode, isEmpty, iterator, keySet, locateKey, notEmpty, parse, parse, parse, put, putAll, putAll, putAll, putAll, putAll, putIfAbsent, putLegible, putLegible, putLegible, putLegible, putOrDefault, putPairs, putResize, remove, remove, replace, replace, replaceAll, setDefaultValue, setHashMultiplier, setLoadFactor, shrink, size, toString, toString, toString, toString, truncate, values, with, with, with, with, with, with, withPrimitive, withPrimitive, withPrimitive, withPrimitiveMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
CoordFloatMap
public CoordFloatMap() -
CoordFloatMap
public CoordFloatMap(int initialCapacity) -
CoordFloatMap
public CoordFloatMap(int initialCapacity, float loadFactor) -
CoordFloatMap
-
CoordFloatMap
-
CoordFloatMap
public CoordFloatMap(Collection<? extends Coord> keys, com.github.tommyettinger.ds.PrimitiveCollection.OfFloat values)
-
-
Method Details
-
place
-
equate
-
resize
protected void resize(int newSize) - Overrides:
resizein classcom.github.tommyettinger.ds.ObjectFloatMap<Coord>
-
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
Constructs a single-entry map given one key and one value. This is mostly useful as an optimization forwith(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 float, regardless of which Number type was used.- Parameters:
key0- the first and only keyvalue0- the first and only value; will be converted to primitive float- Returns:
- a new map containing just the entry mapping key0 to value0
-
with
Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(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 floats, regardless of which Number type was used.- Parameters:
key0- a Coord keyvalue0- a Number for a value; will be converted to primitive floatkey1- a Coord keyvalue1- a Number for a value; will be converted to primitive float- Returns:
- a new map containing the given key-value pairs
-
with
public static CoordFloatMap 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 forwith(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 floats, regardless of which Number type was used.- Parameters:
key0- a Coord keyvalue0- a Number for a value; will be converted to primitive floatkey1- a Coord keyvalue1- a Number for a value; will be converted to primitive floatkey2- a Coord keyvalue2- a Number for a value; will be converted to primitive float- Returns:
- a new map containing the given key-value pairs
-
with
public static CoordFloatMap 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 forwith(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 floats, regardless of which Number type was used.- Parameters:
key0- a Coord keyvalue0- a Number for a value; will be converted to primitive floatkey1- a Coord keyvalue1- a Number for a value; will be converted to primitive floatkey2- a Coord keyvalue2- a Number for a value; will be converted to primitive floatkey3- a Coord keyvalue3- a Number for a value; will be converted to primitive float- Returns:
- a new map containing the given key-value pairs
-
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 useCoordFloatMap(Coord[], float[]), 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 asIntegerorDouble, and will be converted to primitivefloats. Any keys that don't have Coord as their type or values that aren'tNumbers have that entry skipped.- Parameters:
key0- the first key; will be used to determine the type of all keysvalue0- the first value; will be converted to primitive floatrest- 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
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
Constructs a single-entry map given one key and one value. This is mostly useful as an optimization forwith(Coord, Number, Object...)when there's no "rest" of the keys or values. Unlike with(), this takes unboxed float as its value type, and will not box it.- Parameters:
key0- a Coord for a keyvalue0- a float for a value- Returns:
- a new map containing just the entry mapping key0 to value0
-
withPrimitive
Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Coord, Number, Object...)when there's no "rest" of the keys or values. Unlike with(), this takes unboxed float as its value type, and will not box it.- Parameters:
key0- a Coord keyvalue0- a float for a valuekey1- a Coord keyvalue1- a float for a value- Returns:
- a new map containing the given key-value pairs
-
withPrimitive
public static CoordFloatMap withPrimitive(Coord key0, float value0, Coord key1, float value1, Coord key2, float value2) Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Coord, Number, Object...)when there's no "rest" of the keys or values. Unlike with(), this takes unboxed float as its value type, and will not box it.- Parameters:
key0- a Coord keyvalue0- a float for a valuekey1- a Coord keyvalue1- a float for a valuekey2- a Coord keyvalue2- a float for a value- Returns:
- a new map containing the given key-value pairs
-
withPrimitive
public static CoordFloatMap withPrimitive(Coord key0, float value0, Coord key1, float value1, Coord key2, float value2, Coord key3, float value3) Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Coord, Number, Object...)when there's no "rest" of the keys or values. Unlike with(), this takes unboxed float as its value type, and will not box it.- Parameters:
key0- a Coord keyvalue0- a float for a valuekey1- a Coord keyvalue1- a float for a valuekey2- a Coord keyvalue2- a float for a valuekey3- a Coord keyvalue3- a float for a value- Returns:
- a new map containing the given key-value pairs
-
fromArray2D
Given a 2D float 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 CoordFloatMap. If you need to get a sorted ordering, useCoordFloatOrderedMap.fromArray2D(float[][], float, float)and sort the result.- Parameters:
array- a usually-rectangular 2D float arraymin- the inclusive minimum valuemax- the inclusive maximum value- Returns:
- a new CoordFloatMap containing all positions with in-range values, mapped to those values.
-
getSerializersNeeded
-