public static IReadOnlyCollection <T> GetAllDescendents <T>(this IUnrootedTree <T> tree) where T : ITreeNode <T> { List <T> foundNodes = new List <T>(); foreach (var childNode in tree.ChildNodes) { foundNodes.AddRange(childNode.GetAllDescendentsAndSelf()); } return(foundNodes); }
public static void RemoveDescendentNode <T>(this IUnrootedTree <T> tree, Guid id) where T : ITreeNode <T> { foreach (var child in tree.ChildNodes) { var success = RemoveDescendentNode(child, id); if (success) { return; } } throw new Exception("Node was not found."); }
public static T FindDescendentNode <T>(this IUnrootedTree <T> tree, Guid id, out IReadOnlyCollection <T> searchPath) where T : ITreeNode <T> { var searchStack = new Stack <T>(); foreach (var child in tree.ChildNodes) { var found = FindDescendentNode(child, id, searchStack); if (found != null) { searchPath = searchStack.ToArray(); return(found); } } searchPath = new List <T>(); return(default(T)); }
public static T FindDescendentNode <T>(this IUnrootedTree <T> tree, Guid id) where T : ITreeNode <T> { return(FindDescendentNode(tree, id, out _)); }