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


C# HashTable.Contains方法代码示例

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


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

示例1: Main

        private static void Main()
        {
            const int elementsCount = 30000;
            var rand = new Random();
            var beforeHash = GC.GetTotalMemory(true);

            var hashTest = new HashTable<int, int>();
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            for (var i = 0; i < elementsCount; i++)
            {
                var currentNum = rand.Next();
                hashTest.Add(currentNum, currentNum);
                hashTest.Contains(currentNum);
            }

            stopWatch.Stop();
            var afterHash = GC.GetTotalMemory(true);

            Console.WriteLine(
                "The time needed to add {0} items in the HashTalbe was {1}", 
                hashTest.Count, 
                stopWatch.Elapsed);
            Console.WriteLine("Current capacity is {0} items", hashTest.Capacity);
            Console.WriteLine("{0} kb used", (afterHash - beforeHash) / 1024);
        }
开发者ID:hrist0stoichev,项目名称:Telerik-Homeworks,代码行数:28,代码来源:HashTableImplementation.cs

示例2: HashTable

        private static int HashTable(char[] data)
        {
            int[] diffs = new int[data.Length];
            int diff = 0;

            for(int i = 0; i < data.Length; i++)
            {
                if (LettersAndNumbers.IsNumber(data[i]))
                    diff++;
                else
                    diff--;

                diffs[i] = diff;
            }

            HashTable<int, int> hashTable = new HashTable<int, int>();
            hashTable[0] = -1;
            int max = 0;

            for(int i = 0; i < diffs.Length; i++)
            {
                if (hashTable.Contains(diffs[i]))
                    max = Math.Max(max, i - hashTable[diffs[i]]);
                else
                    hashTable[diffs[i]] = i;
            }

            return max;
        }
开发者ID:mmoroney,项目名称:Algorithms,代码行数:29,代码来源:LettersAndNumbers.cs

示例3: MakeFrequencyTable

 public static HashTable<char, int> MakeFrequencyTable(string input)
 {
     HashTable<char, int> result = new HashTable<char, int>(char.MaxValue, HashChar);
     foreach (char c in input){
         if (result.Contains(c)) {
             result[c] += 1;
         }
         else {
             result.Add(c, 1);
         }
     }
     return result;
 }
开发者ID:Mszauer,项目名称:DataStructures,代码行数:13,代码来源:Huffman.cs

示例4: HashTableTest

        public void HashTableTest()
        {
            for(int i = 0; i < 10; i++)
            {
                int[] data = ArrayUtilities.CreateRandomArray(20, 0, 15);

                HashTable<int, int> hashTable = new HashTable<int, int>();

                for(int j = 0; j < data.Length; j++)
                {
                    hashTable[j] = data[j];
                    Assert.IsTrue(hashTable.Contains(j));
                }

                for(int j = 0; j < data.Length; j++)
                {
                    bool contains = hashTable.Contains(j);
                    bool deleted = hashTable.Delete(j);
                    Assert.AreEqual(contains, deleted);
                    Assert.IsFalse(hashTable.Contains(j));
                }
            }
        }
开发者ID:mmoroney,项目名称:Algorithms,代码行数:23,代码来源:HashTableTests.cs

