Package arc.struct
Class OrderedSet<T>
java.lang.Object
arc.struct.ObjectSet<T>
arc.struct.OrderedSet<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()
.-
Nested Class Summary
Nested classes/interfaces inherited from class arc.struct.ObjectSet
ObjectSet.ObjectSetIterator
-
Field Summary
-
Constructor Summary
ConstructorDescriptionOrderedSet
(int initialCapacity) OrderedSet
(int initialCapacity, float loadFactor) OrderedSet
(OrderedSet set) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns true if the key was not already in the set.boolean
void
clear()
Clears the set, leaving the backing arrays at the current capacity.void
clear
(int maximumCapacity) Clears the set and reduces the size of the backing arrays to be the specified capacity, if they are larger.first()
iterator()
Returns an iterator for the keys in the set.boolean
Returns true if the key was removed.removeIndex
(int index) toString()
Methods inherited from class arc.struct.ObjectSet
addAll, addAll, addAll, addAll, addAll, contains, each, ensureCapacity, equals, get, hashCode, isEmpty, removeAll, removeAll, removeAll, select, shrink, toSeq, with, with
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
-
OrderedSet
public OrderedSet() -
OrderedSet
public OrderedSet(int initialCapacity, float loadFactor) -
OrderedSet
public OrderedSet(int initialCapacity) -
OrderedSet
-
-
Method Details
-
first
-
add
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. -
add
-
remove
Description copied from class:ObjectSet
Returns true if the key was removed. -
removeIndex
-
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. -
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. -
orderedItems
-
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 theObjectSet<T>.ObjectSetIterator
constructor for nested or multithreaded iteration. -
toString
-
toString
-