示例#1
0
        public GraphEnumerator(Graph g, TraversalStrategyEnum ts = TraversalStrategyEnum.BFS)
        {
            graph   = g ?? throw new NullReferenceException("The enumerable graph cannot be null.");
            version = g.Version;
            switch (ts)
            {
            case TraversalStrategyEnum.BFS:
            {
                strategy = new TraversalStrategyBFS(graph);
                break;
            }

            case TraversalStrategyEnum.DFS:
            {
                strategy = new TraversalStrategyDFS(graph);
                break;
            }
            }
            // if strategy's event fires, fire ours
            strategy.OnAllChildrenVisited += delegate(int nodeIndex)
            {
                OnAllChildrenVisited?.Invoke(nodeIndex);
            };
            strategy.OnHasNoChildren += delegate(int nodeIndex)
            {
                OnHasNoChildren?.Invoke(nodeIndex);
            };
        }
示例#2
0
 public void Dispose()
 {
     graph    = null;
     strategy = null;
 }