gnu.trove

Class THashSet<E>

Implemented Interfaces:
Externalizable, Iterable, Set

public class THashSet<E>
extends TObjectHash
implements Set, Iterable, 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.20 2008/05/07 19:26:30 robeden Exp $
Author:
Eric D. Friedman

Constructor Summary

THashSet()
Creates a new THashSet instance with the default capacity and load factor.
THashSet(E> collection)
Creates a new THashSet instance containing the elements of collection.
THashSet(E> collection, TObjectHashingStrategy strategy)
Creates a new THashSet instance containing the elements of collection.
THashSet(TObjectHashingStrategy strategy)
Creates a new THashSet instance with the default capacity and load factor.
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, TObjectHashingStrategy strategy)
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.

Method Summary

T[] toArray(T[] a)
Returns a typed array of the objects in the set.
boolean
add(E obj)
Inserts a value into the set.
boolean
addAll(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
equals(Object other)
int
hashCode()
Iterator
iterator()
Creates an iterator over the values of the set.
void
readExternal(ObjectInput in)
protected void
rehash(int newCapacity)
Expands the set to accommodate new values.
boolean
remove(Object obj)
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.
String
toString()
void
writeExternal(ObjectOutput out)

Constructor Details

THashSet

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

THashSet

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

THashSet

public THashSet(E> 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.

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.

Method Details

T[] toArray

public  T[] toArray(T[] a)
Returns a typed array of the objects in the set.
Parameters:
a - an Object[] value
Returns:
an Object[] value

add

public boolean add(E obj)
Inserts a value into the set.
Parameters:
obj - an Object value
Returns:
true if the set was modified by the add operation

addAll

public boolean addAll(E> collection)
Adds all of the elements in collection to the set.
Parameters:
collection - a Collection value
Returns:
true if the set was modified by the add all operation.

clear

public void clear()
Empties the set.

containsAll

public boolean containsAll(Collection collection)
Tests the set to determine if all of the elements in collection are present.
Parameters:
collection - a Collection value
Returns:
true if all elements were present in the set.

equals

public boolean equals(Object other)

hashCode

public int hashCode()

iterator

public Iterator iterator()
Creates an iterator over the values of the set. The iterator supports element deletion.
Returns:
an Iterator value

readExternal

public void readExternal(ObjectInput in)
            throws IOException,
                   ClassNotFoundException

rehash

protected void rehash(int newCapacity)
Expands the set to accommodate new values.
Parameters:
newCapacity - an int value

remove

public boolean remove(Object obj)
Removes obj from the set.
Parameters:
obj - an Object value
Returns:
true if the set was modified by the remove operation.

removeAll

public boolean removeAll(Collection collection)
Removes all of the elements in collection from the set.
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.
Parameters:
collection - a Collection value
Returns:
true if the set was modified by the retain all operation

toArray

public Object[] toArray()
Returns a new array containing the objects in the set.
Returns:
an Object[] value

toString

public String toString()

writeExternal

public void writeExternal(ObjectOutput out)
            throws IOException

GNU Trove is copyright B) 2001-2008 Eric D. Friedman. All Rights Reserved.