示例5: TestHashTableContains

        public void TestHashTableContains()
        {
            HashTable<string, int> hashTable = new HashTable<string, int>(3, 0.9f);

            hashTable.Add("m", 0);
            hashTable.Add("b", 0);
            hashTable.Add("t", 0);
            hashTable.Add("o", 0);
            hashTable.Add("z", 0);
            hashTable.Add("k", 0);
            hashTable.Add("g", 0);
            hashTable.Add("a5", 0);
            hashTable.Add("c", 0);
            hashTable.Add("a2", 0);
            hashTable.Add("a7", 0);
            hashTable.Add("i", 0);
            hashTable.Add("h", 0);

            Assert.IsTrue(hashTable.ContainsKey("m"));
            Assert.IsTrue(hashTable.Contains(new KeyValuePair<string, int>("m", 0)));
            Assert.IsTrue(hashTable.ContainsKey("b"));
            Assert.IsTrue(hashTable.Contains(new KeyValuePair<string, int>("b", 0)));
            Assert.IsTrue(hashTable.ContainsKey("t"));
            Assert.IsTrue(hashTable.Contains(new KeyValuePair<string, int>("t", 0)));
            Assert.IsTrue(hashTable.ContainsKey("o"));
            Assert.IsTrue(hashTable.Contains(new KeyValuePair<string, int>("o", 0)));
            Assert.IsTrue(hashTable.ContainsKey("z"));
            Assert.IsTrue(hashTable.Contains(new KeyValuePair<string, int>("z", 0)));
            Assert.IsTrue(hashTable.ContainsKey("k"));
            Assert.IsTrue(hashTable.Contains(new KeyValuePair<string, int>("k", 0)));
            Assert.IsTrue(hashTable.ContainsKey("g"));
            Assert.IsTrue(hashTable.Contains(new KeyValuePair<string, int>("g", 0)));
            Assert.IsTrue(hashTable.ContainsKey("a5"));
            Assert.IsTrue(hashTable.Contains(new KeyValuePair<string, int>("a5", 0)));
            Assert.IsTrue(hashTable.ContainsKey("c"));
            Assert.IsTrue(hashTable.Contains(new KeyValuePair<string, int>("a2", 0)));
            Assert.IsTrue(hashTable.ContainsKey("a7"));
            Assert.IsTrue(hashTable.Contains(new KeyValuePair<string, int>("a7", 0)));
            Assert.IsTrue(hashTable.ContainsKey("i"));
            Assert.IsTrue(hashTable.Contains(new KeyValuePair<string, int>("i", 0)));
            Assert.IsTrue(hashTable.ContainsKey("h"));
            Assert.IsTrue(hashTable.Contains(new KeyValuePair<string, int>("h", 0)));
        }
开发者ID:VesiBaleva,项目名称:TelerikAcademy,代码行数:43,代码来源:HashTableTests.cs

示例6: TestHashTableRemove

        public void TestHashTableRemove()
        {
            HashTable<string, int> hashTable = new HashTable<string, int>(3, 0.9f);

            hashTable.Add("m", 10);
            hashTable.Add("b", 2000);
            hashTable.Add("t", 0);
            hashTable.Add("o", 33);
            hashTable.Add("z", 0);
            hashTable.Add("k", -812);
            hashTable.Add("g", 0);
            hashTable.Add("a5", 91);
            hashTable.Add("c", 0);
            hashTable.Add("a2", 22);
            hashTable.Add("a7", 66);
            hashTable.Add("i", 707);
            hashTable.Add("h", -15);

            int value = 0;

            bool success = hashTable.Remove(new KeyValuePair<string, int>("a5", 91));
            Assert.IsTrue(success);
            Assert.AreEqual(12, hashTable.Count);
            Assert.IsFalse(hashTable.ContainsKey("a5"));
            Assert.IsFalse(hashTable.Contains(new KeyValuePair<string, int>("a5", 91)));

            success = hashTable.TryGetValue("a5", out value);
            Assert.IsFalse(success);
        }
开发者ID:Ivan-Dimitrov-bg,项目名称:.Net-framework,代码行数:29,代码来源:HashTableTest.cs

示例7: TestIfRemoveWorksCorrectly

        public void TestIfRemoveWorksCorrectly()
        {
            var table = new HashTable<int, int>();

            table.Add(1, 11);
            table.Add(2, 12);
            table.Add(3, 13);
            table.Add(4, 14);
            table.Add(5, 15);
            table.Add(6, 16);
            table.Add(7, 17);
            table.Add(8, 18);

            var count = table.Count;
            Assert.AreEqual(8, count);
            table.Remove(4);
            Assert.AreEqual(false, table.Contains(4));
            Assert.AreEqual(7, table.Count);
        }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:19,代码来源:HashTableTests.cs

示例8: ContainsShouldReturnTrueWhenTheGivenKeyValuePairIsPresent

        public void ContainsShouldReturnTrueWhenTheGivenKeyValuePairIsPresent()
        {
            var hashtable = new HashTable<double, string>();

            hashtable.Add(1.1, "fsdfsdf");

            Assert.IsTrue(hashtable.Contains(new KeyValuePair<double, string>(1.1, "fsdfsdf")));
        }
开发者ID:KonstantinSimeonov,项目名称:Studying-with-Pesho-and-Mimeto,代码行数:8,代码来源:HashTableTests.cs


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