コード例 #1
0
        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);
        }
コード例 #2
0
        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.");
        }
コード例 #3
0
        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));
        }
コード例 #4
0
 public static T FindDescendentNode <T>(this IUnrootedTree <T> tree, Guid id) where T : ITreeNode <T>
 {
     return(FindDescendentNode(tree, id, out _));
 }