Package org.antlr.v4.runtime.dfa
Class HashEdgeMap<T>
java.lang.Object
org.antlr.v4.runtime.dfa.AbstractEdgeMap<T>
org.antlr.v4.runtime.dfa.HashEdgeMap<T>
- All Implemented Interfaces:
EdgeMap<T>
Sparse open-addressed edge map used while a DFA state has only a few outgoing
edges. Grows by doubling and promotes to
ArrayEdgeMap when density
approaches half of the allowed symbol range.
PERF: isEmpty() / size() are O(1) via a retained
occupancy counter (updated only under the same monitor as structural
mutations). toMap() remains a cold diagnostic path (sorted
TreeMap for stable DFASerializer output); hot emptiness
checks must use isEmpty() directly rather than
toMap().isEmpty().
Lexer maps whose keys all lie in [0, tableLength) may be stored
identity-indexed (isDirectIndex()). get(int) does not branch
on that layout — parser maps stay on the hashed probe. DFAState
publishes directArray() for the lexer hot path.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.antlr.v4.runtime.dfa.AbstractEdgeMap
AbstractEdgeMap.AbstractEntrySet -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intInitial open-addressed table length (power of two).private final booleanprivate final AtomicIntegerArrayprivate final AtomicIntegerNumber of non-null slots.private final T[]Fields inherited from class org.antlr.v4.runtime.dfa.AbstractEdgeMap
maxIndex, minIndex -
Constructor Summary
ConstructorsModifierConstructorDescriptionHashEdgeMap(int minIndex, int maxIndex) HashEdgeMap(int minIndex, int maxIndex, int maxSparseSize) privateHashEdgeMap(HashEdgeMap<T> map, int maxSparseSize) privateHashEdgeMap(HashEdgeMap<T> map, int maxSparseSize, boolean allowDirect) -
Method Summary
Modifier and TypeMethodDescriptionprivate intbucket(int key) private static intbucket(int length, int key) clear()booleancontainsKey(int key) (package private) Object[]Values array for an identity-indexed map, ornullwhen this map is hashed.entrySet()get(int key) (package private) final TgetDirect(int key) Identity lookup.(package private) AtomicIntegerArraygetKeys()(package private) T[](package private) booleanIdentity-indexed lexer layout.booleanisEmpty()private static booleankeysFit(HashEdgeMap<?> src, int length) remove(int key) intsize()(package private) intTable length.toMap()Methods inherited from class org.antlr.v4.runtime.dfa.AbstractEdgeMap
putAll
-
Field Details
-
DEFAULT_MAX_SIZE
private static final int DEFAULT_MAX_SIZEInitial open-addressed table length (power of two). Raised from 2 to 8 so the common "handful of outgoing edges" case (parser token edges, short lexer loops) avoids collision-driven resize churn on the first fewput(int, T)calls. Tables still promote toArrayEdgeMaponce density approaches half of the allowed symbol range.- See Also:
-
keys
-
values
-
size
Number of non-null slots. Updated only insidesynchronized (this)mutation paths; read without the monitor for O(1)size()/isEmpty()(same visibility model asArrayEdgeMap). -
directIndex
private final boolean directIndexWhentrue, slotiholds keyiandgetDirect(int)is a plain array load. Final: an out-of-rangeput(int, T)publishes a new hashed map rather than flipping this flag. Public constructors stay hashed so the first inserts mutate in place. Parser maps (minIndex < 0, EOF is a key) never set this.
-
-
Constructor Details
-
HashEdgeMap
public HashEdgeMap(int minIndex, int maxIndex) -
HashEdgeMap
public HashEdgeMap(int minIndex, int maxIndex, int maxSparseSize) -
HashEdgeMap
-
HashEdgeMap
-
-
Method Details
-
isDirectIndex
boolean isDirectIndex()Identity-indexed lexer layout. Package-private; not part of the public API. -
tableLength
int tableLength()Table length. Package-private; used by tests andgetDirect(int). -
directArray
Object[] directArray()Values array for an identity-indexed map, ornullwhen this map is hashed. Slotiholds keyi. Package-private. -
getDirect
Identity lookup. Valid only whenisDirectIndex()is true. Keys outside[0, tableLength)miss. Does not read the key word, so a hashed map must not be queried through this method. -
keysFit
-
bucket
private static int bucket(int length, int key) -
bucket
private int bucket(int key) -
getKeys
-
getValues
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
public boolean containsKey(int key) -
get
-
put
-
remove
-
clear
-
toMap
-
entrySet
-