Package arc.struct
Class IntSet
java.lang.Object
arc.struct.IntSet
An unordered set that uses int keys. This implementation uses cuckoo hashing using 3 hashes, random walking, and a small stash
for problematic keys. No allocation is done except when growing the table size.
This set performs very fast contains and remove (typically O(1), worst case O(log(n))). Add may be a bit slower, depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the set will have to rehash to the next higher POT size.
This set performs very fast contains and remove (typically O(1), worst case O(log(n))). Add may be a bit slower, depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the set will have to rehash to the next higher POT size.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionIntSet()Creates a new set with an initial capacity of 51 and a load factor of 0.8.IntSet(int initialCapacity) Creates a new set with a load factor of 0.8.IntSet(int initialCapacity, float loadFactor) Creates a new set with the specified initial capacity and load factor.Creates a new set identical to the specified set. -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(int key) Returns true if the key was not already in the set.voidaddAll(int... array) voidaddAll(int[] array, int offset, int length) voidvoidvoidvoidclear()voidclear(int maximumCapacity) Clears the set and reduces the size of the backing arrays to be the specified capacity if they are larger.booleancontains(int key) voidvoidensureCapacity(int additionalCapacity) Increases the size of the backing array to accommodate the specified number of additional items.booleanintfirst()inthashCode()booleanisEmpty()Returns true if the set is empty.iterator()Returns an iterator for the keys in the set.booleanremove(int key) Returns true if the key was removed.voidshrink(int maximumCapacity) Reduces the size of the backing arrays to be the specified capacity or less.toString()static IntSetwith(int... array) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
size
public int size
-
-
Constructor Details
-
IntSet
public IntSet()Creates a new set with an initial capacity of 51 and a load factor of 0.8. -
IntSet
public IntSet(int initialCapacity) Creates a new set with a load factor of 0.8.- Parameters:
initialCapacity- If not a power of two, it is increased to the next nearest power of two.
-
IntSet
public IntSet(int initialCapacity, float loadFactor) Creates a new set with the specified initial capacity and load factor. This set will hold initialCapacity items before growing the backing table.- Parameters:
initialCapacity- If not a power of two, it is increased to the next nearest power of two.
-
IntSet
Creates a new set identical to the specified set.
-
-
Method Details
-
with
-
each
-
add
public boolean add(int key) Returns true if the key was not already in the set. -
addAll
-
addAll
-
addAll
public void addAll(int... array) -
addAll
public void addAll(int[] array, int offset, int length) -
addAll
-
remove
public boolean remove(int key) Returns true if the key was removed. -
isEmpty
public boolean isEmpty()Returns true if the set is empty. -
shrink
public void shrink(int maximumCapacity) Reduces the size of the backing arrays to be the specified capacity or less. If the capacity is already less, nothing is done. If the set contains more items than the specified capacity, the next highest power of two capacity is used instead. -
clear
public void clear(int maximumCapacity) Clears the set and reduces the size of the backing arrays to be the specified capacity if they are larger. -
clear
public void clear() -
contains
public boolean contains(int key) -
first
public int first() -
ensureCapacity
public void ensureCapacity(int additionalCapacity) Increases the size of the backing array to accommodate the specified number of additional items. Useful before adding many items to avoid multiple backing array resizes. -
hashCode
public int hashCode() -
equals
-
toString
-
iterator
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 theIntSet.IntSetIteratorconstructor for nested or multithreaded iteration.
-