Package gnu.trove

Class TIntHashSet

  • All Implemented Interfaces:
    TIntHashingStrategy, java.io.Externalizable, java.io.Serializable, java.lang.Cloneable

    public class TIntHashSet
    extends TIntHash
    implements java.io.Externalizable
    An open addressed set implementation for int primitives.
    Author:
    Eric D. Friedman, Rob Eden
    See Also:
    Serialized Form
    • 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 loadFactor)
        Creates a new TIntHashSet instance with a prime capacity equal to or greater than initialCapacity and with the specified load factor.
        Parameters:
        initialCapacity - an int value
        loadFactor - a float value
      • TIntHashSet

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

        public TIntHashSet​(TIntHashingStrategy strategy)
        Creates a new TIntHash instance with the default capacity and load factor.
        Parameters:
        strategy - used to compute hash codes and to compare keys.
      • TIntHashSet

        public TIntHashSet​(int initialCapacity,
                           TIntHashingStrategy strategy)
        Creates a new TIntHash instance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime.
        Parameters:
        initialCapacity - an int value
        strategy - used to compute hash codes and to compare keys.
      • TIntHashSet

        public TIntHashSet​(int initialCapacity,
                           float loadFactor,
                           TIntHashingStrategy strategy)
        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.
        loadFactor - used to calculate the threshold over which rehashing takes place.
        strategy - used to compute hash codes and to compare keys.
      • TIntHashSet

        public TIntHashSet​(int[] array,
                           TIntHashingStrategy strategy)
        Creates a new TIntHashSet instance containing the elements of array.
        Parameters:
        array - an array of int primitives
        strategy - used to compute hash codes and to compare keys.
    • Method Detail

      • iterator

        public TIntIterator iterator()
        Returns:
        a TIntIterator with access to the values in this set
      • add

        public boolean add​(int val)
        Inserts a value into the set.
        Parameters:
        val - an int value
        Returns:
        true if the set was modified by the add operation
      • rehash

        protected void rehash​(int newCapacity)
        Expands the set to accommodate new values.
        Specified by:
        rehash in class THash
        Parameters:
        newCapacity - an int value
      • toArray

        public int[] toArray()
        Returns a new array containing the values in the set.
        Returns:
        an int[] value
      • clear

        public void clear()
        Empties the set.
        Overrides:
        clear in class THash
      • equals

        public boolean equals​(java.lang.Object other)
        Compares this set with another set for equality of their stored entries.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        other - an Object value
        Returns:
        a boolean value
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • remove

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

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

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

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

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

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Overrides:
        writeExternal in class 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 THash
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException