using System;
using System.Collections.Generic;
using Antlr4.Runtime.Sharpen;
namespace Antlr4.Runtime.Atn
{
public class PredictionContextCache
{
protected readonly Dictionary<PredictionContext, PredictionContext> cache =
new Dictionary<PredictionContext, PredictionContext>();
public PredictionContext Add(PredictionContext ctx)
{
if (ctx == EmptyPredictionContext.Instance)
return EmptyPredictionContext.Instance;
PredictionContext existing = cache.Get(ctx);
if (existing != null)
{
return existing;
}
cache.Put(ctx, ctx);
return ctx;
}
public PredictionContext Get(PredictionContext ctx)
{
return cache.Get(ctx);
}
public int Count
{
get
{
return cache.Count;
}
}
}
}