Package gnu.trove.impl.hash
Class TObjectHash<T>
- java.lang.Object
-
- gnu.trove.impl.hash.THash
-
- gnu.trove.impl.hash.TObjectHash<T>
-
- All Implemented Interfaces:
java.io.Externalizable,java.io.Serializable
- Direct Known Subclasses:
TCustomObjectHash,THashMap,THashSet,TObjectByteHashMap,TObjectCharHashMap,TObjectDoubleHashMap,TObjectFloatHashMap,TObjectIntHashMap,TObjectLongHashMap,TObjectShortHashMap
public abstract class TObjectHash<T> extends THash
An open addressed hashing implementation for Object types.
Created: Sun Nov 4 08:56:06 2001- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.Object[]_setthe set of Objectsprotected booleanconsumeFreeSlotIndicates whether the last insertKey() call used a FREE slot.static java.lang.ObjectFREEstatic java.lang.ObjectREMOVED-
Fields inherited from class gnu.trove.impl.hash.THash
_autoCompactionFactor, _autoCompactRemovesRemaining, _autoCompactTemporaryDisable, _free, _loadFactor, _maxSize, _size, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR
-
-
Constructor Summary
Constructors Constructor Description TObjectHash()Creates 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected java.lang.IllegalArgumentExceptionbuildObjectContractViolation(java.lang.Object o1, java.lang.Object o2, java.lang.String extra)Convenience methods for subclasses to use in throwing exceptions about badly behaved user objects employed as keys.intcapacity()booleancontains(java.lang.Object obj)Searches the set for objprotected java.lang.StringdumpExtraInfo(java.lang.Object newVal, java.lang.Object oldVal, int currentSize, int oldSize, java.lang.Object[] oldKeys)protected booleanequals(java.lang.Object notnull, java.lang.Object two)booleanforEach(TObjectProcedure<? super T> procedure)Executes procedure for each element in the set.protected inthash(java.lang.Object notnull)protected intindex(java.lang.Object obj)Locates the index of obj.protected intinsertionIndex(T obj)Deprecated.useinsertKey(T)insteadprotected intinsertKey(T key)Locates the index at which key can be inserted.protected static java.lang.StringobjectInfo(java.lang.Object o)voidreadExternal(java.io.ObjectInput in)protected voidremoveAt(int index)Delete the record at index.protected static java.lang.StringreportPotentialConcurrentMod(int newSize, int oldSize)intsetUp(int initialCapacity)initializes the Object set of this hash table.protected voidthrowObjectContractViolation(java.lang.Object o1, java.lang.Object o2)Convenience methods for subclasses to use in throwing exceptions about badly behaved user objects employed as keys.protected voidthrowObjectContractViolation(java.lang.Object o1, java.lang.Object o2, int size, int oldSize, java.lang.Object[] oldKeys)Convenience methods for subclasses to use in throwing exceptions about badly behaved user objects employed as keys.voidwriteExternal(java.io.ObjectOutput out)-
Methods inherited from class gnu.trove.impl.hash.THash
calculateGrownCapacity, clear, compact, computeMaxSize, computeNextAutoCompactionAmount, ensureCapacity, fastCeil, getAutoCompactionFactor, isEmpty, postInsertHook, reenableAutoCompaction, rehash, saturatedCast, setAutoCompactionFactor, size, tempDisableAutoCompaction, trimToSize
-
-
-
-
Field Detail
-
_set
public transient java.lang.Object[] _set
the set of Objects
-
REMOVED
public static final java.lang.Object REMOVED
-
FREE
public static final java.lang.Object FREE
-
consumeFreeSlot
protected boolean consumeFreeSlot
Indicates whether the last insertKey() call used a FREE slot. This field should be inspected right after call insertKey()
-
-
Constructor Detail
-
TObjectHash
public TObjectHash()
Creates a newTObjectHashinstance with the default capacity and load factor.
-
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
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.
-
-
Method Detail
-
capacity
public 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
public int setUp(int initialCapacity)
initializes the Object set of this hash table.
-
forEach
public boolean forEach(TObjectProcedure<? super T> procedure)
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
public boolean contains(java.lang.Object obj)
Searches the set for obj- Parameters:
obj- anObjectvalue- Returns:
- a
booleanvalue
-
index
protected int index(java.lang.Object obj)
Locates the index of obj.- Parameters:
obj- anObjectvalue- Returns:
- the index of obj or -1 if it isn't in the set.
-
insertionIndex
@Deprecated protected int insertionIndex(T obj)
Deprecated.useinsertKey(T)insteadAlias introduced to avoid breaking the API. The new method name insertKey() reflects the changes made to the logic.- Parameters:
obj-
-
insertKey
protected int insertKey(T key)
Locates the index at which key can be inserted. if there is already a value equal()ing key in the set, returns that value's index as -index - 1.
If a slot is found the value is inserted. When a FREE slot is used the consumeFreeSlot field is set to true. This field should be used in the method invoking insertKey() to pass to postInsertHook()
- Parameters:
key- anObjectvalue- Returns:
- the index of a FREE slot at which key can be inserted or, if key is already stored in the hash, the negative value of that index, minus 1: -index -1.
-
throwObjectContractViolation
protected final void throwObjectContractViolation(java.lang.Object o1, java.lang.Object o2) throws java.lang.IllegalArgumentExceptionConvenience 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:
java.lang.IllegalArgumentException- the whole point of this method.
-
throwObjectContractViolation
protected final void throwObjectContractViolation(java.lang.Object o1, java.lang.Object o2, int size, int oldSize, java.lang.Object[] oldKeys) throws java.lang.IllegalArgumentExceptionConvenience 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.size-oldSize-oldKeys-- Throws:
java.lang.IllegalArgumentException- the whole point of this method.
-
buildObjectContractViolation
protected final java.lang.IllegalArgumentException buildObjectContractViolation(java.lang.Object o1, java.lang.Object o2, java.lang.String extra)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:
java.lang.IllegalArgumentException- the whole point of this method.
-
equals
protected boolean equals(java.lang.Object notnull, java.lang.Object two)
-
hash
protected int hash(java.lang.Object notnull)
-
reportPotentialConcurrentMod
protected static java.lang.String reportPotentialConcurrentMod(int newSize, int oldSize)
-
dumpExtraInfo
protected java.lang.String dumpExtraInfo(java.lang.Object newVal, java.lang.Object oldVal, int currentSize, int oldSize, java.lang.Object[] oldKeys)- Parameters:
newVal- the key being insertedoldVal- the key already stored at that positioncurrentSize- size of the key set during rehashingoldSize- size of the key set before rehashingoldKeys- the old key set
-
objectInfo
protected static java.lang.String objectInfo(java.lang.Object o)
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException- Specified by:
writeExternalin interfacejava.io.Externalizable- Overrides:
writeExternalin classTHash- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
readExternalin interfacejava.io.Externalizable- Overrides:
readExternalin classTHash- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
-