Package gnu.trove
Class TObjectHash<T>
java.lang.Object
gnu.trove.THash
gnu.trove.TObjectHash<T>
- All Implemented Interfaces:
TObjectHashingStrategy<T>,Externalizable,Serializable,Cloneable
- Direct Known Subclasses:
THashMap,THashSet,TObjectByteHashMap,TObjectDoubleHashMap,TObjectFloatHashMap,TObjectIntHashMap,TObjectLongHashMap,TObjectShortHashMap
An open addressed hashing implementation for Object types.
Created: Sun Nov 4 08:56:06 2001
- Version:
- $Id: TObjectHash.java,v 1.27 2009/06/01 22:14:44 robeden Exp $
- Author:
- Eric D. Friedman
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TObjectHashingStrategy<T> the strategy used to hash objects in this collection.protected Object[]the set of Objectsprotected static final Objectprotected static final ObjectFields inherited from class gnu.trove.THash
_autoCompactionFactor, _autoCompactRemovesRemaining, _free, _loadFactor, _maxSize, _size, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newTObjectHashinstance with the default capacity and load factor.TObjectHash(int initialCapacity) Creates a newTObjectHashinstance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime.TObjectHash(int initialCapacity, float loadFactor) Creates a newTObjectHashinstance with a prime value at or near the specified capacity and load factor.TObjectHash(int initialCapacity, float loadFactor, TObjectHashingStrategy<T> strategy) Creates a newTObjectHashinstance with a prime value at or near the specified capacity and load factor.TObjectHash(int initialCapacity, TObjectHashingStrategy<T> strategy) Creates a newTObjectHashinstance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime.TObjectHash(TObjectHashingStrategy<T> strategy) Creates a newTObjectHashinstance with the default capacity and load factor and a custom hashing strategy. -
Method Summary
Modifier and TypeMethodDescriptionprotected intcapacity()clone()final intcomputeHashCode(T o) This is the default implementation of TObjectHashingStrategy: it delegates hashing to the Object's hashCode method.booleanSearches the set for objfinal booleanThis is the default implementation of TObjectHashingStrategy: it delegates equality comparisons to the first parameter's equals() method.booleanforEach(TObjectProcedure<T> procedure) Executes procedure for each element in the set.protected intLocates the index of obj.protected intinsertionIndex(T obj) Locates the index at which obj can be inserted.voidprotected voidremoveAt(int index) Delete the record at index.protected intsetUp(int initialCapacity) initializes the Object set of this hash table.protected final voidthrowObjectContractViolation(Object o1, Object o2) Convenience methods for subclasses to use in throwing exceptions about badly behaved user objects employed as keys.voidMethods inherited from class gnu.trove.THash
calculateGrownCapacity, clear, compact, ensureCapacity, getAutoCompactionFactor, isEmpty, postInsertHook, reenableAutoCompaction, rehash, setAutoCompactionFactor, size, tempDisableAutoCompaction, trimToSize
-
Field Details
-
_set
the set of Objects -
_hashingStrategy
the strategy used to hash objects in this collection. -
REMOVED
-
FREE
-
-
Constructor Details
-
TObjectHash
public TObjectHash()Creates a newTObjectHashinstance with the default capacity and load factor. -
TObjectHash
Creates a newTObjectHashinstance with the default capacity and load factor and a custom hashing strategy.- Parameters:
strategy- used to compute hash codes and to compare objects.
-
TObjectHash
public TObjectHash(int initialCapacity) Creates a newTObjectHashinstance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime.- Parameters:
initialCapacity- anintvalue
-
TObjectHash
Creates a newTObjectHashinstance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime. Uses the specified custom hashing strategy.- Parameters:
initialCapacity- anintvaluestrategy- used to compute hash codes and to compare objects.
-
TObjectHash
public TObjectHash(int initialCapacity, float loadFactor) Creates a newTObjectHashinstance 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.
-
TObjectHash
Creates a newTObjectHashinstance with a prime value at or near the specified capacity and load factor. Uses the specified custom hashing strategy.- 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 objects.
-
-
Method Details
-
clone
-
capacity
protected int capacity() -
removeAt
protected void removeAt(int index) Description copied from class:THashDelete the record at index. Reduces the size of the collection by one. -
setUp
protected int setUp(int initialCapacity) initializes the Object set of this hash table. -
forEach
Executes procedure for each element in the set.- Parameters:
procedure- aTObjectProcedurevalue- Returns:
- false if the loop over the set terminated because the procedure returned false for some value.
-
contains
Searches the set for obj- Parameters:
obj- anObjectvalue- Returns:
- a
booleanvalue
-
index
Locates the index of obj.- Parameters:
obj- anObjectvalue- Returns:
- the index of obj or -1 if it isn't in the set.
-
insertionIndex
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.- Parameters:
obj- anObjectvalue- Returns:
- 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.
-
computeHashCode
This is the default implementation of TObjectHashingStrategy: it delegates hashing to the Object's hashCode method.- Specified by:
computeHashCodein interfaceTObjectHashingStrategy<T>- Parameters:
o- for which the hashcode is to be computed- Returns:
- the hashCode
- See Also:
-
equals
This is the default implementation of TObjectHashingStrategy: it delegates equality comparisons to the first parameter's equals() method.- Specified by:
equalsin interfaceTObjectHashingStrategy<T>- Parameters:
o1- anObjectvalueo2- anObjectvalue- Returns:
- true if the objects are equal
- See Also:
-
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.- Parameters:
o1- the first of the equal elements with unequal hash codes.o2- the second of the equal elements with unequal hash codes.- Throws:
IllegalArgumentException- the whole point of this method.
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Overrides:
writeExternalin classTHash- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Overrides:
readExternalin classTHash- Throws:
IOExceptionClassNotFoundException
-