gnu.trove
Class TObjectHash<T>
- TObjectHashingStrategy
public abstract class TObjectHash<T>
extends THash
implements TObjectHashingStrategy
An open addressed hashing implementation for Object types.
Created: Sun Nov 4 08:56:06 2001
$Id: TObjectHash.java,v 1.25 2007/03/30 20:53:22 robeden Exp $protected static Object | FREE
|
protected static Object | REMOVED
|
protected TObjectHashingStrategy | _hashingStrategy - the strategy used to hash objects in this collection.
|
protected Object[] | _set - the set of Objects
|
TObjectHash() - Creates a new
TObjectHash instance with the
default capacity and load factor.
|
TObjectHash(TObjectHashingStrategy strategy) - Creates a new
TObjectHash instance with the
default capacity and load factor and a custom hashing strategy.
|
TObjectHash(int initialCapacity) - Creates a new
TObjectHash instance whose capacity
is the next highest prime above initialCapacity + 1
unless that value is already prime.
|
TObjectHash(int initialCapacity, TObjectHashingStrategy strategy) - Creates a new
TObjectHash instance whose capacity
is the next highest prime above initialCapacity + 1
unless that value is already prime.
|
TObjectHash(int initialCapacity, float loadFactor) - Creates a new
TObjectHash instance with a prime
value at or near the specified capacity and load factor.
|
TObjectHash(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) - Creates a new
TObjectHash instance with a prime
value at or near the specified capacity and load factor.
|
protected int | capacity()
|
TObjectHash | clone()
|
int | computeHashCode(T o) - This is the default implementation of TObjectHashingStrategy:
it delegates hashing to the Object's hashCode method.
|
boolean | contains(Object obj) - Searches the set for obj
|
boolean | equals(T o1, T o2) - This is the default implementation of TObjectHashingStrategy:
it delegates equality comparisons to the first parameter's
equals() method.
|
boolean | forEach(TObjectProcedure procedure) - Executes procedure for each element in the set.
|
protected int | index(T obj) - Locates the index of obj.
|
protected int | insertionIndex(T obj) - Locates the index at which obj can be inserted.
|
protected void | removeAt(int index)
|
protected int | setUp(int initialCapacity) - initializes the Object set of this hash table.
|
protected void | throwObjectContractViolation(Object o1, Object o2) - Convenience methods for subclasses to use in throwing exceptions about
badly behaved user objects employed as keys.
|
FREE
protected static final Object FREE
REMOVED
protected static final Object REMOVED
_hashingStrategy
protected TObjectHashingStrategy _hashingStrategy
the strategy used to hash objects in this collection.
_set
protected Object[] _set
the set of Objects
TObjectHash
public TObjectHash()
Creates a new TObjectHash
instance with the
default capacity and load factor.
TObjectHash
public TObjectHash(TObjectHashingStrategy strategy)
Creates a new TObjectHash
instance with the
default capacity and load factor and a custom hashing strategy.
strategy
- used to compute hash codes and to compare objects.
TObjectHash
public TObjectHash(int initialCapacity)
Creates a new TObjectHash
instance whose capacity
is the next highest prime above initialCapacity + 1
unless that value is already prime.
initialCapacity
- an int
value
TObjectHash
public TObjectHash(int initialCapacity,
TObjectHashingStrategy strategy)
Creates a new TObjectHash
instance whose capacity
is the next highest prime above initialCapacity + 1
unless that value is already prime. Uses the specified custom
hashing strategy.
initialCapacity
- an int
valuestrategy
- used to compute hash codes and to compare objects.
TObjectHash
public TObjectHash(int initialCapacity,
float loadFactor)
Creates a new TObjectHash
instance with a prime
value at or near the specified capacity and load factor.
initialCapacity
- used to find a prime capacity for the table.loadFactor
- used to calculate the threshold over which
rehashing takes place.
TObjectHash
public TObjectHash(int initialCapacity,
float loadFactor,
TObjectHashingStrategy strategy)
Creates a new TObjectHash
instance with a prime
value at or near the specified capacity and load factor. Uses
the specified custom hashing strategy.
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 objects.
capacity
protected int capacity()
clone
public TObjectHash clone()
- a shallow clone of this collection
computeHashCode
public final int computeHashCode(T o)
This is the default implementation of TObjectHashingStrategy:
it delegates hashing to the Object's hashCode method.
o
- for which the hashcode is to be computed
contains
public boolean contains(Object obj)
Searches the set for obj
equals
public final boolean equals(T o1,
T o2)
This is the default implementation of TObjectHashingStrategy:
it delegates equality comparisons to the first parameter's
equals() method.
o1
- an Object
valueo2
- an Object
value
- true if the objects are equal
forEach
public boolean forEach(TObjectProcedure procedure)
Executes procedure for each element in the set.
procedure
- a TObjectProcedure
value
- false if the loop over the set terminated because
the procedure returned false for some value.
index
protected int index(T obj)
Locates the index of obj.
- the index of obj or -1 if it isn't in the set.
insertionIndex
protected int insertionIndex(T obj)
Locates the index at which obj can be inserted. if
there is already a value equal()ing obj in the set,
returns that value's index as -index - 1.
- the index of a FREE slot at which obj can be inserted
or, if obj is already stored in the hash, the negative value of
that index, minus 1: -index -1.
removeAt
protected void removeAt(int index)
setUp
protected int setUp(int initialCapacity)
initializes the Object set of this hash table.
initialCapacity
- an int
value
throwObjectContractViolation
protected final void throwObjectContractViolation(Object o1,
Object o2)
throws IllegalArgumentException
Convenience methods for subclasses to use in throwing exceptions about
badly behaved user objects employed as keys. We have to throw an
IllegalArgumentException with a rather verbose message telling the
user that they need to fix their object implementation to conform
to the general contract for java.lang.Object.
o1
- the first of the equal elements with unequal hash codes.o2
- the second of the equal elements with unequal hash codes.
GNU Trove is copyright B) 2001-2008 Eric D. Friedman. All Rights Reserved.