Package arc.struct

Class OrderedSet<T>

java.lang.Object
arc.struct.ObjectSet<T>
arc.struct.OrderedSet<T>
All Implemented Interfaces:
Eachable<T>, Iterable<T>

public class OrderedSet<T> extends ObjectSet<T>
An ObjectSet that also stores keys in an Seq using the insertion order. Iteration is ordered and faster than an unordered set. Keys can also be accessed and the order changed using orderedItems(). There is some additional overhead for put and remove. When used for faster iteration versus ObjectSet and the order does not actually matter, copying during remove can be greatly reduced by setting Seq.ordered to false for orderedItems().
  • Constructor Details

    • OrderedSet

      public OrderedSet()
    • OrderedSet

      public OrderedSet(int initialCapacity, float loadFactor)
    • OrderedSet

      public OrderedSet(int initialCapacity)
    • OrderedSet

      public OrderedSet(OrderedSet set)
  • Method Details

    • first

      public T first()
      Overrides:
      first in class ObjectSet<T>
    • add

      public boolean add(T key)
      Description copied from class: ObjectSet
      Returns true if the key was not already in the set. If this set already contains the key, the call leaves the set unchanged and returns false.
      Overrides:
      add in class ObjectSet<T>
    • add

      public boolean add(T key, int index)
    • remove

      public boolean remove(T key)
      Description copied from class: ObjectSet
      Returns true if the key was removed.
      Overrides:
      remove in class ObjectSet<T>
    • removeIndex

      public T removeIndex(int index)
    • clear

      public void clear(int maximumCapacity)
      Description copied from class: ObjectSet
      Clears the set 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 ObjectSet<T>
    • clear

      public void clear()
      Description copied from class: ObjectSet
      Clears the set, leaving the backing arrays at the current capacity. When the capacity is high and the population is low, iteration can be unnecessarily slow. ObjectSet.clear(int) can be used to reduce the capacity.
      Overrides:
      clear in class ObjectSet<T>
    • orderedItems

      public Seq<T> orderedItems()
    • iterator

      public OrderedSet<T>.OrderedSetIterator iterator()
      Description copied from class: ObjectSet
      Returns an iterator for the keys in the set. Remove is supported. Note that the same iterator instance is returned each time this method is called. Use the ObjectSet<T>.ObjectSetIterator constructor for nested or multithreaded iteration.
      Specified by:
      iterator in interface Iterable<T>
      Overrides:
      iterator in class ObjectSet<T>
    • toString

      public String toString()
      Overrides:
      toString in class ObjectSet<T>
    • toString

      public String toString(String separator)
      Overrides:
      toString in class ObjectSet<T>