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


C# BinarySearchTree.ContainsKey方法代码示例

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


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

示例1: Simple

        public void Simple()
        {
            var tree = new BinarySearchTree<int, string>();
            tree.Clear();

            Assert.AreEqual(tree.Count, 0);

            tree = GetTestTree();
            Assert.IsTrue(tree.ContainsKey(19));

            tree.Clear();
            Assert.AreEqual(tree.Count, 0);
            Assert.IsFalse(tree.ContainsKey(19));
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:14,代码来源:Clear.cs

示例2: Simple

        public void Simple()
        {
            var tree = new BinarySearchTree<int, string>();

            var dictionary = new Dictionary<int, string>();

            var rand = new Random(Convert.ToInt32(DateTime.Now.Ticks % Int32.MaxValue));

            for (var i = 0; i < 50; i++)
            {
                var gen = rand.Next(2000);

                while (dictionary.ContainsKey(gen))
                {
                    gen = rand.Next(2000);
                }

                dictionary.Add(gen, null);

                tree.Add(gen, gen.ToString());

                Assert.AreEqual(tree.Count, i + 1);
                Assert.IsTrue(tree.ContainsKey(gen));
            }

            using (var enumerator = dictionary.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Assert.IsTrue(tree.Remove(enumerator.Current));
                }
            }
        }
开发者ID:havok,项目名称:ngenerics,代码行数:33,代码来源:Remove.cs

