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:
Externalizable
,Serializable
- Direct Known Subclasses:
TCustomObjectHash
,THashMap
,THashSet
,TObjectByteHashMap
,TObjectCharHashMap
,TObjectDoubleHashMap
,TObjectFloatHashMap
,TObjectIntHashMap
,TObjectLongHashMap
,TObjectShortHashMap
An open addressed hashing implementation for Object types.
Created: Sun Nov 4 08:56:06 2001
Created: Sun Nov 4 08:56:06 2001
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionObject[]
the set of Objectsprotected boolean
Indicates whether the last insertKey() call used a FREE slot.static final Object
static final Object
Fields inherited from class gnu.trove.impl.hash.THash
_autoCompactionFactor, _autoCompactRemovesRemaining, _autoCompactTemporaryDisable, _free, _loadFactor, _maxSize, _size, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newTObjectHash
instance with the default capacity and load factor.TObjectHash
(int initialCapacity) Creates a newTObjectHash
instance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime.TObjectHash
(int initialCapacity, float loadFactor) Creates a newTObjectHash
instance with a prime value at or near the specified capacity and load factor. -
Method Summary
Modifier and TypeMethodDescriptionprotected final IllegalArgumentException
buildObjectContractViolation
(Object o1, Object o2, String extra) Convenience methods for subclasses to use in throwing exceptions about badly behaved user objects employed as keys.int
capacity()
boolean
Searches the set for objprotected String
dumpExtraInfo
(Object newVal, Object oldVal, int currentSize, int oldSize, Object[] oldKeys) protected boolean
boolean
forEach
(TObjectProcedure<? super T> procedure) Executes procedure for each element in the set.protected int
protected int
Locates the index of obj.protected int
insertionIndex
(T obj) Deprecated.protected int
Locates the index at which key can be inserted.protected static String
objectInfo
(Object o) void
protected void
removeAt
(int index) Delete the record at index.protected static String
reportPotentialConcurrentMod
(int newSize, int oldSize) int
setUp
(int initialCapacity) initializes the Object set of this hash table.protected final void
throwObjectContractViolation
(Object o1, Object o2) Convenience methods for subclasses to use in throwing exceptions about badly behaved user objects employed as keys.protected final void
throwObjectContractViolation
(Object o1, Object o2, int size, int oldSize, Object[] oldKeys) Convenience methods for subclasses to use in throwing exceptions about badly behaved user objects employed as keys.void
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 Details
-
_set
the set of Objects -
REMOVED
-
FREE
-
consumeFreeSlot
protected boolean consumeFreeSlotIndicates whether the last insertKey() call used a FREE slot. This field should be inspected right after call insertKey()
-
-
Constructor Details
-
TObjectHash
public TObjectHash()Creates a newTObjectHash
instance with the default capacity and load factor. -
TObjectHash
public TObjectHash(int initialCapacity) Creates a newTObjectHash
instance whose capacity is the next highest prime above initialCapacity + 1 unless that value is already prime.- Parameters:
initialCapacity
- anint
value
-
TObjectHash
public TObjectHash(int initialCapacity, float loadFactor) Creates a newTObjectHash
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.
-
-
Method Details
-
capacity
public int capacity() -
removeAt
protected void removeAt(int index) Description copied from class:THash
Delete 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
Executes procedure for each element in the set.- Parameters:
procedure
- aTObjectProcedure
value- 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
- anObject
value- Returns:
- a
boolean
value
-
index
Locates the index of obj.- Parameters:
obj
- anObject
value- Returns:
- the index of obj or -1 if it isn't in the set.
-
insertionIndex
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
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
- anObject
value- 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(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.
-
throwObjectContractViolation
protected final void throwObjectContractViolation(Object o1, Object o2, int size, int oldSize, Object[] oldKeys) 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.size
-oldSize
-oldKeys
- @throws IllegalArgumentException the whole point of this method.- Throws:
IllegalArgumentException
-
buildObjectContractViolation
protected final IllegalArgumentException buildObjectContractViolation(Object o1, Object o2, 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:
IllegalArgumentException
- the whole point of this method.
-
equals
-
hash
-
reportPotentialConcurrentMod
-
dumpExtraInfo
protected String dumpExtraInfo(Object newVal, Object oldVal, int currentSize, int oldSize, 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
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Overrides:
writeExternal
in classTHash
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Overrides:
readExternal
in classTHash
- Throws:
IOException
ClassNotFoundException
-
insertKey(T)
instead