Class ConcurrentIntIntMap
int → int map for rare-write / frequent-read workloads.
Used by the LL(1) prediction cache on ATN: many parser threads may
read the shared ATN while occasional writers insert newly discovered
single-token predictions. Reads are lock-free and allocation-free; writes
copy-on-write under a monitor and publish via a volatile reference.
Missing keys return MISSING (0). Predicted alternatives
are always ≥ 1 (ATN.INVALID_ALT_NUMBER is 0), so the
HPPC default empty value matches the domain without a second probe.
Mutating operations that must report a previous value or enforce
ConcurrentMap-style atomicity (put(int, int), putIfAbsent(int, int),
remove(int), replace(int, int, int)) complete under the same monitor so
ConcurrentIntIntMapView can honor the JDK map contract without a
dual store.
Not part of any public or protected API.
HPPC types stay package-private implementation detail.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidclear()Drops every entry (used byATN.clearDFA()).(package private) booleancontainsValue(int value) Whether any published entry has the given value.(package private) intget(int key) (package private) intput(int key, int value) Associateskeywithvalue.(package private) intputIfAbsent(int key, int value) Associateskeywithvalueonly if absent.(package private) intremove(int key) Removes the mapping forkeyif present.(package private) booleanremove(int key, int expectedValue) Removes the mapping forkeyonly if it is currently mapped toexpectedValue.(package private) intreplace(int key, int newValue) Replaces the entry forkeyonly if present.(package private) booleanreplace(int key, int oldValue, int newValue) Replaces the entry forkeyonly if currently mapped tooldValue.(package private) intsize()Approximate size of the published snapshot (for diagnostics/tests).(package private) int[]Immutable snapshot of all entries as interleavedkey, valuepairs (length2 * size()).
-
Field Details
-
MISSING
static final int MISSINGSentinel returned byget(int)when the key is absent. Equal toATN.INVALID_ALT_NUMBERso callers can treat zero as a miss.- See Also:
-
EMPTY_ENTRIES
private static final int[] EMPTY_ENTRIES -
lock
-
map
private volatile com.carrotsearch.hppc.IntIntHashMap mapPublished snapshot. Readers load once and consult the snapshot without further synchronization.
-
-
Constructor Details
-
ConcurrentIntIntMap
ConcurrentIntIntMap()
-
-
Method Details
-
get
int get(int key) - Parameters:
key- packed map key- Returns:
- stored value, or
MISSINGif absent
-
put
int put(int key, int value) Associateskeywithvalue.- Returns:
- the previous value associated with
key, orMISSINGif there was no mapping
-
putIfAbsent
int putIfAbsent(int key, int value) Associateskeywithvalueonly if absent.- Returns:
- the existing value if the key was present, or
MISSINGif the mapping was installed
-
remove
int remove(int key) Removes the mapping forkeyif present.- Returns:
- the previous value, or
MISSINGif absent
-
remove
boolean remove(int key, int expectedValue) Removes the mapping forkeyonly if it is currently mapped toexpectedValue.- Returns:
trueif the entry was removed
-
replace
boolean replace(int key, int oldValue, int newValue) Replaces the entry forkeyonly if currently mapped tooldValue.- Returns:
trueif the value was replaced
-
replace
int replace(int key, int newValue) Replaces the entry forkeyonly if present.- Returns:
- the previous value, or
MISSINGif absent
-
clear
void clear()Drops every entry (used byATN.clearDFA()). -
size
int size()Approximate size of the published snapshot (for diagnostics/tests). -
snapshotEntries
int[] snapshotEntries()Immutable snapshot of all entries as interleavedkey, valuepairs (length2 * size()). Used byConcurrentIntIntMapView.entrySet()so the JDK map façade can iterate without exposing HPPC types. Safe under concurrent writers: iteration walks a frozen array published with the volatile map load. -
containsValue
boolean containsValue(int value) Whether any published entry has the given value. Scans the current snapshot (lock-free). Used by the JDK view'scontainsValue.
-