gnu.trove

Class TIntHash

public abstract class TIntHash extends TPrimitiveHash implements Serializable, TIntHashingStrategy

An open addressed hashing implementation for int primitives. Created: Sun Nov 4 08:56:06 2001

Version: $Id: TIntHash.java,v 1.13 2003/03/19 04:17:04 ericdf Exp $

Author: Eric D. Friedman

Field Summary
protected TIntHashingStrategy_hashingStrategy
strategy used to hash values in this collection
protected int[]_set
the set of ints
Constructor Summary
TIntHash()
Creates a new TIntHash instance with the default capacity and load factor.
TIntHash(int initialCapacity)
Creates a new TIntHash instance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime.
TIntHash(int initialCapacity, float loadFactor)
Creates a new TIntHash instance with a prime value at or near the specified capacity and load factor.
TIntHash(TIntHashingStrategy strategy)
Creates a new TIntHash instance with the default capacity and load factor.
TIntHash(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.
TIntHash(int initialCapacity, float loadFactor, TIntHashingStrategy strategy)
Creates a new TIntHash instance with a prime value at or near the specified capacity and load factor.
Method Summary
Objectclone()
intcomputeHashCode(int val)
Default implementation of TIntHashingStrategy: delegates hashing to HashFunctions.hash(int).
booleancontains(int val)
Searches the set for val
booleanforEach(TIntProcedure procedure)
Executes procedure for each element in the set.
protected intindex(int val)
Locates the index of val.
protected intinsertionIndex(int val)
Locates the index at which val can be inserted. if there is already a value equal()ing val in the set, returns that value as a negative integer.
protected voidremoveAt(int index)
Releases the element currently stored at index.
protected intsetUp(int initialCapacity)
initializes the hashtable to a prime capacity which is at least initialCapacity + 1.

Field Detail

_hashingStrategy

protected TIntHashingStrategy _hashingStrategy
strategy used to hash values in this collection

_set

protected transient int[] _set
the set of ints

Constructor Detail

TIntHash

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

TIntHash

public TIntHash(int initialCapacity)
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

TIntHash

public TIntHash(int initialCapacity, float loadFactor)
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.

TIntHash

public TIntHash(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.

TIntHash

public TIntHash(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.

TIntHash

public TIntHash(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.

Method Detail

clone

public Object clone()

Returns: a deep clone of this collection

computeHashCode

public final int computeHashCode(int val)
Default implementation of TIntHashingStrategy: delegates hashing to HashFunctions.hash(int).

Parameters: the value to hash

Returns: the hashcode.

contains

public boolean contains(int val)
Searches the set for val

Parameters: val an int value

Returns: a boolean value

forEach

public boolean forEach(TIntProcedure procedure)
Executes procedure for each element in the set.

Parameters: procedure a TObjectProcedure value

Returns: false if the loop over the set terminated because the procedure returned false for some value.

index

protected int index(int val)
Locates the index of val.

Parameters: val an int value

Returns: the index of val or -1 if it isn't in the set.

insertionIndex

protected int insertionIndex(int val)
Locates the index at which val can be inserted. if there is already a value equal()ing val in the set, returns that value as a negative integer.

Parameters: val an int value

Returns: an int value

removeAt

protected void removeAt(int index)
Releases the element currently stored at index.

Parameters: index an int value

setUp

protected int setUp(int initialCapacity)
initializes the hashtable to a prime capacity which is at least initialCapacity + 1.

Parameters: initialCapacity an int value

Returns: the actual capacity chosen