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

public class OrderedMap<K,V> extends ObjectMap<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().
  • Constructor Details

    • OrderedMap

      public OrderedMap()
    • OrderedMap

      public OrderedMap(int initialCapacity)
    • OrderedMap

      public OrderedMap(int initialCapacity, float loadFactor)
    • OrderedMap

      public OrderedMap(OrderedMap<? extends K,? extends V> map)
  • Method Details

    • of

      public static <K, V> OrderedMap<K,V> of(Object... values)
    • put

      public V put(K key, V value)
      Description copied from class: ObjectMap
      Returns the old value associated with the specified key, or null.
      Overrides:
      put in class ObjectMap<K,V>
    • remove

      public V remove(K key)
      Description copied from class: ObjectMap
      Returns the value associated with the key, or null.
      Overrides:
      remove in class ObjectMap<K,V>
    • removeIndex

      public V removeIndex(int index)
    • 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.
      Overrides:
      clear in class ObjectMap<K,V>
    • 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.
      Overrides:
      clear in class ObjectMap<K,V>
    • orderedKeys

      public Seq<K> orderedKeys()
    • iterator

      public ObjectMap.Entries<K,V> iterator()
      Specified by:
      iterator in interface Iterable<K>
      Overrides:
      iterator in class ObjectMap<K,V>
    • entries

      public ObjectMap.Entries<K,V> 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 the OrderedMap.OrderedMapEntries constructor for nested or multithreaded iteration.
      Overrides:
      entries in class ObjectMap<K,V>
    • values

      public ObjectMap.Values<V> 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 the OrderedMap.OrderedMapValues constructor for nested or multithreaded iteration.
      Overrides:
      values in class ObjectMap<K,V>
    • keys

      public ObjectMap.Keys<K> 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 the OrderedMap.OrderedMapKeys constructor for nested or multithreaded iteration.
      Overrides:
      keys in class ObjectMap<K,V>
    • toString

      public String toString()
      Overrides:
      toString in class ObjectMap<K,V>