Class TIntHashSet

  • All Implemented Interfaces:
    TIntSet, TIntCollection, java.io.Externalizable, java.io.Serializable

    public class TIntHashSet
    extends gnu.trove.impl.hash.TIntHash
    implements TIntSet, java.io.Externalizable
    An open addressed set implementation for int primitives.
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class gnu.trove.impl.hash.TIntHash

        _set, consumeFreeSlot, no_entry_value
      • Fields inherited from class gnu.trove.impl.hash.TPrimitiveHash

        _states, FREE, FULL, REMOVED
      • Fields inherited from class gnu.trove.impl.hash.THash

        _autoCompactionFactor, _autoCompactRemovesRemaining, _autoCompactTemporaryDisable, _free, _loadFactor, _maxSize, _size, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR
    • Constructor Summary

      Constructors 
      Constructor Description
      TIntHashSet()
      Creates a new TIntHashSet instance with the default capacity and load factor.
      TIntHashSet​(int initialCapacity)
      Creates a new TIntHashSet instance with a prime capacity equal to or greater than initialCapacity and with the default load factor.
      TIntHashSet​(int[] array)
      Creates a new TIntHashSet instance containing the elements of array.
      TIntHashSet​(int initialCapacity, float load_factor)
      Creates a new TIntHash instance with a prime value at or near the specified capacity and load factor.
      TIntHashSet​(int initial_capacity, float load_factor, int no_entry_value)
      Creates a new TIntHashSet instance with a prime capacity equal to or greater than initial_capacity and with the specified load factor.
      TIntHashSet​(TIntCollection collection)
      Creates a new TIntHashSet instance that is a copy of the existing set.
      TIntHashSet​(java.util.Collection<? extends java.lang.Integer> collection)
      Creates a new TIntHashSet instance that is a copy of the existing Collection.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(int val)
      Inserts a value into the set.
      boolean addAll​(int[] array)
      Adds all of the elements in the array to the set.
      boolean addAll​(TIntCollection collection)
      Adds all of the elements in the TIntCollection to the set.
      boolean addAll​(java.util.Collection<? extends java.lang.Integer> collection)
      Adds all of the elements in collection to the set.
      void clear()
      Empties the collection.
      boolean containsAll​(int[] array)
      Tests the set to determine if all of the elements in array are present.
      boolean containsAll​(TIntCollection collection)
      Tests the set to determine if all of the elements in TIntCollection are present.
      boolean containsAll​(java.util.Collection<?> collection)
      Tests the set to determine if all of the elements in collection are present.
      boolean equals​(java.lang.Object other)
      Compares the specified object with this set for equality.
      int hashCode()
      Returns the hash code value for this set.
      TIntIterator iterator()
      Creates an iterator over the values of the set.
      void readExternal​(java.io.ObjectInput in)
      protected void rehash​(int newCapacity)
      Rehashes the set.
      boolean remove​(int val)
      Removes entry from the set.
      boolean removeAll​(int[] array)
      Removes all of the elements in array from the set.
      boolean removeAll​(TIntCollection collection)
      Removes all of the elements in TIntCollection from the set.
      boolean removeAll​(java.util.Collection<?> collection)
      Removes all of the elements in collection from the set.
      boolean retainAll​(int[] array)
      Removes any values in the set which are not contained in array.
      boolean retainAll​(TIntCollection collection)
      Removes any values in the set which are not contained in TIntCollection.
      boolean retainAll​(java.util.Collection<?> collection)
      Removes any values in the set which are not contained in collection.
      int[] toArray()
      Returns an array containing all of the elements in this set.
      int[] toArray​(int[] dest)
      Returns an array containing elements in this set.
      java.lang.String toString()
      void writeExternal​(java.io.ObjectOutput out)
      • Methods inherited from class gnu.trove.impl.hash.TIntHash

        contains, forEach, getNoEntryValue, index, insertKey, removeAt, setUp
      • Methods inherited from class gnu.trove.impl.hash.TPrimitiveHash

        capacity
      • Methods inherited from class gnu.trove.impl.hash.THash

        calculateGrownCapacity, compact, computeMaxSize, computeNextAutoCompactionAmount, ensureCapacity, getAutoCompactionFactor, isEmpty, postInsertHook, reenableAutoCompaction, setAutoCompactionFactor, size, tempDisableAutoCompaction, trimToSize
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TIntHashSet

        public TIntHashSet()
        Creates a new TIntHashSet instance with the default capacity and load factor.
      • TIntHashSet

        public TIntHashSet​(int initialCapacity)
        Creates a new TIntHashSet instance with a prime capacity equal to or greater than initialCapacity and with the default load factor.
        Parameters:
        initialCapacity - an int value
      • TIntHashSet

        public TIntHashSet​(int initialCapacity,
                           float load_factor)
        Creates a new TIntHash instance with a prime value at or near the specified capacity and load factor.
        Parameters:
        initialCapacity - used to find a prime capacity for the table.
        load_factor - used to calculate the threshold over which rehashing takes place.
      • TIntHashSet

        public TIntHashSet​(int initial_capacity,
                           float load_factor,
                           int no_entry_value)
        Creates a new TIntHashSet instance with a prime capacity equal to or greater than initial_capacity and with the specified load factor.
        Parameters:
        initial_capacity - an int value
        load_factor - a float value
        no_entry_value - a int value that represents null.
      • TIntHashSet

        public TIntHashSet​(java.util.Collection<? extends java.lang.Integer> collection)
        Creates a new TIntHashSet instance that is a copy of the existing Collection.
        Parameters:
        collection - a Collection that will be duplicated.
      • TIntHashSet

        public TIntHashSet​(TIntCollection collection)
        Creates a new TIntHashSet instance that is a copy of the existing set.
        Parameters:
        collection - a TIntSet that will be duplicated.
      • TIntHashSet

        public TIntHashSet​(int[] array)
        Creates a new TIntHashSet instance containing the elements of array.
        Parameters:
        array - an array of int primitives
    • Method Detail

      • iterator

        public TIntIterator iterator()
        Creates an iterator over the values of the set. The iterator supports element deletion.
        Specified by:
        iterator in interface TIntCollection
        Specified by:
        iterator in interface TIntSet
        Returns:
        an TIntIterator value
      • toArray

        public int[] toArray()
        Returns an array containing all of the elements in this set. If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

        The returned array will be "safe" in that no references to it are maintained by this set. (In other words, this method must allocate a new array even if this set is backed by an array). The caller is thus free to modify the returned array.

        This method acts as bridge between array-based and collection-based APIs.

        Specified by:
        toArray in interface TIntCollection
        Specified by:
        toArray in interface TIntSet
        Returns:
        an array containing all the elements in this set
      • toArray

        public int[] toArray​(int[] dest)
        Returns an array containing elements in this set.

        If this set fits in the specified array with room to spare (i.e., the array has more elements than this set), the element in the array immediately following the end of the set is set to TIntSet.getNoEntryValue(). (This is useful in determining the length of this set only if the caller knows that this set does not contain any elements representing null.)

        If the native array is smaller than the set size, the array will be filled with elements in Iterator order until it is full and exclude the remainder.

        If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

        Specified by:
        toArray in interface TIntCollection
        Specified by:
        toArray in interface TIntSet
        Parameters:
        dest - the array into which the elements of this set are to be stored.
        Returns:
        an int[] containing all the elements in this set
      • add

        public boolean add​(int val)
        Inserts a value into the set.
        Specified by:
        add in interface TIntCollection
        Specified by:
        add in interface TIntSet
        Parameters:
        val - a int value
        Returns:
        true if the set was modified by the add operation
      • remove

        public boolean remove​(int val)
        Removes entry from the set.
        Specified by:
        remove in interface TIntCollection
        Specified by:
        remove in interface TIntSet
        Parameters:
        val - an int value
        Returns:
        true if the set was modified by the remove operation.
      • containsAll

        public boolean containsAll​(java.util.Collection<?> collection)
        Tests the set to determine if all of the elements in collection are present.
        Specified by:
        containsAll in interface TIntCollection
        Specified by:
        containsAll in interface TIntSet
        Parameters:
        collection - a Collection value
        Returns:
        true if all elements were present in the set.
      • containsAll

        public boolean containsAll​(TIntCollection collection)
        Tests the set to determine if all of the elements in TIntCollection are present.
        Specified by:
        containsAll in interface TIntCollection
        Specified by:
        containsAll in interface TIntSet
        Parameters:
        collection - a TIntCollection value
        Returns:
        true if all elements were present in the set.
      • containsAll

        public boolean containsAll​(int[] array)
        Tests the set to determine if all of the elements in array are present.
        Specified by:
        containsAll in interface TIntCollection
        Specified by:
        containsAll in interface TIntSet
        Parameters:
        array - as array of int primitives.
        Returns:
        true if all elements were present in the set.
      • addAll

        public boolean addAll​(java.util.Collection<? extends java.lang.Integer> collection)
        Adds all of the elements in collection to the set.
        Specified by:
        addAll in interface TIntCollection
        Specified by:
        addAll in interface TIntSet
        Parameters:
        collection - a Collection value
        Returns:
        true if the set was modified by the add all operation.
      • addAll

        public boolean addAll​(TIntCollection collection)
        Adds all of the elements in the TIntCollection to the set.
        Specified by:
        addAll in interface TIntCollection
        Specified by:
        addAll in interface TIntSet
        Parameters:
        collection - a TIntCollection value
        Returns:
        true if the set was modified by the add all operation.
      • addAll

        public boolean addAll​(int[] array)
        Adds all of the elements in the array to the set.
        Specified by:
        addAll in interface TIntCollection
        Specified by:
        addAll in interface TIntSet
        Parameters:
        array - a array of int primitives.
        Returns:
        true if the set was modified by the add all operation.
      • retainAll

        public boolean retainAll​(java.util.Collection<?> collection)
        Removes any values in the set which are not contained in collection.
        Specified by:
        retainAll in interface TIntCollection
        Specified by:
        retainAll in interface TIntSet
        Parameters:
        collection - a Collection value
        Returns:
        true if the set was modified by the retain all operation
      • retainAll

        public boolean retainAll​(TIntCollection collection)
        Removes any values in the set which are not contained in TIntCollection.
        Specified by:
        retainAll in interface TIntCollection
        Specified by:
        retainAll in interface TIntSet
        Parameters:
        collection - a TIntCollection value
        Returns:
        true if the set was modified by the retain all operation
      • retainAll

        public boolean retainAll​(int[] array)
        Removes any values in the set which are not contained in array.
        Specified by:
        retainAll in interface TIntCollection
        Specified by:
        retainAll in interface TIntSet
        Parameters:
        array - an array of int primitives.
        Returns:
        true if the set was modified by the retain all operation
      • removeAll

        public boolean removeAll​(java.util.Collection<?> collection)
        Removes all of the elements in collection from the set.
        Specified by:
        removeAll in interface TIntCollection
        Specified by:
        removeAll in interface TIntSet
        Parameters:
        collection - a Collection value
        Returns:
        true if the set was modified by the remove all operation.
      • removeAll

        public boolean removeAll​(TIntCollection collection)
        Removes all of the elements in TIntCollection from the set.
        Specified by:
        removeAll in interface TIntCollection
        Specified by:
        removeAll in interface TIntSet
        Parameters:
        collection - a TIntCollection value
        Returns:
        true if the set was modified by the remove all operation.
      • removeAll

        public boolean removeAll​(int[] array)
        Removes all of the elements in array from the set.
        Specified by:
        removeAll in interface TIntCollection
        Specified by:
        removeAll in interface TIntSet
        Parameters:
        array - an array of int primitives.
        Returns:
        true if the set was modified by the remove all operation.
      • clear

        public void clear()
        Empties the collection.
        Specified by:
        clear in interface TIntCollection
        Specified by:
        clear in interface TIntSet
        Overrides:
        clear in class gnu.trove.impl.hash.THash
      • rehash

        protected void rehash​(int newCapacity)
        Rehashes the set.
        Specified by:
        rehash in class gnu.trove.impl.hash.THash
        Parameters:
        newCapacity - an int value
      • equals

        public boolean equals​(java.lang.Object other)
        Compares the specified object with this set for equality. Returns true if the specified object is also a set, the two sets have the same size, and every member of the specified set is contained in this set (or equivalently, every member of this set is contained in the specified set). This definition ensures that the equals method works properly across different implementations of the set interface.
        Specified by:
        equals in interface TIntCollection
        Specified by:
        equals in interface TIntSet
        Overrides:
        equals in class java.lang.Object
        Parameters:
        other - object to be compared for equality with this set
        Returns:
        true if the specified object is equal to this set
      • hashCode

        public int hashCode()
        Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set. This ensures that s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for any two sets s1 and s2, as required by the general contract of Object.hashCode().
        Specified by:
        hashCode in interface TIntCollection
        Specified by:
        hashCode in interface TIntSet
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code value for this set
        See Also:
        Object.equals(Object), Set.equals(Object)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Overrides:
        writeExternal in class gnu.trove.impl.hash.THash
        Throws:
        java.io.IOException
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Specified by:
        readExternal in interface java.io.Externalizable
        Overrides:
        readExternal in class gnu.trove.impl.hash.THash
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException