public void Run <TTree>(TTree tree) where TTree : ITree <TNode> { //_toVisit.Enqueue(tree); _toVisit.Put(tree); while (_toVisit.Any() && _stopSearch == false) { //var current = _toVisit.Dequeue(); var current = _toVisit.Pull(); var node = current.Node; Enter(current); FollowChildrenIfNeeded(current); } while (_lastEntered != default(ITree <TNode>)) { _nodeVisitor.OnLeave(_lastEntered, this); _lastEntered = _lastEntered.Parent; } }
public static IEnumerable <ITree <T> > TraverseDfs <T>(this ITree <T> tree, ISearchNodeVisitor <T> visitor, int depth) { if (depth == 0) { yield break; } visitor.OnEnter(tree, null); yield return(tree); foreach (var child in tree.Children.SelectMany(child => child.TraverseDfs(visitor, depth - 1))) { yield return(child); } visitor.OnLeave(tree, null); }
private void ContinueSearch <TTree>(TTree tree) where TTree : ITree <TNode> { _nodeVisitor.OnEnter(tree, this); if (false == _stopSearch && false == _dontEnterChildren) { foreach (var child in tree.Children) { if (_dontEnterNeighbours) { break; } Run(child); } _dontEnterNeighbours = false; } _nodeVisitor.OnLeave(tree, this); _dontEnterChildren = false; }
public void OnLeave(ITree <TNode> node, ITreeSearchContinuation treeSearchContinuation) { _second.OnLeave(node, treeSearchContinuation); _first.OnLeave(node, treeSearchContinuation); }
private void Leave(ITree <T> tree) { _nodeVisitor.OnLeave(tree, null); }