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 obj)
 {
     if (!(obj is PredictionContextCache.IdentityCommutativePredictionContextOperands))
     {
         return(false);
     }
     else
     {
         if (this == obj)
         {
             return(true);
         }
     }
     PredictionContextCache.IdentityCommutativePredictionContextOperands other = (PredictionContextCache.IdentityCommutativePredictionContextOperands)obj;
     return((this.x == other.x && this.y == other.y) || (this.x == other.y && this.y == other.x));
 }
 public virtual PredictionContext Join(PredictionContext x, PredictionContext y)
 {
     if (!enableCache)
     {
         return PredictionContext.Join(x, y, this);
     }
     PredictionContextCache.IdentityCommutativePredictionContextOperands operands = new PredictionContextCache.IdentityCommutativePredictionContextOperands(x, y);
     PredictionContext result;
     if (joinContexts.TryGetValue(operands, out result))
     {
         return result;
     }
     result = PredictionContext.Join(x, y, this);
     result = GetAsCached(result);
     joinContexts[operands] = result;
     return result;
 }
        public virtual PredictionContext Join(PredictionContext x, PredictionContext y)
        {
            if (!enableCache)
            {
                return(PredictionContext.Join(x, y, this));
            }
            PredictionContextCache.IdentityCommutativePredictionContextOperands operands = new PredictionContextCache.IdentityCommutativePredictionContextOperands(x, y);
            PredictionContext result;

            if (joinContexts.TryGetValue(operands, out result))
            {
                return(result);
            }
            result = PredictionContext.Join(x, y, this);
            result = GetAsCached(result);
            joinContexts[operands] = result;
            return(result);
        }
 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;
 }