Class: Antlr4::Runtime::PredictionContextCache

Inherits:
Object
  • Object
show all
Defined in:
lib/antlr4/runtime/prediction_context_cache.rb

Instance Method Summary collapse

Constructor Details

#initializePredictionContextCache



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

#sizeObject



22
23
24
# File 'lib/antlr4/runtime/prediction_context_cache.rb', line 22

def size
  @cache.size
end