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


C# RedBlackTree类代码示例

本文整理汇总了C#中RedBlackTree的典型用法代码示例。如果您正苦于以下问题:C# RedBlackTree类的具体用法?C# RedBlackTree怎么用?C# RedBlackTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: BuildStorageEntry

        private static int BuildStorageEntry(DirectoryEntry storageEntry)
        {
            // direct members of each storage are organised in a separate red-black tree
            RedBlackTree<DirectoryEntry> rbTree = new RedBlackTree<DirectoryEntry>();
            foreach (DirectoryEntry entry in storageEntry.Members.Values)
            {
                rbTree.Add(entry);
            }

            foreach (RedBlackTreeNode<DirectoryEntry> node in rbTree.InorderTreeWalk(rbTree.Root))
            {
                DirectoryEntry entry = node.Data;
                entry.NodeColor = GetNodeColor(node.Color);
                entry.LeftChildDID = GetNodeID(node.Left);
                entry.RightChildDID = GetNodeID(node.Right);

                if (entry.Members.Count > 0)
                {
                    entry.EntryType = EntryType.Storage;
                    entry.MembersTreeNodeDID = BuildStorageEntry(entry);
                }
                else
                {
                    entry.EntryType = EntryType.Stream;
                    entry.MembersTreeNodeDID = -1;
                }
            }

            return rbTree.Root.Data.ID;
        }
开发者ID:Johnnyfly,项目名称:source20131023,代码行数:30,代码来源:DirectoryTree.cs

示例2: EmptyTreeTest

        public void EmptyTreeTest()
        {
            var tree = new RedBlackTree<Int32>();

            Assert.IsTrue(tree.IsEmpty);
            Assert.IsFalse(tree.BredthContains(2));
        }
开发者ID:jramey,项目名称:BinaryTree,代码行数:7,代码来源:RedBlackTreeTests.cs

示例3: ExceptionNullKey

 public void ExceptionNullKey()
 {
     var redBlackTree = new RedBlackTree<object, string>
                            {
                                {null, "a"}
                            };
 }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:7,代码来源:Add.cs

示例4: RotationTests

        public void RotationTests()
        {
            var tree = new RedBlackTree<Int32>();

            tree.Insert(35);
            tree.Insert(25);
            tree.Insert(70);
            tree.Insert(10);
            tree.Insert(100);
            tree.Insert(20);
            tree.Insert(5);
            tree.Insert(85);
            tree.Insert(55);
            tree.Insert(40);

            Assert.AreEqual(35, tree.RootNode.NodeValue);
            Assert.AreEqual(20, tree.RootNode.LeftNode.NodeValue);
            Assert.AreEqual(25, tree.RootNode.LeftNode.RightNode.NodeValue);
            Assert.AreEqual(10, tree.RootNode.LeftNode.LeftNode.NodeValue);
            Assert.AreEqual(5, tree.RootNode.LeftNode.LeftNode.LeftNode.NodeValue);

            Assert.AreEqual(85, tree.RootNode.RightNode.NodeValue);
            Assert.AreEqual(100, tree.RootNode.RightNode.RightNode.NodeValue);
            Assert.AreEqual(55, tree.RootNode.RightNode.LeftNode.NodeValue);
            Assert.AreEqual(40, tree.RootNode.RightNode.LeftNode.LeftNode.NodeValue);
            Assert.AreEqual(70, tree.RootNode.RightNode.LeftNode.RightNode.NodeValue);
        }
开发者ID:jramey,项目名称:BinaryTree,代码行数:27,代码来源:RedBlackTreeTests.cs

