/// <summary> // Walks a Node in a depth-first/pre-order manner without recursion. // It returns a series of "events" that indicate one of three things: // - whether it has enters into a node // - whether it has exited from a node (i.e. it is finished with that container and its children) // - caller can control which children get entered via the enum_children method /// </summary> public static IEnumerable <GenTreeOps.WalkEvent <T> > Walk <T>(T node, EnumerateChildren <T> enum_children) { var stack = new Stack <WalkState <T> >(); // put the first item on the stack stack.Push(new WalkState <T>(node)); // As long as something is on the stack, we are not done while (stack.Count > 0) { var cur_item = stack.Pop(); if (cur_item.Entered == false) { var walkevent = WalkEvent <T> .CreateEnterEvent(cur_item.Node); yield return(walkevent); cur_item.Entered = true; stack.Push(cur_item); foreach (var child in Algorithms.efficient_reverse(enum_children(cur_item.Node))) { stack.Push(new WalkState <T>(child)); } } else { var walkevent = WalkEvent <T> .CreateExitEvent(cur_item.Node); yield return(walkevent); } } }
public void TearDown() { if (_enumerate != null) { _enumerate.Dispose(); } _enumerate = null; }
public void SetUp() { _enumerate = new EnumerateChildren(ClientFactory, RequestTimoutMilliseconds, LoggerMock) { Bucket = Bucket, Prefix = Prefix }; }
public static IEnumerable <T> PostOrder <T>(T root, EnumerateChildren <T> enum_children) { foreach (var walkevent in Traversal.Walk <T>(root, enum_children, x => true)) { if (walkevent.HasExitedNode) { yield return(walkevent.Node); } } }
public static IEnumerable <T> PreOrder <T>(T root, EnumerateChildren <T> enum_children) { var stack = new Stack <T>(); // put the first item on the stack stack.Push(root); while (stack.Count > 0) { var cur_item = stack.Pop(); yield return(cur_item); foreach (var i in efficient_reverse(enum_children(cur_item))) { stack.Push(i); } } }
public static IEnumerable <T> PostOrder <T>(T root, EnumerateChildren <T> enum_children) { return(Algorithms.Walk(root, enum_children).Where(ev => ev.Type == WalkEventType.EventExit).Select(ev => ev.Node)); }
public static IEnumerable <T> PreOrder <T>(T root, EnumerateChildren <T> enum_children) { return(Algorithms.Walk(root, enum_children).Where(ev => ev.HasEnteredNode).Select(ev => ev.Node)); }
public void TearDown() { if (_enumerate != null) _enumerate.Dispose(); _enumerate = null; }