private bool Equals(Antlr4.Runtime.Atn.ArrayPredictionContext other, HashSet <PredictionContextCache.IdentityCommutativePredictionContextOperands> visited)
        {
            Stack <PredictionContext> selfWorkList  = new Stack <PredictionContext>();
            Stack <PredictionContext> otherWorkList = new Stack <PredictionContext>();

            selfWorkList.Push(this);
            otherWorkList.Push(other);
            while (selfWorkList.Count > 0)
            {
                PredictionContextCache.IdentityCommutativePredictionContextOperands operands = new PredictionContextCache.IdentityCommutativePredictionContextOperands(selfWorkList.Pop(), otherWorkList.Pop());
                if (!visited.Add(operands))
                {
                    continue;
                }
                int selfSize = operands.X.Size;
                if (selfSize == 0)
                {
                    if (!operands.X.Equals(operands.Y))
                    {
                        return(false);
                    }
                    continue;
                }
                int otherSize = operands.Y.Size;
                if (selfSize != otherSize)
                {
                    return(false);
                }
                for (int i = 0; i < selfSize; i++)
                {
                    if (operands.X.GetReturnState(i) != operands.Y.GetReturnState(i))
                    {
                        return(false);
                    }
                    PredictionContext selfParent  = operands.X.GetParent(i);
                    PredictionContext otherParent = operands.Y.GetParent(i);
                    if (selfParent.GetHashCode() != otherParent.GetHashCode())
                    {
                        return(false);
                    }
                    if (selfParent != otherParent)
                    {
                        selfWorkList.Push(selfParent);
                        otherWorkList.Push(otherParent);
                    }
                }
            }
            return(true);
        }
 public override bool Equals(object o)
 {
     if (this == o)
     {
         return(true);
     }
     else
     {
         if (!(o is Antlr4.Runtime.Atn.ArrayPredictionContext))
         {
             return(false);
         }
     }
     if (this.GetHashCode() != o.GetHashCode())
     {
         return(false);
     }
     // can't be same if hash is different
     Antlr4.Runtime.Atn.ArrayPredictionContext other = (Antlr4.Runtime.Atn.ArrayPredictionContext)o;
     return(Equals(other, new HashSet <PredictionContextCache.IdentityCommutativePredictionContextOperands>()));
 }
 private static PredictionContext AppendContext(PredictionContext context, PredictionContext suffix, PredictionContext.IdentityHashMap visited)
 {
     if (suffix.IsEmpty)
     {
         if (IsEmptyLocal(suffix))
         {
             if (context.HasEmpty)
             {
                 return EmptyLocal;
             }
             throw new NotSupportedException("what to do here?");
         }
         return context;
     }
     if (suffix.Size != 1)
     {
         throw new NotSupportedException("Appending a tree suffix is not yet supported.");
     }
     PredictionContext result;
     if (!visited.TryGetValue(context, out result))
     {
         if (context.IsEmpty)
         {
             result = suffix;
         }
         else
         {
             int parentCount = context.Size;
             if (context.HasEmpty)
             {
                 parentCount--;
             }
             PredictionContext[] updatedParents = new PredictionContext[parentCount];
             int[] updatedReturnStates = new int[parentCount];
             for (int i = 0; i < parentCount; i++)
             {
                 updatedReturnStates[i] = context.GetReturnState(i);
             }
             for (int i_1 = 0; i_1 < parentCount; i_1++)
             {
                 updatedParents[i_1] = AppendContext(context.GetParent(i_1), suffix, visited);
             }
             if (updatedParents.Length == 1)
             {
                 result = new SingletonPredictionContext(updatedParents[0], updatedReturnStates[0]);
             }
             else
             {
                 System.Diagnostics.Debug.Assert(updatedParents.Length > 1);
                 result = new Antlr4.Runtime.Atn.ArrayPredictionContext(updatedParents, updatedReturnStates);
             }
             if (context.HasEmpty)
             {
                 result = PredictionContext.Join(result, suffix);
             }
         }
         visited[context] = result;
     }
     return result;
 }
        private static PredictionContext AppendContext(PredictionContext context, PredictionContext suffix, PredictionContext.IdentityHashMap visited)
        {
            if (suffix.IsEmpty)
            {
                if (IsEmptyLocal(suffix))
                {
                    if (context.HasEmpty)
                    {
                        return(EmptyLocal);
                    }
                    throw new NotSupportedException("what to do here?");
                }
                return(context);
            }
            if (suffix.Size != 1)
            {
                throw new NotSupportedException("Appending a tree suffix is not yet supported.");
            }
            PredictionContext result;

            if (!visited.TryGetValue(context, out result))
            {
                if (context.IsEmpty)
                {
                    result = suffix;
                }
                else
                {
                    int parentCount = context.Size;
                    if (context.HasEmpty)
                    {
                        parentCount--;
                    }
                    PredictionContext[] updatedParents = new PredictionContext[parentCount];
                    int[] updatedReturnStates          = new int[parentCount];
                    for (int i = 0; i < parentCount; i++)
                    {
                        updatedReturnStates[i] = context.GetReturnState(i);
                    }
                    for (int i_1 = 0; i_1 < parentCount; i_1++)
                    {
                        updatedParents[i_1] = AppendContext(context.GetParent(i_1), suffix, visited);
                    }
                    if (updatedParents.Length == 1)
                    {
                        result = new SingletonPredictionContext(updatedParents[0], updatedReturnStates[0]);
                    }
                    else
                    {
                        System.Diagnostics.Debug.Assert(updatedParents.Length > 1);
                        result = new Antlr4.Runtime.Atn.ArrayPredictionContext(updatedParents, updatedReturnStates);
                    }
                    if (context.HasEmpty)
                    {
                        result = PredictionContext.Join(result, suffix);
                    }
                }
                visited[context] = result;
            }
            return(result);
        }