GNU Trove

gnu.trove
Class THashSet

java.lang.Object
  |
  +--gnu.trove.THash
        |
        +--gnu.trove.TObjectHash
              |
              +--gnu.trove.THashSet
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.io.Serializable, java.util.Set, TObjectHashingStrategy

public class THashSet
extends TObjectHash
implements java.util.Set, java.io.Serializable

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.11 2003/03/23 04:06:59 ericdf Exp $
Author:
Eric D. Friedman
See Also:
Serialized Form

Field Summary
 
Fields inherited from class gnu.trove.TObjectHash
_hashingStrategy, _set, REMOVED
 
Fields inherited from class gnu.trove.THash
_free, _loadFactor, _maxSize, _size, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR
 
Constructor Summary
THashSet()
          Creates a new THashSet instance with the default capacity and load factor.
THashSet(java.util.Collection collection)
          Creates a new THashSet instance containing the elements of collection.
THashSet(java.util.Collection collection, TObjectHashingStrategy strategy)
          Creates a new THashSet instance containing the elements of collection.
THashSet(int initialCapacity)
          Creates a new THashSet instance with a prime capacity equal to or greater than initialCapacity and with the default load factor.
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.
THashSet(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy)
          Creates a new THashSet instance with a prime capacity equal to or greater than initialCapacity and with the specified load factor.
THashSet(int initialCapacity, TObjectHashingStrategy strategy)
          Creates a new THashSet instance with a prime capacity equal to or greater than initialCapacity and with the default load factor.
THashSet(TObjectHashingStrategy strategy)
          Creates a new THashSet instance with the default capacity and load factor.
 
Method Summary
 boolean add(java.lang.Object obj)
          Inserts a value into the set.
 boolean addAll(java.util.Collection collection)
          Adds all of the elements in collection to the set.
 void clear()
          Empties the set.
 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)
           
 int hashCode()
           
 java.util.Iterator iterator()
          Creates an iterator over the values of the set.
protected  void rehash(int newCapacity)
          Expands the set to accomodate new values.
 boolean remove(java.lang.Object obj)
          Removes obj from the set.
 boolean removeAll(java.util.Collection collection)
          Removes all of the elements in collection from the set.
 boolean retainAll(java.util.Collection collection)
          Removes any values in the set which are not contained in collection.
 java.lang.Object[] toArray()
          Returns a new array containing the objects in the set.
 java.lang.Object[] toArray(java.lang.Object[] a)
          Returns a typed array of the objects in the set.
 
Methods inherited from class gnu.trove.TObjectHash
capacity, clone, computeHashCode, contains, equals, forEach, index, insertionIndex, removeAt, setUp, throwObjectContractViolation
 
Methods inherited from class gnu.trove.THash
compact, ensureCapacity, isEmpty, postInsertHook, size, trimToSize
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Set
contains, isEmpty, size
 

Constructor Detail

THashSet

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


THashSet

public THashSet(TObjectHashingStrategy 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 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 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(java.util.Collection collection)
Creates a new THashSet instance containing the elements of collection.

Parameters:
collection - a Collection value

THashSet

public THashSet(java.util.Collection collection,
                TObjectHashingStrategy 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 Detail

add

public boolean add(java.lang.Object obj)
Inserts a value into the set.

Specified by:
add in interface java.util.Set
Parameters:
obj - an Object value
Returns:
true if the set was modified by the add operation

equals

public boolean equals(java.lang.Object other)
Specified by:
equals in interface java.util.Set
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Set
Overrides:
hashCode in class java.lang.Object

rehash

protected void rehash(int newCapacity)
Expands the set to accomodate new values.

Specified by:
rehash in class THash
Parameters:
newCapacity - an int value

toArray

public java.lang.Object[] toArray()
Returns a new array containing the objects in the set.

Specified by:
toArray in interface java.util.Set
Returns:
an Object[] value

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Returns a typed array of the objects in the set.

Specified by:
toArray in interface java.util.Set
Parameters:
a - an Object[] value
Returns:
an Object[] value

clear

public void clear()
Empties the set.

Specified by:
clear in interface java.util.Set
Overrides:
clear in class THash

remove

public boolean remove(java.lang.Object obj)
Removes obj from the set.

Specified by:
remove in interface java.util.Set
Parameters:
obj - an Object value
Returns:
true if the set was modified by the remove operation.

iterator

public java.util.Iterator iterator()
Creates an iterator over the values of the set. The iterator supports element deletion.

Specified by:
iterator in interface java.util.Set
Returns:
an Iterator value

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 java.util.Set
Parameters:
collection - a Collection value
Returns:
true if all elements were present in the set.

addAll

public boolean addAll(java.util.Collection collection)
Adds all of the elements in collection to the set.

Specified by:
addAll in interface java.util.Set
Parameters:
collection - a Collection value
Returns:
true if the set was modified by the add 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 java.util.Set
Parameters:
collection - a Collection value
Returns:
true if the set was modified by the remove 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 java.util.Set
Parameters:
collection - a Collection value
Returns:
true if the set was modified by the retain all operation

GNU Trove

GNU Trove is copyright 2001-2003 Eric D. Friedman. All Rights Reserved.