Package gnu.trove

Class THashSet<E>

All Implemented Interfaces:
TObjectHashingStrategy<E>, Externalizable, Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>

public class THashSet<E> extends TObjectHash<E> implements Set<E>, Iterable<E>, Externalizable
An implementation of the Set interface that uses an open-addressed hash table to store its contents. Created: Sat Nov 3 10:38:17 2001
Version:
$Id: THashSet.java,v 1.21 2008/10/07 20:33:56 robeden Exp $
Author:
Eric D. Friedman
See Also:
  • Constructor Details

    • THashSet

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

      public THashSet(TObjectHashingStrategy<E> strategy)
      Creates a new THashSet instance with the default capacity and load factor.
      Parameters:
      strategy - used to compute hash codes and to compare objects.
    • THashSet

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

      public THashSet(int initialCapacity, TObjectHashingStrategy<E> strategy)
      Creates a new THashSet instance with a prime capacity equal to or greater than initialCapacity and with the default load factor.
      Parameters:
      initialCapacity - an int value
      strategy - used to compute hash codes and to compare objects.
    • THashSet

      public THashSet(int initialCapacity, float loadFactor)
      Creates a new THashSet 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
    • THashSet

      public THashSet(int initialCapacity, float loadFactor, TObjectHashingStrategy<E> strategy)
      Creates a new THashSet 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
      strategy - used to compute hash codes and to compare objects.
    • THashSet

      public THashSet(Collection<? extends E> collection)
      Creates a new THashSet instance containing the elements of collection.
      Parameters:
      collection - a Collection value
    • THashSet

      public THashSet(Collection<? extends E> collection, TObjectHashingStrategy<E> strategy)
      Creates a new THashSet instance containing the elements of collection.
      Parameters:
      collection - a Collection value
      strategy - used to compute hash codes and to compare objects.
  • Method Details

    • add

      public boolean add(E obj)
      Inserts a value into the set.
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface Set<E>
      Parameters:
      obj - an Object value
      Returns:
      true if the set was modified by the add operation
    • equals

      public boolean equals(Object other)
      Specified by:
      equals in interface Collection<E>
      Specified by:
      equals in interface Set<E>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<E>
      Specified by:
      hashCode in interface Set<E>
      Overrides:
      hashCode in class Object
    • 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 Object[] toArray()
      Returns a new array containing the objects in the set.
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface Set<E>
      Returns:
      an Object[] value
    • toArray

      public <T> T[] toArray(T[] a)
      Returns a typed array of the objects in the set.
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface Set<E>
      Parameters:
      a - an Object[] value
      Returns:
      an Object[] value
    • clear

      public void clear()
      Empties the set.
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface Set<E>
      Overrides:
      clear in class THash
    • remove

      public boolean remove(Object obj)
      Removes obj from the set.
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface Set<E>
      Parameters:
      obj - an Object value
      Returns:
      true if the set was modified by the remove operation.
    • iterator

      public Iterator<E> iterator()
      Creates an iterator over the values of the set. The iterator supports element deletion.
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface Set<E>
      Returns:
      an Iterator value
    • containsAll

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

      public boolean addAll(Collection<? extends E> collection)
      Adds all of the elements in collection to the set.
      Specified by:
      addAll in interface Collection<E>
      Specified by:
      addAll in interface Set<E>
      Parameters:
      collection - a Collection value
      Returns:
      true if the set was modified by the add all operation.
    • removeAll

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

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

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

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Overrides:
      writeExternal in class TObjectHash<E>
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Overrides:
      readExternal in class TObjectHash<E>
      Throws:
      IOException
      ClassNotFoundException