コード例 #1
0
ファイル: TreeDecision.cs プロジェクト: MrHungerrr/CSharpDLLs
        public void Add(TreeDecision <T> treeToAdd, TreeElement <T> parent)
        {
            if (treeToAdd == null)
            {
                throw new NullReferenceException();
            }

            if (treeToAdd == this)
            {
                throw new ArgumentException();
            }

            if (_elements.Contains(parent) || parent == Root)
            {
                _branchCount += parent.PathCount * treeToAdd._branchCount;

                if (!parent.HasChildren)
                {
                    _branchCount -= parent.PathCount;
                }

                parent.AddChildren(treeToAdd.Root.Children);
                treeToAdd.Root.RemoveAllChildren();
                _elements.UnionWith(treeToAdd._elements);
            }
            else
            {
                throw new Exception($"Нет такого родителя!\n {parent}");
            }
        }
コード例 #2
0
ファイル: TreeDecision.cs プロジェクト: MrHungerrr/CSharpDLLs
        public void Add(TreeDecision <T> treeToAdd, IEnumerable <TreeElement <T> > parents)
        {
            if (treeToAdd == null)
            {
                throw new NullReferenceException();
            }

            if (treeToAdd == this)
            {
                throw new ArgumentException();
            }

            if (_elements.IsSupersetOf(parents))
            {
                foreach (var parent in parents)
                {
                    _branchCount += parent.PathCount * treeToAdd._branchCount;

                    if (!parent.HasChildren)
                    {
                        _branchCount -= parent.PathCount;
                    }

                    parent.AddChildren(treeToAdd.Root.Children);
                }

                treeToAdd.Root.RemoveAllChildren();
                _elements.UnionWith(treeToAdd._elements);
            }
            else
            {
                throw new Exception($"Нет таких родителей!\n{parents.ToString()}");
            }
        }
コード例 #3
0
ファイル: TreeIterator.cs プロジェクト: MrHungerrr/CSharpDLLs
        /// <summary>
        /// Итерировать в форме змейки без повтором элементов
        /// </summary>
        public static IEnumerable <TreeElement <T> > SnakeIterator <T>(this TreeDecision <T> tree)
        {
            if (tree.Root.HasChildren)
            {
                return(GetElementsSnake(tree.Root.Children));
            }

            throw new Exception("Пустое дерево!");
        }
コード例 #4
0
ファイル: TreeIterator.cs プロジェクト: MrHungerrr/CSharpDLLs
        internal static IEnumerable <TreeElement <T> > BranchIteratorWithRoot <T>(this TreeDecision <T> tree)
        {
            yield return(tree.Root);

            if (tree.Root.HasChildren)
            {
                foreach (var element in GetElementsDown(tree.Root))
                {
                    yield return(element);
                }
            }
        }
コード例 #5
0
ファイル: TreeDecision.cs プロジェクト: MrHungerrr/CSharpDLLs
 public void AddToLeafs(TreeDecision <T> treeToAdd)
 {
     if (!IsEmpty)
     {
         var leafs = GetLeafs();
         Add(treeToAdd, leafs);
     }
     else
     {
         Add(treeToAdd, Root);
     }
 }
コード例 #6
0
ファイル: TreeIterator.cs プロジェクト: MrHungerrr/CSharpDLLs
        /// <summary>
        /// Итерировать каждую ветку с повторами элементов
        /// </summary>
        public static IEnumerable <TreeElement <T> > BranchIteratorWithDuplicates <T>(this TreeDecision <T> tree)
        {
            if (tree.Root.HasChildren)
            {
                return(GetElementsDownWithDuplicates(tree.Root));
            }

            throw new Exception("Пустое дерево!");
        }
コード例 #7
0
ファイル: TreeDecision.cs プロジェクト: MrHungerrr/CSharpDLLs
 public void AddToRoot(TreeDecision <T> treeToAdd)
 {
     Add(treeToAdd, Root);
 }