Пример #1
0
 private static void AddIfNotVisited(Queue <NodeId> queue, NodeId node, VisitationTracker visitedNodes)
 {
     if (visitedNodes.MarkVisited(node))
     {
         queue.Enqueue(node);
     }
 }
Пример #2
0
        private void VisitTransitiveClosure(
            Queue <NodeId> queue,
            VisitationTracker visitedNodes,
            VisitNode visitNodeDependencies,
            VisitNode visitNodeDependents,
            bool dependencies,
            bool dependents)
        {
            Contract.Assert(visitNodeDependencies == null || dependencies);
            Contract.Assert(visitNodeDependents == null || dependents);

            while (queue.Count != 0)
            {
                var node = queue.Dequeue();

                if (dependencies)
                {
                    if (visitNodeDependencies == null || visitNodeDependencies(node))
                    {
                        foreach (Edge inEdge in m_dataflowGraph.GetIncomingEdges(node))
                        {
                            if (visitedNodes.MarkVisited(inEdge.OtherNode))
                            {
                                queue.Enqueue(inEdge.OtherNode);
                            }
                        }
                    }
                }

                if (dependents)
                {
                    if (visitNodeDependents == null || visitNodeDependents(node))
                    {
                        foreach (Edge outEdge in m_dataflowGraph.GetOutgoingEdges(node))
                        {
                            if (visitedNodes.MarkVisited(outEdge.OtherNode))
                            {
                                queue.Enqueue(outEdge.OtherNode);
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Visits the transitive dependencies of the node
        /// </summary>
        public void VisitTransitiveDependencies(
            NodeId startNode,
            VisitationTracker visitedNodes,
            VisitNode visitNode)
        {
            using (var queueWrapper = m_nodeQueuePool.GetInstance())
            {
                var queue = queueWrapper.Instance;
                AddIfNotVisited(queue, startNode, visitedNodes);

                VisitTransitiveClosure(
                    queue,
                    visitedNodes,
                    visitNodeDependents: null,
                    visitNodeDependencies: visitNode,
                    dependencies: true,
                    dependents: false);
            }
        }
Пример #4
0
        /// <summary>
        /// Visits the transitive reachable nodes of the given nodes
        /// </summary>
        public void VisitTransitiveReachableNodes(
            IEnumerable <NodeId> startNodes,
            VisitationTracker visitedNodes,
            VisitNode visitNodeDependencies,
            VisitNode visitNodeDependents)
        {
            using (var queueWrapper = m_nodeQueuePool.GetInstance())
            {
                var queue = queueWrapper.Instance;
                AddIfNotVisited(queue, startNodes, visitedNodes);

                VisitTransitiveClosure(
                    queue,
                    visitedNodes,
                    visitNodeDependencies: visitNodeDependencies,
                    visitNodeDependents: visitNodeDependents,
                    dependencies: true,
                    dependents: true);
            }
        }
Пример #5
0
 private static void AddIfNotVisited(Queue <NodeId> queue, IEnumerable <NodeId> nodes, VisitationTracker visitedNodes)
 {
     foreach (var node in nodes)
     {
         if (visitedNodes.MarkVisited(node))
         {
             queue.Enqueue(node);
         }
     }
 }