Beispiel #1
0
        private void Bfs(Digraph g, int s)
        {
            if (g.V == 0)
            {
                return;
            }

            var q = new Queue <int>();

            _marked[s] = true;
            q.Enqueue(s);
            while (q.Any())
            {
                int v = q.Dequeue();
                foreach (int w in g.GetAdjList(v))
                {
                    if (!_marked[w])
                    {
                        _marked[w] = true;
                        q.Enqueue(w);
                        _preorder.Enqueue(w);
                    }
                }
            }
        }
        public List <T> GetDependencies(int symbolId, DependencyDirection direction, DependencyLevel level)
        {
            if (symbolId < 0 || symbolId >= SymbolTable.Count)
            {
                throw new ArgumentException(nameof(symbolId));
            }
            Digraph           g = direction == DependencyDirection.Downstream ? Digraph : Digraph.Reverse();
            IEnumerable <int> symbolIndexes;

            if (level == DependencyLevel.DirectOnly)
            {
                // That's easy
                symbolIndexes = g.GetAdjList(symbolId);
            }
            else
            {
                // Run BFS to find out
                var bfs = new DigraphBfs(g, symbolId);
                symbolIndexes = bfs.Preorder;
            }

            List <T> symbols = symbolIndexes
                               .Select(i => Keys[i])
                               .ToList();

            return(symbols);
        }
Beispiel #3
0
 private void Dfs(Digraph g, int v)
 {
     _marked[v] = true;
     foreach (var w in g.GetAdjList(v))
     {
         if (!_marked[w])
         {
             Dfs(g, w);
         }
     }
 }