当前位置: 首页>>代码示例>>C#>>正文


C# GeneralTree.Add方法代码示例

本文整理汇总了C#中GeneralTree.Add方法的典型用法代码示例。如果您正苦于以下问题:C# GeneralTree.Add方法的具体用法?C# GeneralTree.Add怎么用?C# GeneralTree.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GeneralTree的用法示例。


在下文中一共展示了GeneralTree.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Simple

        public void Simple()
        {
            var root = new GeneralTree<int>(5);

            var child1 = new GeneralTree<int>(2);
            var child2 = new GeneralTree<int>(3);
            var child3 = new GeneralTree<int>(1);

            root.Add(child1);
            root.Add(child2);
            root.Add(child3);

            var child4 = new GeneralTree<int>(9);
            var child5 = new GeneralTree<int>(12);
            var child6 = new GeneralTree<int>(13);

            child1.Add(child4);
            child1.Add(child5);
            child2.Add(child6);

            Assert.AreEqual(root.FindNode(target => target == 13), child6);

            Assert.AreEqual(root.FindNode(target => target == 2), child1);

            Assert.AreEqual(root.FindNode(target => target == 9), child4);

            Assert.AreEqual(root.FindNode(target => target == 57), null);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:28,代码来源:FindNode.cs

示例2: Crawl

        private GeneralTree<IDirectoryTreeNode> Crawl(DirectoryInfo directory, IDirectoryTreeNode rootNode)
        {
            IDirectoryTreeNode currentNode =
                featureNodeFactory.Create(rootNode != null ? rootNode.OriginalLocation : null, directory);

            if (rootNode == null)
            {
                rootNode = currentNode;
            }

            var tree = new GeneralTree<IDirectoryTreeNode>(currentNode);

            bool isRelevantFileFound = false;
            foreach (FileInfo file in directory.GetFiles().Where(file => relevantFileDetector.IsRelevant(file)))
            {
                isRelevantFileFound = true;
                IDirectoryTreeNode node = featureNodeFactory.Create(rootNode.OriginalLocation, file);
                tree.Add(node);
            }

            bool isRelevantDirectoryFound = false;
            foreach (DirectoryInfo subDirectory in directory.GetDirectories())
            {
                GeneralTree<IDirectoryTreeNode> subTree = Crawl(subDirectory, rootNode);
                if (subTree != null)
                {
                    isRelevantDirectoryFound = true;
                    tree.Add(subTree);
                }
            }

            if (!isRelevantFileFound && !isRelevantDirectoryFound) return null;

            return tree;
        }
开发者ID:chfj,项目名称:pickles,代码行数:35,代码来源:DirectoryTreeCrawler.cs

示例3: Simple

        public void Simple()
        {
            var root = new GeneralTree<int>(5);

            var child1 = new GeneralTree<int>(2);
            var child2 = new GeneralTree<int>(3);
            var child3 = new GeneralTree<int>(5);
            var child4 = new GeneralTree<int>(7);

            root.Add(child1);
            root.Add(child2);

            Assert.AreEqual(root.Count, 2);
            Assert.AreEqual(root.Degree, 2);

            root.RemoveAt(0);

            Assert.IsNull(child1.Parent);

            Assert.AreEqual(root.Count, 1);
            Assert.AreEqual(root.Degree, 1);
            Assert.AreEqual(root.GetChild(0), child2);
            Assert.AreEqual(root.GetChild(0).Data, 3);

            root.Add(child1);

            Assert.AreEqual(child1.Parent, root);
            Assert.AreEqual(root.Count, 2);
            Assert.AreEqual(root.Degree, 2);

            Assert.IsTrue(root.Remove(child1));
            Assert.IsNull(child1.Parent);

            Assert.AreEqual(root.Count, 1);
            Assert.AreEqual(root.Degree, 1);
            Assert.AreEqual(root.GetChild(0), child2);
            Assert.AreEqual(root.GetChild(0).Data, 3);

            Assert.IsFalse(root.Remove(child3));

            root.Add(child3);
            root.Add(child4);

            Assert.AreEqual(root.Count, 3);
            Assert.AreEqual(root.Degree, 3);

            var fiveNode = root.FindNode(target => target == 5);
            Assert.IsTrue(root.Remove(5));

            Assert.IsNull(fiveNode.Parent);

            Assert.AreEqual(root.Count, 2);
            Assert.AreEqual(root.Degree, 2);
            Assert.AreEqual(root.GetChild(1).Data, 7);

            Assert.IsFalse(root.Remove(13));
        }
开发者ID:havok,项目名称:ngenerics,代码行数:57,代码来源:Remove.cs

示例4: ExceptionInvalidSubTree

        public void ExceptionInvalidSubTree()
        {
            var root = new GeneralTree<int>(5);

            var child1 = new GeneralTree<int>(2);
            var child2 = new GeneralTree<int>(3);

            root.Add(child1);
            root.Add(child2);

            root.GetChild(3);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:12,代码来源:GetChild.cs

示例5: ExceptionInvalidIndex1

        public void ExceptionInvalidIndex1()
        {
            var root = new GeneralTree<int>(5);

            var child1 = new GeneralTree<int>(2);
            var child2 = new GeneralTree<int>(3);

            root.Add(child1);
            root.Add(child2);

            var i = root[3].Data;
        }
开发者ID:havok,项目名称:ngenerics,代码行数:12,代码来源:Index.cs

示例6: Interface

        public void Interface()
        {
            ITree<int> tree = new GeneralTree<int>(5);

            var child1 = new GeneralTree<int>(4);
            var child2 = new GeneralTree<int>(6);
            var child3 = new GeneralTree<int>(7);

            tree.Add(child1);
            tree.Add(child2);
            Assert.AreEqual(tree.Degree, 2);
            Assert.IsTrue(tree.Remove(child1));
            Assert.AreEqual(tree.Degree, 1);
            Assert.IsFalse(tree.Remove(child3));
            Assert.AreEqual(tree.Degree, 1);
            Assert.IsTrue(tree.Remove(child2));
            Assert.AreEqual(tree.Degree, 0);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:18,代码来源:Remove.cs

示例7: Simple

        public void Simple()
        {
            var root = new GeneralTree<int>(5);

            var child1 = new GeneralTree<int>(2);
            var child2 = new GeneralTree<int>(3);

            root.Add(child1);
            root.Add(child2);

            Assert.AreEqual(child1.Parent, root);
            Assert.AreEqual(child2.Parent, root);

            Assert.AreEqual(root.Count, 2);
            Assert.AreEqual(root.Degree, 2);

            Assert.AreEqual(root.GetChild(0), child1);
            Assert.AreEqual(root.GetChild(0).Data, child1.Data);

            Assert.AreEqual(root.GetChild(1).Data, child2.Data);
            Assert.AreEqual(root.GetChild(1), child2);

            root = new GeneralTree<int>(5)
                       {
                           2,
                           3
                       };

            Assert.AreEqual(root.GetChild(0).Data, child1.Data);
            Assert.AreEqual(root.GetChild(1).Data, child2.Data);

            Assert.AreEqual(root.GetChild(0).Parent, root);
            Assert.AreEqual(root.GetChild(1).Parent, root);

            var anotherRoot = new GeneralTree<int>(2);

            var movedChild = root.GetChild(0);
            anotherRoot.Add(movedChild);

            Assert.AreEqual(movedChild.Parent, anotherRoot);
            Assert.AreEqual(root.Degree, 1);
            Assert.AreEqual(root.GetChild(0).Parent, root);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:43,代码来源:Add.cs

示例8: GetTestTree

        internal static GeneralTree<int> GetTestTree()
        {
            var root = new GeneralTree<int>(5);

            var child1 = new GeneralTree<int>(2);
            var child2 = new GeneralTree<int>(3);
            var child3 = new GeneralTree<int>(1);

            root.Add(child1);
            root.Add(child2);
            root.Add(child3);

            var child4 = new GeneralTree<int>(9);
            var child5 = new GeneralTree<int>(12);
            var child6 = new GeneralTree<int>(13);

            child1.Add(child4);
            child1.Add(child5);
            child2.Add(child6);

            return root;
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:22,代码来源:GeneralTreeTest.cs

示例9: Simple

        public void Simple()
        {
            var tree = GetTestTree();
            var ancestors = tree.GetChild(0).GetChild(0).Ancestors;

            Assert.AreEqual(ancestors.Count, 2);
            Assert.AreEqual(ancestors[1], tree.GetChild(0));
            Assert.AreEqual(ancestors[0], tree);

            var root = new GeneralTree<int>(5);

            var child1 = new GeneralTree<int>(2);
            var child2 = new GeneralTree<int>(3);
            var child3 = new GeneralTree<int>(1);

            root.Add(child1);
            root.Add(child2);
            root.Add(child3);

            var child4 = new GeneralTree<int>(9);
            var child5 = new GeneralTree<int>(12);
            var child6 = new GeneralTree<int>(13);
            var child7 = new GeneralTree<int>(15);

            child1.Add(child4);
            child1.Add(child5);
            child2.Add(child6);

            child4.Add(child7);

            ancestors = child7.Ancestors;

            Assert.AreEqual(ancestors.Count, 3);

            Assert.AreEqual(ancestors[0], root);
            Assert.AreEqual(ancestors[1], child1);
            Assert.AreEqual(ancestors[2], child4);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:38,代码来源:Ancestors.cs

示例10: Simple

        public void Simple()
        {
            var generalTree = new GeneralTree<int>(5);

            Assert.AreEqual(generalTree.Height, 0);

            var s1 = new GeneralTree<int>(3);

            generalTree.Add(s1);

            Assert.AreEqual(generalTree.Height, 1);

            s1.Add(new GeneralTree<int>(6));

            Assert.AreEqual(generalTree.Height, 2);
            generalTree.Add(new GeneralTree<int>(4));

            Assert.AreEqual(generalTree.Height, 2);

            generalTree = GetTestTree();

            Assert.AreEqual(generalTree.Height, 2);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:23,代码来源:Height.cs

示例11: Crawl

        private GeneralTree<IDirectoryTreeNode> Crawl(DirectoryInfo directory, IDirectoryTreeNode rootNode)
        {
            IDirectoryTreeNode currentNode =
                featureNodeFactory.Create(rootNode != null ? rootNode.OriginalLocation : null, directory);

            if (rootNode == null)
            {
                rootNode = currentNode;
            }

            var tree = new GeneralTree<IDirectoryTreeNode>(currentNode);

            bool isRelevantFileFound = false;
            foreach (FileInfo file in directory.GetFiles().Where(file => relevantFileDetector.IsRelevant(file)))
            {
                isRelevantFileFound = true;

                IDirectoryTreeNode node = null;
                try
                {
                    node = featureNodeFactory.Create(rootNode.OriginalLocation, file);
                }
                catch (Exception)
                {     
                    if (log.IsWarnEnabled) log.WarnFormat("The file, {0}, will be ignored because it could not be read in properly", file.FullName);
                }

                if (node != null) tree.Add(node);
            }

            bool isRelevantDirectoryFound = false;
            foreach (DirectoryInfo subDirectory in directory.GetDirectories())
            {
                GeneralTree<IDirectoryTreeNode> subTree = Crawl(subDirectory, rootNode);
                if (subTree != null)
                {
                    isRelevantDirectoryFound = true;
                    tree.Add(subTree);
                }
            }

            if (!isRelevantFileFound && !isRelevantDirectoryFound) return null;

            return tree;
        }
开发者ID:ppnrao,项目名称:pickles,代码行数:45,代码来源:DirectoryTreeCrawler.cs

示例12: Simple

        public void Simple()
        {
            var tree = new GeneralTree<int>(5);

            var originalNodes = new GeneralTree<int>[10];

            for (var i = 10; i < 20; i++)
            {
                originalNodes[i - 10] = new GeneralTree<int>(i);
                tree.Add(originalNodes[i - 10]);
            }

            var childNodes = tree.ChildNodes;

            Assert.AreEqual(childNodes.Count, 10);

            for (var i = 0; i < 10; i++)
            {
                Assert.IsTrue(childNodes.Contains(originalNodes[i]));
            }
        }
开发者ID:havok,项目名称:ngenerics,代码行数:21,代码来源:ChildNodes.cs

示例13: CollectDirectories

        private bool CollectDirectories(DirectoryInfoBase directory, INode rootNode, GeneralTree<INode> tree)
        {
            List<GeneralTree<INode>> collectedNodes = new List<GeneralTree<INode>>();

            foreach (DirectoryInfoBase subDirectory in directory.GetDirectories().OrderBy(di => di.Name))
            {
                GeneralTree<INode> subTree = this.Crawl(subDirectory, rootNode);
                if (subTree != null)
                {
                    collectedNodes.Add(subTree);
                }
            }

            foreach (var node in collectedNodes)
            {
                tree.Add(node);
            }

            return collectedNodes.Count > 0;
        }
开发者ID:MikeThomas64,项目名称:pickles,代码行数:20,代码来源:DirectoryTreeCrawler.cs

示例14: CollectFiles

        private bool CollectFiles(DirectoryInfoBase directory, INode rootNode, GeneralTree<INode> tree)
        {
            List<INode> collectedNodes = new List<INode>();

            foreach (FileInfoBase file in directory.GetFiles().Where(file => this.relevantFileDetector.IsRelevant(file)))
            {
                INode node = null;
                try
                {
                    node = this.featureNodeFactory.Create(rootNode.OriginalLocation, file);
                }
                catch (Exception)
                {
                    if (Log.IsWarnEnabled)
                    {
                        // retrieving the name as file.FullName may trigger an exception if the FullName is too long
                        // so we retreive Name and DirectoryName separately
                        // https://github.com/picklesdoc/pickles/issues/199
                        var fullName = file.Name + " in directory " + file.DirectoryName;
                        Log.Warn("The file {0} will be ignored because it could not be read in properly", fullName);
                    }
                }

                if (node != null)
                {
                    collectedNodes.Add(node);
                }
            }

            foreach (var node in OrderFileNodes(collectedNodes))
            {
                tree.Add(node);
            }

            return collectedNodes.Count > 0;
        }
开发者ID:MikeThomas64,项目名称:pickles,代码行数:36,代码来源:DirectoryTreeCrawler.cs

示例15: CollectFiles

        private bool CollectFiles(DirectoryInfoBase directory, INode rootNode, GeneralTree<INode> tree)
      {
        List<INode> collectedNodes = new List<INode>();

        foreach (FileInfoBase file in directory.GetFiles().Where(file => this.relevantFileDetector.IsRelevant(file)))
        {
          INode node = null;
          try
          {
            node = this.featureNodeFactory.Create(rootNode.OriginalLocation, file);
          }
          catch (Exception)
          {
            if (log.IsWarnEnabled)
            {
              log.WarnFormat("The file, {0}, will be ignored because it could not be read in properly", file.FullName);
            }
          }

          if (node != null)
          {
            collectedNodes.Add(node);
          }
        }

        foreach (var node in OrderFileNodes(collectedNodes))
        {
          tree.Add(node);
        }

        return collectedNodes.Count > 0;
      }
开发者ID:eduaquiles,项目名称:pickles,代码行数:32,代码来源:DirectoryTreeCrawler.cs


注:本文中的GeneralTree.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。