Package org.apache.uima.internal.util
Class Obj2IntIdentityHashMap<T>
- java.lang.Object
-
- org.apache.uima.internal.util.Common_hash_support
-
- org.apache.uima.internal.util.Obj2IntIdentityHashMap<T>
-
public class Obj2IntIdentityHashMap<T> extends Common_hash_support
A Map from non-null Objects of type T to ints int value 0 reserved to mean object is not in the table. This impl is for use in a single thread case only, for table updates Multiple reader threads are OK if there's no writing. Supports shrinking (reallocating the big table) Removed objects replaced with special marker object in the table so find operations continue to work (they can't stop upon finding this object).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
Obj2IntIdentityHashMap.Obj2IntIdentityHashMapIterator
-
Nested classes/interfaces inherited from class org.apache.uima.internal.util.Common_hash_support
Common_hash_support.CommonCopyOld2New, Common_hash_support.CommonKeyIterator
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Class<T>
componentType
private T[]
keys
private T
removedMarker
private int[]
values
-
Fields inherited from class org.apache.uima.internal.util.Common_hash_support
found_removed, histogram, initialCapacity, loadFactor, maxProbe, MIN_CAPACITY, MIN_CAPACITY_SHRINK, MIN_SIZE, removed, secondTimeShrinkable, sizeWhichTriggersExpansion, TUNE
-
-
Constructor Summary
Constructors Constructor Description Obj2IntIdentityHashMap(int initialCapacity, java.lang.Class<T> clazz, T removedMarker)
Obj2IntIdentityHashMap(java.lang.Class<T> clazz, T removedMarker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
clearKeysAndValues()
boolean
contains(java.lang.Object obj)
protected void
copy_to_new_table(int newCapacity, int oldCapacity, Common_hash_support.CommonCopyOld2New commonCopy)
int
find(T obj)
private int
findPosition(T obj)
returns a position in the key/value table if the key is not found, then the position will be to the place where the key would be put upon adding (without reusing REMOVED, and the current internal value of keys[position] would be 0.int
get(T obj)
T[]
getKeys()
protected boolean
is_valid_key(int pos)
IntListIterator
iterator()
protected int
keys_length()
protected void
newKeysAndValues(int capacity)
int
put(T obj, int value)
private void
putInner(T obj, int value)
used for increasing table sizeint
remove(java.lang.Object rawKey)
Can't replace the item with a null because other keys that were stored in the table which previously collided with the removed item won't be found.java.lang.String
toString()
-
Methods inherited from class org.apache.uima.internal.util.Common_hash_support
clear, commonPutOrAddNotFound, commonRemove, debugValidate, findPosition, getCapacity, incrementSize, moveToNextFilled, moveToPreviousFilled, newTable, resetHistogram, showHistogram, size, tableSpace
-
-
-
-
Constructor Detail
-
Obj2IntIdentityHashMap
public Obj2IntIdentityHashMap(int initialCapacity, java.lang.Class<T> clazz, T removedMarker)
- Parameters:
initialCapacity
- - you can add this many before expansionclazz
- - a superclass of the stored itemsremovedMarker
- - a unique value never stored in the table, used to mark removed items
-
-
Method Detail
-
findPosition
private int findPosition(T obj)
returns a position in the key/value table if the key is not found, then the position will be to the place where the key would be put upon adding (without reusing REMOVED, and the current internal value of keys[position] would be 0. if the key is found, then keys[position] == key- Parameters:
obj
- the object to find- Returns:
- the probeAddr in keys array - might reference a slot holding null, or the key value if found
-
contains
public boolean contains(java.lang.Object obj)
-
find
public int find(T obj)
- Parameters:
obj
- the object to find in the table (if it is there)- Returns:
- the position of obj in the table, or -1 if not in the table
-
get
public int get(T obj)
-
put
public int put(T obj, int value)
- Parameters:
obj
- the keyvalue
- the value- Returns:
- the previous value, or 0 if this map did not already contain the specified key
-
putInner
private void putInner(T obj, int value)
used for increasing table size- Parameters:
rawKey
-
-
remove
public int remove(java.lang.Object rawKey)
Can't replace the item with a null because other keys that were stored in the table which previously collided with the removed item won't be found. UIMA-4204- Parameters:
rawKey
- the value to remove- Returns:
- the value previously associated with the key, or 0 if none
-
getKeys
public T[] getKeys()
-
iterator
public IntListIterator iterator()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
is_valid_key
protected boolean is_valid_key(int pos)
- Specified by:
is_valid_key
in classCommon_hash_support
-
keys_length
protected int keys_length()
- Specified by:
keys_length
in classCommon_hash_support
-
newKeysAndValues
protected void newKeysAndValues(int capacity)
- Specified by:
newKeysAndValues
in classCommon_hash_support
-
clearKeysAndValues
protected void clearKeysAndValues()
- Specified by:
clearKeysAndValues
in classCommon_hash_support
-
copy_to_new_table
protected void copy_to_new_table(int newCapacity, int oldCapacity, Common_hash_support.CommonCopyOld2New commonCopy)
- Specified by:
copy_to_new_table
in classCommon_hash_support
-
-