Class: Antlr4::Runtime::PredictionContextCache
- Inherits:
-
Object
- Object
- Antlr4::Runtime::PredictionContextCache
- Defined in:
- lib/antlr4/runtime/prediction_context_cache.rb
Instance Method Summary collapse
- #add(ctx) ⇒ Object
- #get(ctx) ⇒ Object
-
#initialize ⇒ PredictionContextCache
constructor
A new instance of PredictionContextCache.
- #size ⇒ Object
Constructor Details
#initialize ⇒ PredictionContextCache
Returns a new instance of PredictionContextCache.
4 5 6 |
# File 'lib/antlr4/runtime/prediction_context_cache.rb', line 4 def initialize @cache = {} end |
Instance Method Details
#add(ctx) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/antlr4/runtime/prediction_context_cache.rb', line 8 def add(ctx) return EmptyPredictionContext::EMPTY if ctx == EmptyPredictionContext::EMPTY existing = @cache[ctx] return existing unless existing.nil? @cache[ctx] = ctx ctx end |
#get(ctx) ⇒ Object
18 19 20 |
# File 'lib/antlr4/runtime/prediction_context_cache.rb', line 18 def get(ctx) @cache[ctx] end |
#size ⇒ Object
22 23 24 |
# File 'lib/antlr4/runtime/prediction_context_cache.rb', line 22 def size @cache.size end |