Esempio n. 1
0
        public void FindTest()
        {
            OpenAddressHashTable <int, int> hashTable = new OpenAddressHashTable <int, int>();

            for (int i = 0; i < 10000; i++)
            {
                hashTable.Add(i, i);
            }

            for (int i = 100; i < 1000; i++)
            {
                hashTable.Remove(i);
            }

            bool result = false;

            for (int i = 100; i < 1000; i++)
            {
                result = result || hashTable.Contains(i);
            }

            bool resultTrue = true;

            for (int i = 0; i < 100; i++)
            {
                resultTrue = resultTrue & hashTable.Contains(i);
            }
            Assert.IsFalse(result);
            Assert.IsTrue(resultTrue);
        }
Esempio n. 2
0
        private static void TestingHashTable(OpenAddressHashTable <string, int> hashTable, string[] words)
        {
            foreach (var el in words)
            {
                if (hashTable.Contains(el))
                {
                    hashTable[el] = hashTable[el] + 1;
                }
                else
                {
                    hashTable.Add(el, 0);
                }
            }

            List <string> words7 = new List <string>();

            foreach (var pair in hashTable)
            {
                if (pair.Key.Length == 7)
                {
                    words7.Add(pair.Key);
                }
            }

            foreach (var el in words7)
            {
                hashTable.Remove(el);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Regex           regex    = new Regex(@"\p{L}+");
            MatchCollection _matches = regex.Matches(new StreamReader("WarAndWorld.txt").ReadToEnd());

            string[] _words = _matches.Cast <Match>().Select(v => v.Value.ToString().ToLower()).ToArray(); //LINQ запрос, перевод из Matches в string[]

            Stopwatch timer = new Stopwatch();

            var hashTable = new OpenAddressHashTable <string, int>();

            timer.Start();
            TestingHashTable(hashTable, _words);
            timer.Stop();

            Console.WriteLine($"Total time for OAHT is {timer.ElapsedMilliseconds}");

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

            timer.Reset();
            timer.Start();
            TestingDict(dict, _words);
            timer.Stop();

            Console.WriteLine($"Total time for Dictionary is {timer.ElapsedMilliseconds}");

            //FirstHashMaker<int> first = new FirstHashMaker<int>();
            //Console.WriteLine(first.GetHash(2000000));

            //SecondHashMaker<int> second = new SecondHashMaker<int>();
            //Console.WriteLine(second.GetHash(20000000));
        }
Esempio n. 4
0
        public void AddTest()
        {
            OpenAddressHashTable <int, int> hashTable = new OpenAddressHashTable <int, int>();

            for (int i = 0; i < 10000; i++)
            {
                hashTable.Add(i, i);
            }
            Assert.AreEqual(10000, hashTable.Count);
        }
Esempio n. 5
0
        public void CollissionTest()
        {
            OpenAddressHashTable <int, int> hashTable = new OpenAddressHashTable <int, int>();

            hashTable.Add(1, 1);
            hashTable.Add(374, 374);
            hashTable.Add(5, 5);
            hashTable.Add(2, 2);

            hashTable.Remove(1);

            Assert.IsTrue(hashTable.Contains(374));
        }