Package arc.struct
Class OrderedMap<K,V>
java.lang.Object
arc.struct.ObjectMap<K,V>
arc.struct.OrderedMap<K,V>
- All Implemented Interfaces:
Iterable<ObjectMap.Entry<K,
V>>
An
ObjectMap
that also stores keys in an Seq
using the insertion order. Iteration over the
entries()
, keys()
, and values()
is ordered and faster than an unordered map. Keys can also be
accessed and the order changed using orderedKeys()
. There is some additional overhead for put and remove. When used
for faster iteration versus ObjectMap and the order does not actually matter, copying during remove can be greatly reduced by
setting Seq.ordered
to false for orderedKeys()
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
Nested classes/interfaces inherited from class arc.struct.ObjectMap
ObjectMap.Entries<K,
V>, ObjectMap.Entry<K, V>, ObjectMap.Keys<K>, ObjectMap.Values<V> -
Field Summary
-
Constructor Summary
ConstructorDescriptionOrderedMap
(int initialCapacity) OrderedMap
(int initialCapacity, float loadFactor) OrderedMap
(OrderedMap<? extends K, ? extends V> map) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the map, leaving the backing arrays at the current capacity.void
clear
(int maximumCapacity) Clears the map and reduces the size of the backing arrays to be the specified capacity, if they are larger.entries()
Returns an iterator for the entries in the map.iterator()
keys()
Returns an iterator for the keys in the map.static <K,
V> OrderedMap<K, V> Returns the old value associated with the specified key, or null.Returns the value associated with the key, or null.removeIndex
(int index) toString()
values()
Returns an iterator for the values in the map.Methods inherited from class arc.struct.ObjectMap
containsKey, containsValue, copy, each, ensureCapacity, equals, findKey, get, get, get, getNull, getThrow, hashCode, isEmpty, merge, putAll, putAll, shrink, toString, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
OrderedMap
public OrderedMap() -
OrderedMap
public OrderedMap(int initialCapacity) -
OrderedMap
public OrderedMap(int initialCapacity, float loadFactor) -
OrderedMap
-
-
Method Details
-
of
-
put
Description copied from class:ObjectMap
Returns the old value associated with the specified key, or null. -
remove
Description copied from class:ObjectMap
Returns the value associated with the key, or null. -
removeIndex
-
clear
public void clear(int maximumCapacity) Description copied from class:ObjectMap
Clears the map and reduces the size of the backing arrays to be the specified capacity, if they are larger. The reduction is done by allocating new arrays, though for large arrays this can be faster than clearing the existing array. -
clear
public void clear()Description copied from class:ObjectMap
Clears the map, leaving the backing arrays at the current capacity. When the capacity is high and the population is low, iteration can be unnecessarily slow.ObjectMap.clear(int)
can be used to reduce the capacity. -
orderedKeys
-
iterator
-
entries
Returns an iterator for the entries in the map. Remove is supported. Note that the same iterator instance is returned each time this method is called. Use theOrderedMap.OrderedMapEntries
constructor for nested or multithreaded iteration. -
values
Returns an iterator for the values in the map. Remove is supported. Note that the same iterator instance is returned each time this method is called. Use theOrderedMap.OrderedMapValues
constructor for nested or multithreaded iteration. -
keys
Returns an iterator for the keys in the map. Remove is supported. Note that the same iterator instance is returned each time this method is called. Use theOrderedMap.OrderedMapKeys
constructor for nested or multithreaded iteration. -
toString
-