public bool Traverse(Visit onEnter, Path.Visit onEnterPath, Path.Visit onReturnPath, Visit onReturn) { HashSet <object> visited = new HashSet <object>(); bool stop = Traverse(visited, onEnter, onEnterPath, onReturnPath, onReturn, 0); return(stop); }
public bool Traverse(HashSet <object> visited, Visit onEnter, Path.Visit onEnterPath, Path.Visit onReturnPath, Visit onReturn, int depth) { bool stop = false; if (visited.Contains(this)) { return(stop); } visited.Add(this); if (onEnter != null) { stop = onEnter(depth, stop, this); if (stop) { return(stop); } } foreach (var exit in exits) { bool stopping = exit.Traverse(visited, onEnter, onEnterPath, onReturnPath, onReturn, depth + 1); stop = stop || stopping; if (stop) { break; } } if (onReturn != null) { bool stopping = onReturn(depth, stop, this); stop = stop || stopping; } return(stop); }