Package squidpony.squidmath
Class RegionMap<V>
java.lang.Object
squidpony.squidmath.OrderedMap<short[],V>
squidpony.squidmath.RegionMap<V>
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<short[],V>
,SortedMap<short[],V>
public class RegionMap<V> extends OrderedMap<short[],V> implements Serializable
A small extension of OrderedMap that specifically handles
short[]
regions as produced by CoordPacker
.
The methods allAt(int, int)
, containsRegion(short[])
, and regionsContaining(int, int)
are
added here, and the minor extra work needed to handle array keys in OrderedMap is taken care of automatically.
toString()
also produces nicer output by default for this usage, with the keys printed in a usable way.
Created by Tommy Ettinger on 11/24/2016.- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class squidpony.squidmath.OrderedMap
OrderedMap.KeyIterator, OrderedMap.KeySet, OrderedMap.MapEntrySet, OrderedMap.ValueCollection, OrderedMap.ValueIterator
-
Field Summary
Fields inherited from class squidpony.squidmath.OrderedMap
containsNullKey, DEFAULT_INITIAL_SIZE, DEFAULT_LOAD_FACTOR, defRetValue, entries, f, FAST_LOAD_FACTOR, hasher, key, keys, mask, maxFill, n, order, size, value, values, VERY_FAST_LOAD_FACTOR
-
Constructor Summary
Constructors Constructor Description RegionMap()
Creates a new RegionMap with initial expected 16 entries and 0.75f as load factor.RegionMap(int expected)
Creates a new RegionMap with 0.75f as load factor.RegionMap(int expected, float f)
RegionMap(short[][] keyArray, V[] valueArray)
Creates a new RegionMap with 0.75f as load factor using the elements of two parallel arrays.RegionMap(short[][] keyArray, V[] valueArray, float f)
Creates a new RegionMap using the elements of two parallel arrays.RegionMap(Collection<short[]> keyColl, Collection<V> valueColl, float f)
Creates a new RegionMap using the elements of two parallel arrays.RegionMap(Map<short[],? extends V> m)
Creates a new RegionMap with 0.75f as load factor copying a given one.RegionMap(Map<short[],? extends V> m, float f)
Creates a new RegionMap copying a given one. -
Method Summary
Modifier and Type Method Description ArrayList<V>
allAt(int x, int y)
Gets a List of all values associated with regions containing a given x,y point.boolean
containsRegion(short[] region)
Checks if a region, stored as packed data (possibly from CoordPacker or this class) overlaps with regions stored in this object as keys.OrderedSet<short[]>
regionsContaining(int x, int y)
Gets a List of all regions containing a given x,y point.String
toString()
String
toString(String separator)
Methods inherited from class squidpony.squidmath.OrderedMap
alter, alterAt, alterAtCarefully, alterCarefully, arraySize, clear, clone, comparator, containsKey, containsValue, defaultReturnValue, defaultReturnValue, ensureCapacity, entryAt, entrySet, equals, firstKey, fixOrder, fixOrder, get, getAndMoveToFirst, getAndMoveToLast, getAt, getMany, getOrDefault, hash64, hashCode, headMap, indexOf, isEmpty, keyAt, keysAsOrderedSet, keySet, lastKey, makeMap, makeMap, maxFill, objectUnwrap, objectUnwrap, positionOf, put, putAll, putAll, putAndMoveToFirst, putAndMoveToLast, putAt, putIfAbsent, putPairs, randomEntry, randomKey, randomValue, rehash, remove, remove, removeAt, removeEntry, removeFirst, removeLast, removeNullEntry, reorder, replace, replace, reverse, shiftKeys, shuffle, size, sort, sort, sortByValue, sortByValue, subMap, swap, swapIndices, tailMap, trim, trim, unwrap, unwrap, values, valuesAsList
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, merge, replaceAll
-
Constructor Details
-
RegionMap
-
RegionMap
Creates a new RegionMap with 0.75f as load factor.- Parameters:
expected
- the expected number of elements in the RegionMap.
-
RegionMap
public RegionMap()Creates a new RegionMap with initial expected 16 entries and 0.75f as load factor. -
RegionMap
Creates a new RegionMap copying a given one.- Parameters:
m
- aMap
to be copied into the new RegionMap.f
- the load factor.
-
RegionMap
Creates a new RegionMap with 0.75f as load factor copying a given one.- Parameters:
m
- aMap
to be copied into the new RegionMap.
-
RegionMap
Creates a new RegionMap using the elements of two parallel arrays.- Parameters:
keyArray
- the array of keys of the new RegionMap.valueArray
- the array of corresponding values in the new RegionMap.f
- the load factor.- Throws:
IllegalArgumentException
- ifk
andv
have different lengths.
-
RegionMap
Creates a new RegionMap using the elements of two parallel arrays.- Parameters:
keyColl
- the collection of keys of the new RegionMap.valueColl
- the collection of corresponding values in the new RegionMap.f
- the load factor.- Throws:
IllegalArgumentException
- ifk
andv
have different lengths.
-
RegionMap
Creates a new RegionMap with 0.75f as load factor using the elements of two parallel arrays.- Parameters:
keyArray
- the array of keys of the new RegionMap.valueArray
- the array of corresponding values in the new RegionMap.- Throws:
IllegalArgumentException
- ifk
andv
have different lengths.
-
-
Method Details
-
allAt
Gets a List of all values associated with regions containing a given x,y point.- Parameters:
x
- the x coordinate of the point in questiony
- the y coordinate of the point in question- Returns:
- an ArrayList of all V values corresponding to regions containing the given x,y point.
-
containsRegion
Checks if a region, stored as packed data (possibly from CoordPacker or this class) overlaps with regions stored in this object as keys. Returns true if there is any overlap, false otherwise- Parameters:
region
- the packed region to check for overlap with regions this stores values for- Returns:
- true if the region overlaps at all, false otherwise
-
regionsContaining
Gets a List of all regions containing a given x,y point.- Parameters:
x
- the x coordinate of the point in questiony
- the y coordinate of the point in question- Returns:
- an ArrayList of all regions in this data structure containing the given x,y point.
-
toString
-
toString
- Overrides:
toString
in classOrderedMap<short[],V>
-