示例5: NonIComparable

        public void NonIComparable()
        {
            var redBlackTree = new RedBlackTree<NonComparableTClass, string>();

            for (var i = 0; i < 100; i++)
            {
                redBlackTree.Add(new NonComparableTClass(i), i.ToString());
            }

            var newTree = SerializeUtil.BinarySerializeDeserialize(redBlackTree);

            Assert.AreNotSame(redBlackTree, newTree);
            Assert.AreEqual(redBlackTree.Count, newTree.Count);

            var redBlackTreeEnumerator = redBlackTree.GetEnumerator();
            var newTreeEnumerator = newTree.GetEnumerator();

            while (redBlackTreeEnumerator.MoveNext())
            {
                Assert.IsTrue(newTreeEnumerator.MoveNext());
                Assert.AreEqual(redBlackTreeEnumerator.Current.Key.Number, newTreeEnumerator.Current.Key.Number);
                Assert.AreEqual(redBlackTreeEnumerator.Current.Value, newTreeEnumerator.Current.Value);

                Assert.IsTrue(newTree.ContainsKey(redBlackTreeEnumerator.Current.Key));
                Assert.AreEqual(newTree[redBlackTreeEnumerator.Current.Key], redBlackTreeEnumerator.Current.Value);
            }

            Assert.IsFalse(newTreeEnumerator.MoveNext());
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:29,代码来源:Serialization.cs

示例6: ExceptionKeyAlreadyInTree

 public void ExceptionKeyAlreadyInTree()
 {
     var redBlackTree = new RedBlackTree<int, string>
                            {
                                {0, "50"},
                                {0, "20"}
                            };
 }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:8,代码来源:Add.cs

示例7: AddExample

        public void AddExample()
        {
            // Create a simple tree
            var tree = new RedBlackTree<string, int> {{"cat", 1}, {"dog", 2}, {"canary", 3}};

            // There should be 3 items in the tree.
            Assert.AreEqual(3, tree.Count);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:8,代码来源:RedBlackTreeExamples.cs

示例8: RootNodeTest

        public void RootNodeTest()
        {
            var tree = new RedBlackTree<Int32>();
            tree.Insert(10);

            Assert.IsFalse(tree.IsEmpty);
            Assert.IsTrue(tree.BredthContains(10));
            Assert.AreEqual(10, tree.RootNode.NodeValue);
        }
开发者ID:jramey,项目名称:BinaryTree,代码行数:9,代码来源:RedBlackTreeTests.cs

示例9: ContainsFailureTest

        public void ContainsFailureTest()
        {
            var tree = new RedBlackTree<Int32>();

            tree.Insert(10);
            tree.Insert(25);
            tree.Insert(7);

            Assert.IsFalse(tree.BredthContains(2));
        }
开发者ID:jramey,项目名称:BinaryTree,代码行数:10,代码来源:RedBlackTreeTests.cs

示例10: ContainsSuccessTest

        public void ContainsSuccessTest()
        {
            var tree = new RedBlackTree<Int32>();

            tree.Insert(10);
            tree.Insert(25);
            tree.Insert(7);

            Assert.IsTrue(tree.BredthContains(25));
        }
开发者ID:jramey,项目名称:BinaryTree,代码行数:10,代码来源:RedBlackTreeTests.cs

示例11: Simple

        public void Simple()
        {
            var redBlackTree = new RedBlackTree<int, string>();
            Assert.AreEqual(redBlackTree.Count, 0);
            Assert.IsTrue(redBlackTree.Comparer is KeyValuePairComparer<int, string>);

            redBlackTree = new RedBlackTree<int, string>(new ReverseComparer<int>());
            Assert.AreEqual(redBlackTree.Count, 0);
            Assert.IsTrue(redBlackTree.Comparer.GetType().IsAssignableFrom(typeof(KeyValuePairComparer<int, string>)));
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:10,代码来源:Contruction.cs

示例12: GetTestTree

        internal static RedBlackTree<int, string> GetTestTree(int noOfItems)
        {
            var redBlackTree = new RedBlackTree<int, string>();

            for (var i = 0; i < noOfItems; i++)
            {
                redBlackTree.Add(i, i.ToString());
            }

            return redBlackTree;
        }
开发者ID:havok,项目名称:ngenerics,代码行数:11,代码来源:RedBlackTreeTest.cs

示例13: AddItem

        public void AddItem()
        {
            RedBlackTree<int, int> tree = new RedBlackTree<int, int>();
            int temp;

            tree.Add(1, 1);

            Assert.AreEqual(tree.Count, 1);
            Assert.IsTrue(tree.TryGetValue(1, out temp));
            Assert.IsFalse(tree.TryGetValue(2, out temp));
        }
开发者ID:CedricDumont,项目名称:NMemory.Next,代码行数:11,代码来源:RedBlackTreeFixture.cs

示例14: Simple

        public void Simple()
        {
            var redBlackTree = GetTestTree();
            Assert.IsFalse(redBlackTree.IsEmpty);

            redBlackTree.Clear();
            Assert.IsTrue(redBlackTree.IsEmpty);

            redBlackTree = new RedBlackTree<int, string>();
            Assert.IsTrue(redBlackTree.IsEmpty);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:11,代码来源:Count.cs

示例15: AddTest

        public void AddTest()
        {
            //Arrange
            var bst = new RedBlackTree<int, string>();

            // 33 28 63 20 31 39 79 10 35 60          ( red links = 10 39 )

            var testData = new[]
            {
                new KeyValuePair<int, string>(33, "33"),
                new KeyValuePair<int, string>(28, "28"),
                new KeyValuePair<int, string>(63, "63"),
                new KeyValuePair<int, string>(20, "20"),
                new KeyValuePair<int, string>(31, "31"),
                new KeyValuePair<int, string>(39, "39"),
                new KeyValuePair<int, string>(79, "79"),
                new KeyValuePair<int, string>(10, "10"),
                new KeyValuePair<int, string>(35, "35"),
                new KeyValuePair<int, string>(60, "60"),
            };

            //Act
            Array.ForEach(testData, t =>
            {
                bst.Add(t.Key, t.Value);
            });

            bst.Add(75, "75");
            bst.Add(38, "38");
            bst.Add(12, "12");

            var result = bst.LevelOrderTraversal();

            //Assert
            Assert.AreEqual(result.ElementAt(0).Key, 33);
            Assert.AreEqual(result.ElementAt(1).Key, 28);
            Assert.AreEqual(result.ElementAt(2).Key, 63);
            Assert.AreEqual(result.ElementAt(3).Key, 12);
            Assert.AreEqual(result.ElementAt(4).Key, 31);
            Assert.AreEqual(result.ElementAt(5).Key, 39);
            Assert.AreEqual(result.ElementAt(6).Key, 79);
            Assert.AreEqual(result.ElementAt(7).Key, 10);
            Assert.AreEqual(result.ElementAt(8).Key, 20);
            Assert.AreEqual(result.ElementAt(9).Key, 38);
            Assert.AreEqual(result.ElementAt(10).Key, 60);
            Assert.AreEqual(result.ElementAt(11).Key, 75);
            Assert.AreEqual(result.ElementAt(12).Key, 35);

            //Assert are red nodes
            Assert.IsTrue(result.ElementAt(3).IsRed);
            Assert.IsTrue(result.ElementAt(5).IsRed);
            Assert.IsTrue(result.ElementAt(11).IsRed);
        }
开发者ID:GrigoryBushuev,项目名称:Algo,代码行数:53,代码来源:LLRBTreeTest.cs


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