예제 #1
0
        public WalkingVertex <TKey, TValue> CreateSecondPassVertex()
        {
            CheckNotSealed();

            SecondPass = new WalkingVertex <TKey, TValue>(DependencyVertex, this);
            return(SecondPass);
        }
예제 #2
0
        public void AddOutgoing(WalkingVertex <TKey, TValue> outgoingVertex)
        {
            CheckNotSealed();

            _outgoing.Add(outgoingVertex);
            outgoingVertex.IncomingCount++;
        }
예제 #3
0
        private static void CheckForLoop(WalkingVertex <TKey, TValue> vertex, Stack <WalkingVertex <TKey, TValue> > stackP, Stack <WalkingVertex <TKey, TValue> > stackS, ref int counter, ref int loopNumber)
        {
            vertex.Index = counter++;
            stackP.Push(vertex);
            stackS.Push(vertex);

            foreach (var child in vertex.Outgoing)
            {
                if (child.Index == -1)
                {
                    CheckForLoop(child, stackP, stackS, ref counter, ref loopNumber);
                }
                else if (child.LoopNumber == -1)
                {
                    while (stackP.Peek().Index > child.Index)
                    {
                        stackP.Pop();
                    }
                }
            }

            if (stackP.Count > 0 && vertex == stackP.Peek())
            {
                if (SetLoopNumber(vertex, stackS, loopNumber))
                {
                    loopNumber++;
                }
                stackP.Pop();
            }
        }
예제 #4
0
        private static ImmutableArray <WalkingVertex <TKey, TValue> > CreateWalkingGraph(ImmutableArray <DependencyVertex <TKey, TValue> > snapshot, ImmutableArray <DependencyVertex <TKey, TValue> > changedVertices)
        {
            var analysisGraph      = ImmutableArray <WalkingVertex <TKey, TValue> > .Empty;
            var nodesByVertexIndex = new Dictionary <int, WalkingVertex <TKey, TValue> >();

            foreach (var vertex in changedVertices)
            {
                var node = new WalkingVertex <TKey, TValue>(snapshot[vertex.Index]);
                analysisGraph = analysisGraph.Add(node);
                nodesByVertexIndex[vertex.Index] = node;
            }

            var queue = new Queue <WalkingVertex <TKey, TValue> >(analysisGraph);

            while (queue.Count > 0)
            {
                var node = queue.Dequeue();
                foreach (var outgoingIndex in node.DependencyVertex.Outgoing)
                {
                    if (!nodesByVertexIndex.TryGetValue(outgoingIndex, out var outgoingNode))
                    {
                        outgoingNode  = new WalkingVertex <TKey, TValue>(snapshot[outgoingIndex]);
                        analysisGraph = analysisGraph.Add(outgoingNode);
                        nodesByVertexIndex[outgoingIndex] = outgoingNode;

                        queue.Enqueue(outgoingNode);
                    }

                    node.AddOutgoing(outgoingNode);
                }
            }

            return(analysisGraph);
        }
예제 #5
0
 public WalkingVertex(DependencyVertex <TKey, TValue> vertex, WalkingVertex <TKey, TValue> firstPass = null)
 {
     DependencyVertex = vertex;
     FirstPass        = firstPass;
     Index            = -1;
     LoopNumber       = firstPass?.LoopNumber ?? -1;
     _outgoing        = new List <WalkingVertex <TKey, TValue> >();
 }
예제 #6
0
 private static void RemoveLoopEdges(WalkingVertex <TKey, TValue> vertex, ref int counter)
 {
     vertex.Index = counter++;
     for (var i = vertex.Outgoing.Count - 1; i >= 0; i--)
     {
         var outgoing = vertex.Outgoing[i];
         if (outgoing.Index == -1)
         {
             RemoveLoopEdges(outgoing, ref counter);
         }
         else if (outgoing.Index < vertex.Index)
         {
             vertex.RemoveOutgoingAt(i);
         }
     }
 }
예제 #7
0
        private static bool SetLoopNumber(WalkingVertex <TKey, TValue> vertex, Stack <WalkingVertex <TKey, TValue> > stackS, int loopIndex)
        {
            var count = 0;
            WalkingVertex <TKey, TValue> loopVertex;

            do
            {
                loopVertex            = stackS.Pop();
                loopVertex.LoopNumber = loopIndex;
                count++;
            } while (loopVertex != vertex);

            if (count != 1)
            {
                return(true);
            }

            vertex.LoopNumber = -2;
            return(false);
        }