Package gnu.trove.set.hash
Class THashSet<E>
java.lang.Object
gnu.trove.impl.hash.THash
gnu.trove.impl.hash.TObjectHash<E>
gnu.trove.set.hash.THashSet<E>
- All Implemented Interfaces:
Externalizable
,Serializable
,Iterable<E>
,Collection<E>
,Set<E>
An implementation of the Set interface that uses an
open-addressed hash table to store its contents.
- See Also:
-
Field Summary
Fields inherited from class gnu.trove.impl.hash.TObjectHash
_set, consumeFreeSlot, FREE, REMOVED
Fields inherited from class gnu.trove.impl.hash.THash
_autoCompactionFactor, _autoCompactRemovesRemaining, _autoCompactTemporaryDisable, _free, _loadFactor, _maxSize, _size, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR
-
Constructor Summary
ConstructorsConstructorDescriptionTHashSet()
Creates a newTHashSet
instance with the default capacity and load factor.THashSet
(int initialCapacity) Creates a newTHashSet
instance with a prime capacity equal to or greater than initialCapacity and with the default load factor.THashSet
(int initialCapacity, float loadFactor) Creates a newTHashSet
instance with a prime capacity equal to or greater than initialCapacity and with the specified load factor.THashSet
(Collection<? extends E> collection) Creates a newTHashSet
instance containing the elements of collection. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Inserts a value into the set.boolean
addAll
(Collection<? extends E> collection) Adds all of the elements in collection to the set.void
clear()
Empties the set.boolean
containsAll
(Collection<?> collection) Tests the set to determine if all of the elements in collection are present.boolean
int
hashCode()
iterator()
Creates an iterator over the values of the set.void
protected void
rehash
(int newCapacity) Expands the set to accommodate new values.boolean
Removes obj from the set.boolean
removeAll
(Collection<?> collection) Removes all of the elements in collection from the set.boolean
retainAll
(Collection<?> collection) Removes any values in the set which are not contained in collection.Object[]
toArray()
Returns a new array containing the objects in the set.<T> T[]
toArray
(T[] a) Returns a typed array of the objects in the set.toString()
protected void
writeEntries
(ObjectOutput out) void
Methods inherited from class gnu.trove.impl.hash.TObjectHash
buildObjectContractViolation, capacity, contains, dumpExtraInfo, equals, forEach, hash, index, insertionIndex, insertKey, objectInfo, removeAt, reportPotentialConcurrentMod, setUp, throwObjectContractViolation, throwObjectContractViolation
Methods inherited from class gnu.trove.impl.hash.THash
calculateGrownCapacity, compact, computeMaxSize, computeNextAutoCompactionAmount, ensureCapacity, fastCeil, getAutoCompactionFactor, isEmpty, postInsertHook, reenableAutoCompaction, saturatedCast, setAutoCompactionFactor, size, tempDisableAutoCompaction, trimToSize
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.Set
contains, isEmpty, size, spliterator
-
Constructor Details
-
THashSet
public THashSet()Creates a newTHashSet
instance with the default capacity and load factor. -
THashSet
public THashSet(int initialCapacity) Creates a newTHashSet
instance with a prime capacity equal to or greater than initialCapacity and with the default load factor.- Parameters:
initialCapacity
- anint
value
-
THashSet
public THashSet(int initialCapacity, float loadFactor) Creates a newTHashSet
instance with a prime capacity equal to or greater than initialCapacity and with the specified load factor.- Parameters:
initialCapacity
- anint
valueloadFactor
- afloat
value
-
THashSet
Creates a newTHashSet
instance containing the elements of collection.- Parameters:
collection
- aCollection
value
-
-
Method Details
-
add
Inserts a value into the set. -
equals
-
hashCode
public int hashCode() -
rehash
protected void rehash(int newCapacity) Expands the set to accommodate new values. -
toArray
Returns a new array containing the objects in the set. -
toArray
public <T> T[] toArray(T[] a) Returns a typed array of the objects in the set. -
clear
public void clear()Empties the set. -
remove
Removes obj from the set. -
iterator
Creates an iterator over the values of the set. The iterator supports element deletion. -
containsAll
Tests the set to determine if all of the elements in collection are present.- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
- Parameters:
collection
- aCollection
value- Returns:
- true if all elements were present in the set.
-
addAll
Adds all of the elements in collection to the set. -
removeAll
Removes all of the elements in collection from the set. -
retainAll
Removes any values in the set which are not contained in collection. -
toString
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Overrides:
writeExternal
in classTObjectHash<E>
- Throws:
IOException
-
writeEntries
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Overrides:
readExternal
in classTObjectHash<E>
- Throws:
IOException
ClassNotFoundException
-