Beispiel #1
0
        private static void AddToReversePostOrderListIterative(VarVersionNode root
                                                               , LinkedList <VarVersionNode> lst, HashSet <VarVersionNode> setVisited)
        {
            Dictionary <VarVersionNode, List <VarVersionEdge> > mapNodeSuccs = new Dictionary <
                VarVersionNode, List <VarVersionEdge> >();
            LinkedList <VarVersionNode> stackNode  = new LinkedList <VarVersionNode>();
            LinkedList <int>            stackIndex = new LinkedList <int>();

            stackNode.AddLast(root);
            stackIndex.AddLast(0);
            while (!(stackNode.Count == 0))
            {
                VarVersionNode node  = stackNode.Last.Value;
                int            index = Sharpen.Collections.RemoveLast(stackIndex);
                setVisited.Add(node);
                List <VarVersionEdge> lstSuccs = mapNodeSuccs.ComputeIfAbsent(node, (VarVersionNode
                                                                                     n) => new List <VarVersionEdge>(n.succs));
                for (; index < lstSuccs.Count; index++)
                {
                    VarVersionNode succ = lstSuccs[index].dest;
                    if (!setVisited.Contains(succ))
                    {
                        stackIndex.AddLast(index + 1);
                        stackNode.AddLast(succ);
                        stackIndex.AddLast(0);
                        break;
                    }
                }
                if (index == lstSuccs.Count)
                {
                    lst.AddFirst(node);
                    Sharpen.Collections.RemoveLast(stackNode);
                }
            }
        }
Beispiel #2
0
        public virtual VarVersionNode CreateNode(VarVersionPair ver)
        {
            VarVersionNode node;

            nodes.AddWithKey(node = new VarVersionNode(ver.var, ver.version), ver);
            return(node);
        }
Beispiel #3
0
 public VarVersionEdge(int type, VarVersionNode source, VarVersionNode dest)
 {
     // FIXME: can be removed?
     this.type       = type;
     this.source     = source;
     this.dest       = dest;
     this.hashCode__ = source.GetHashCode() ^ dest.GetHashCode() + type;
 }
Beispiel #4
0
 public virtual bool IsDominatorSet(VarVersionNode node, HashSet <VarVersionNode> domnodes
                                    )
 {
     if (domnodes.Count == 1)
     {
         var enumerator = domnodes.GetEnumerator();
         enumerator.MoveNext();
         return(engine.IsDominator(node, enumerator.Current));
     }
     else
     {
         HashSet <VarVersionNode> marked = new HashSet <VarVersionNode>();
         if (domnodes.Contains(node))
         {
             return(true);
         }
         LinkedList <VarVersionNode> lstNodes = new LinkedList <VarVersionNode>();
         lstNodes.AddLast(node);
         while (!(lstNodes.Count == 0))
         {
             VarVersionNode nd = lstNodes.RemoveAtReturningValue(0);
             if (marked.Contains(nd))
             {
                 continue;
             }
             else
             {
                 marked.Add(nd);
             }
             if ((nd.preds.Count == 0))
             {
                 return(false);
             }
             foreach (VarVersionEdge edge in nd.preds)
             {
                 VarVersionNode pred = edge.source;
                 if (!marked.Contains(pred) && !domnodes.Contains(pred))
                 {
                     lstNodes.AddLast(pred);
                 }
             }
         }
     }
     return(true);
 }