Package org.apache.uima.jcas.impl
Class JCasHashMapSubMap
java.lang.Object
org.apache.uima.jcas.impl.JCasHashMapSubMap
Part of the JCasHashMap.
There are multiple instances of this class, one per concurrancy level
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
(package private) int
(package private) int[]
private final float
(package private) int
(package private) int
private static final int
private static final int
(package private) static final ThreadLocal
<int[]> (package private) static final ThreadLocal
<int[]> private boolean
(package private) int
private int
private final int
private final Object
This lock is sometimes held by put, putIfAbsent, get, clear - not held if putIfAbsent or get find existing (non-reserve) item -- assumes no "remove" operation(package private) TOP[]
private static final boolean
-
Constructor Summary
ConstructorsConstructorDescriptionJCasHashMapSubMap
(float loadFactor, int subMapInitialCapacity, int concurrencyLevelBits) -
Method Summary
Modifier and TypeMethodDescription(package private) void
clear()
private TOP
find a real item or a reserve item, matching the key Can be called under lock or not.(package private) final TOP
get
(int key, int hash) Gets a value.private void
private void
private static boolean
iterator()
private JCasHashMapSubMap
newTable
(int capacity) private TOP[]
newTableKeepSize
(int capacity) (package private) final TOP
Puts a new value into the table, replacing an existing one if there is an entry already, or adding a new entry Starts by acquiring the lock.(package private) TOP
putIfAbsent
(int key, int hash, IntFunction<TOP> creatorFromKey) If an entry isn't already present for this key, calls a Supplier to create a value and puts it into the table.private void
Only used to fill in newly expanded table always called with lock heldprivate TOP
private static void
resetProbeInfo
(int[] probeInfo) private static void
setProbeInfo
(int[] probeInfo, int probeAddr, int probeDelta) private void
updateHistogram
(int nbrProbes, boolean isContinue) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
TUNE
private static final boolean TUNE- See Also:
-
PROBE_ADDR_INDEX
private static final int PROBE_ADDR_INDEX- See Also:
-
PROBE_DELTA_INDEX
private static final int PROBE_DELTA_INDEX- See Also:
-
probeInfoGet
-
probeInfoPutInner
-
histogram
int[] histogram -
maxProbe
int maxProbe -
maxProbeAfterContinue
int maxProbeAfterContinue -
continues
int continues -
synclock
This lock is sometimes held by put, putIfAbsent, get, clear - not held if putIfAbsent or get find existing (non-reserve) item -- assumes no "remove" operation -
sizeWhichTriggersExpansion
private int sizeWhichTriggersExpansion -
size
int size -
table
-
secondTimeShrinkable
private boolean secondTimeShrinkable -
loadFactor
private final float loadFactor -
subMapInitialCapacity
private final int subMapInitialCapacity -
concurrencyLevelBits
private final int concurrencyLevelBits
-
-
Constructor Details
-
JCasHashMapSubMap
JCasHashMapSubMap(float loadFactor, int subMapInitialCapacity, int concurrencyLevelBits)
-
-
Method Details
-
newTable
-
newTableKeepSize
-
incrementSize
private void incrementSize() -
clear
void clear() -
find
find a real item or a reserve item, matching the key Can be called under lock or not. Using a ref to the current value of table, searches that int array. If, during the search, the table is resized, it continues using the ** before the resize ** int array referenced by localTable The answer will only be OK if the key is found for a real value. Results that yield null or Reserved slots must be re-searched, under a lock (caller needs to do this).- Parameters:
key
- -hash
- -probeInfo
- - used to get/receive multiple int values; 0: (in/out) startProbe or -1; -1 starts at the hash invalid input: '&' bitMask 1: (in/out) probeDelta (starts at 1)- Returns:
- the probeAddr in original table (which might have been resized)
-
updateHistogram
private void updateHistogram(int nbrProbes, boolean isContinue) -
putIfAbsent
If an entry isn't already present for this key, calls a Supplier to create a value and puts it into the table. otherwise, doesn't call the Supplier and returns the already present value. If the key isn't present, gets a lock, and (partially, as necessary) redoes the find. - assert key still not present. - add a "reserve" for the slot where it will go -- reserve is a pseudo FS with a matching key, but with null _casView - release the lock -- eval the creator to create the item (may cause table to be updated) - require the lock - if resized, redo the find() till find the reserved item, and replace it with value. - if not resized, replace the prev reserved spot. Threading: not synchronized for main path where finding the element (if already in table). Since elements are never updated, there is no race if an element is found, except for table being resized. And it doesn't matter if the table is resized (if the element is found).- Parameters:
key
- - the id to use as the keyhash
- - the hash that was already computed from the keycreatorFromKey
- - the function to call to create the item.- Returns:
- - the found fs in the table with the same key, or the newly created item.
-
put
Puts a new value into the table, replacing an existing one if there is an entry already, or adding a new entry Starts by acquiring the lock.- Parameters:
key
- - the id to use as the keyhash
- - the hash that was already computed from the keycreator
- - the new value- Returns:
- - the previous fs in the table with the same key, or null
-
get
Gets a value. Threading: not synchronized for main path where get is finding an element. Since elements are never updated, there is no race if an element is found. And it doesn't matter if the table is resized (if the element is found). If it is not found, need to get the lock in order to get memory synch, and start over if resized, or continue from reserved or null spot if not- Parameters:
key
- - the addr in the heaphash
- - the hash that was already computed from the key- Returns:
- - the found fs, or null
-
putInner
Only used to fill in newly expanded table always called with lock held- Parameters:
key
- -value
- -hash
- -
-
increaseTableCapacity
private void increaseTableCapacity() -
isReserve
-
resetProbeInfo
private static void resetProbeInfo(int[] probeInfo) -
setProbeInfo
private static void setProbeInfo(int[] probeInfo, int probeAddr, int probeDelta) -
re_find
-
iterator
-