示例3: KeyValuePair

        public void KeyValuePair()
        {
            var tree = new BinarySearchTree<int, string>();

            var dictionary = new Dictionary<int, string>();

            var rand = new Random(Convert.ToInt32(DateTime.Now.Ticks % Int32.MaxValue));

            for (var i = 0; i < 50; i++)
            {
                var gen = rand.Next(2000);

                while (dictionary.ContainsKey(gen))
                {
                    gen = rand.Next(2000);
                }

                dictionary.Add(gen, null);

                tree.Add(new KeyValuePair<int, string>(gen, gen.ToString()));

                Assert.AreEqual(tree.Count, i + 1);
                Assert.IsTrue(tree.ContainsKey(gen));
            }
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:25,代码来源:Add.cs

示例4: AddKeyValuePairExample

        public void AddKeyValuePairExample()
        {
            // Create a simple tree
            BinarySearchTreeBase<string, int> tree = new BinarySearchTree<string, int>
                                                         {
                                                             new KeyValuePair<string, int>("cat", 1),
                                                             new KeyValuePair<string, int>("dog", 2),
                                                             new KeyValuePair<string, int>("canary", 3)
                                                         };

            // There should be 3 items in the tree.
            Assert.AreEqual(3, tree.Count);

            // The tree should contain all three keys
            Assert.IsTrue(tree.ContainsKey("cat"));
            Assert.IsTrue(tree.ContainsKey("dog"));
            Assert.IsTrue(tree.ContainsKey("canary"));

            // The value of the item with key "dog" must be 2.
            Assert.AreEqual(2, tree["dog"]);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:21,代码来源:BinarySearchTreeBaseExamples.cs

示例5: Simple2

        public void Simple2()
        {
            var tree = new BinarySearchTree<int, string>
                           {
                               {4, "4"},
                               {6, "6"},
                               {2, "2"},
                               {5, "5"},
                               {19, "19"},
                               {1, "1"}
                           };

            Assert.AreEqual(tree.Count, 6);

            Assert.IsTrue(tree.ContainsKey(4));
            Assert.IsTrue(tree.ContainsKey(6));
            Assert.IsTrue(tree.ContainsKey(2));
            Assert.IsTrue(tree.ContainsKey(5));
            Assert.IsTrue(tree.ContainsKey(19));
            Assert.IsTrue(tree.ContainsKey(1));

            Assert.IsFalse(tree.Remove(20));

            Assert.IsTrue(tree.Remove(4));
            Assert.AreEqual(tree.Count, 5);

            Assert.IsFalse(tree.ContainsKey(4));
            Assert.IsTrue(tree.ContainsKey(6));
            Assert.IsTrue(tree.ContainsKey(2));
            Assert.IsTrue(tree.ContainsKey(5));
            Assert.IsTrue(tree.ContainsKey(19));
            Assert.IsTrue(tree.ContainsKey(1));

            Assert.IsTrue(tree.Remove(2));
            Assert.AreEqual(tree.Count, 4);

            Assert.IsFalse(tree.ContainsKey(4));
            Assert.IsTrue(tree.ContainsKey(6));
            Assert.IsFalse(tree.ContainsKey(2));
            Assert.IsTrue(tree.ContainsKey(5));
            Assert.IsTrue(tree.ContainsKey(19));
            Assert.IsTrue(tree.ContainsKey(1));

            Assert.IsTrue(tree.Remove(19));
            Assert.AreEqual(tree.Count, 3);

            Assert.IsFalse(tree.ContainsKey(4));
            Assert.IsTrue(tree.ContainsKey(6));
            Assert.IsFalse(tree.ContainsKey(2));
            Assert.IsTrue(tree.ContainsKey(5));
            Assert.IsFalse(tree.ContainsKey(19));
            Assert.IsTrue(tree.ContainsKey(1));

            Assert.IsFalse(tree.Remove(20));

            Assert.IsTrue(tree.Remove(1));
            Assert.AreEqual(tree.Count, 2);

            Assert.IsFalse(tree.ContainsKey(4));
            Assert.IsTrue(tree.ContainsKey(6));
            Assert.IsFalse(tree.ContainsKey(2));
            Assert.IsTrue(tree.ContainsKey(5));
            Assert.IsFalse(tree.ContainsKey(19));
            Assert.IsFalse(tree.ContainsKey(1));

            Assert.IsTrue(tree.Remove(6));
            Assert.AreEqual(tree.Count, 1);

            Assert.IsFalse(tree.ContainsKey(4));
            Assert.IsFalse(tree.ContainsKey(6));
            Assert.IsFalse(tree.ContainsKey(2));
            Assert.IsTrue(tree.ContainsKey(5));
            Assert.IsFalse(tree.ContainsKey(19));
            Assert.IsFalse(tree.ContainsKey(1));

            Assert.IsTrue(tree.Remove(5));
            Assert.AreEqual(tree.Count, 0);

            Assert.IsFalse(tree.ContainsKey(4));
            Assert.IsFalse(tree.ContainsKey(6));
            Assert.IsFalse(tree.ContainsKey(2));
            Assert.IsFalse(tree.ContainsKey(5));
            Assert.IsFalse(tree.ContainsKey(19));
            Assert.IsFalse(tree.ContainsKey(1));

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

示例6: KeyValuePair

        public void KeyValuePair()
        {
            var tree = new BinarySearchTree<int, string>
                           {
                               {4, "4"},
                               {6, "6"},
                               {2, "2"},
                               {5, "5"},
                               {19, "19"},
                               {1, "1"}
                           };

            Assert.AreEqual(tree.Count, 6);

            Assert.IsTrue(tree.ContainsKey(4));
            Assert.IsTrue(tree.ContainsKey(6));
            Assert.IsTrue(tree.ContainsKey(2));
            Assert.IsTrue(tree.ContainsKey(5));
            Assert.IsTrue(tree.ContainsKey(19));
            Assert.IsTrue(tree.ContainsKey(1));

            Assert.IsFalse(tree.Remove(new KeyValuePair<int, string>(20, "20")));

            Assert.IsTrue(tree.Remove(new KeyValuePair<int, string>(4, "4")));
            Assert.AreEqual(tree.Count, 5);

            Assert.IsFalse(tree.ContainsKey(4));
            Assert.IsTrue(tree.ContainsKey(6));
            Assert.IsTrue(tree.ContainsKey(2));
            Assert.IsTrue(tree.ContainsKey(5));
            Assert.IsTrue(tree.ContainsKey(19));
            Assert.IsTrue(tree.ContainsKey(1));
        }
开发者ID:havok,项目名称:ngenerics,代码行数:33,代码来源:Remove.cs

示例7: ClearExample

        public void ClearExample()
        {
            // Create a simple tree
            BinarySearchTreeBase<string, int> tree = new BinarySearchTree<string, int>
                                                         {
                                                             new KeyValuePair<string, int>("cat", 1),
                                                             new KeyValuePair<string, int>("dog", 2),
                                                             new KeyValuePair<string, int>("canary", 3)
                                                         };

            // There should be 3 items in the tree.
            Assert.AreEqual(3, tree.Count);

            // Clear the tree
            tree.Clear();

            // The tree should be empty.
            Assert.AreEqual(0, tree.Count);

            // No cat here..
            Assert.IsFalse(tree.ContainsKey("cat"));
        }
开发者ID:havok,项目名称:ngenerics,代码行数:22,代码来源:BinarySearchTreeBaseExamples.cs

示例8: RemoveExample

        public void RemoveExample()
        {
            // Build a simple tree.
            BinarySearchTreeBase<string, int> tree = new BinarySearchTree<string, int>
                                                         {
                                                             new KeyValuePair<string, int>("cat", 1),
                                                             new KeyValuePair<string, int>("dog", 2),
                                                             new KeyValuePair<string, int>("canary", 3)
                                                         };

            // There are three items in the tree
            Assert.AreEqual(3, tree.Count);

            // Let's remove the dog
            tree.Remove("dog");

            // Now the tree contains only two items, and dog isn't
            // in the tree.
            Assert.AreEqual(2, tree.Count);
            Assert.IsFalse(tree.ContainsKey("dog"));
        }
开发者ID:havok,项目名称:ngenerics,代码行数:21,代码来源:BinarySearchTreeBaseExamples.cs

示例9: ContainsKeyExample

        public void ContainsKeyExample()
        {
            // Create a simple tree
            BinarySearchTreeBase<string, int> tree = new BinarySearchTree<string, int>
                                                         {
                                                             new KeyValuePair<string, int>("cat", 1),
                                                             new KeyValuePair<string, int>("dog", 2),
                                                             new KeyValuePair<string, int>("canary", 3)
                                                         };

            // The tree should contain a cat and a dog...
            Assert.IsTrue(tree.ContainsKey("cat"));
            Assert.IsTrue(tree.ContainsKey("dog"));

            // But definitely not an ostrich.
            Assert.IsFalse(tree.ContainsKey("ostrich"));
        }
开发者ID:havok,项目名称:ngenerics,代码行数:17,代码来源:BinarySearchTreeBaseExamples.cs

示例10: Simple

        public void Simple()
        {
            var tree = new BinarySearchTree<int, string>();

            Assert.IsFalse(tree.ContainsKey(5));

            tree.Add(4, "4");
            Assert.AreEqual(tree[4], "4");
            Assert.IsTrue(tree.ContainsKey(4));
            Assert.IsFalse(tree.ContainsKey(5));

            tree.Add(6, "6");
            Assert.AreEqual(tree[6], "6");
            Assert.IsTrue(tree.ContainsKey(4));
            Assert.IsFalse(tree.ContainsKey(5));
            Assert.IsTrue(tree.ContainsKey(6));

            tree.Add(2, "2");
            Assert.AreEqual(tree[2], "2");
            Assert.IsTrue(tree.ContainsKey(2));
            Assert.IsTrue(tree.ContainsKey(4));
            Assert.IsFalse(tree.ContainsKey(5));
            Assert.IsTrue(tree.ContainsKey(6));

            tree.Add(5, "5");
            Assert.AreEqual(tree[5], "5");
            Assert.IsTrue(tree.ContainsKey(2));
            Assert.IsTrue(tree.ContainsKey(4));
            Assert.IsTrue(tree.ContainsKey(5));
            Assert.IsTrue(tree.ContainsKey(6));

            var rand = new Random();

            tree = new BinarySearchTree<int, string>();

            var list = new List<int>();

            for (var i = 0; i < 100; i++)
            {
                int r;

                do
                {
                    r = rand.Next(5000);
                }
                while (list.Contains(r));

                list.Add(r);

                tree.Add(r, null);

                Assert.IsTrue(tree.ContainsKey(r));
            }
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:54,代码来源:Contains.cs


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