private void OnVertexFinished([NotNull] TVertex vertex)
        {
            foreach (TVertex target in VisitedGraph.OutEdges(vertex).Select(edge => edge.Target))
            {
                if (Components[target] == int.MaxValue)
                {
                    Roots[vertex] = MinDiscoverTime(Roots[vertex], Roots[target]);
                }
            }

            if (EqualityComparer <TVertex> .Default.Equals(Roots[vertex], vertex))
            {
                TVertex w;
                do
                {
                    w             = _stack.Pop();
                    Components[w] = ComponentCount;

                    ComponentsPerStep.Add(ComponentCount);
                    VerticesPerStep.Add(w);
                    ++Steps;
                }while (!EqualityComparer <TVertex> .Default.Equals(w, vertex));

                ++ComponentCount;
            }
        }
Esempio n. 2
0
        private void OnVertexFinished([NotNull] TVertex vertex)
        {
            foreach (TEdge edge in VisitedGraph.OutEdges(vertex))
            {
                TVertex target = edge.Target;
                if (Components[target] == int.MaxValue)
                {
                    Roots[vertex] = MinDiscoverTime(Roots[vertex], Roots[target]);
                }
            }

            if (Roots[vertex].Equals(vertex))
            {
                TVertex w;
                do
                {
                    w             = _stack.Pop();
                    Components[w] = ComponentCount;

                    ComponentsPerStep.Add(ComponentCount);
                    VerticesPerStep.Add(w);
                    ++Steps;
                }while (!w.Equals(vertex));

                ++ComponentCount;
            }
        }
        private void OnVertexDiscovered([NotNull] TVertex vertex)
        {
            Roots[vertex]      = vertex;
            Components[vertex] = int.MaxValue;

            ComponentsPerStep.Add(ComponentCount);
            VerticesPerStep.Add(vertex);
            ++Steps;

            DiscoverTimes[vertex] = _dfsTime++;
            _stack.Push(vertex);
        }