Example #1
0
        public void TestHashTable()
        {
            HashTable <string, int> hashTable = new HashTable <string, int>();

            for (int i = 1; i < 700; i++)
            {
                hashTable.Add(i.ToString(), i);
            }

            if (hashTable.LookUp("643") != 643)
            {
                Assert.Equal(643, hashTable.LookUp("643"));
            }

            if (hashTable.LookUp("56") != 56)
            {
                Assert.Equal(56, hashTable.LookUp("56"));
            }

            if (hashTable.LookUp("275") != 275)
            {
                Assert.True(false);
            }

            if (hashTable.LookUp("477") != 477)
            {
                Assert.True(false);
            }

            ChainableHashTable <string, int> chainableHashTable = new ChainableHashTable <string, int>();

            for (int i = 1; i < 1000; i++)
            {
                chainableHashTable.Add(i.ToString(), i);
            }

            if (hashTable.LookUp("643") != 643)
            {
                Assert.Equal(643, hashTable.LookUp("643"));
            }

            if (hashTable.LookUp("56") != 56)
            {
                Assert.Equal(56, hashTable.LookUp("56"));
            }

            if (hashTable.LookUp("275") != 275)
            {
                Assert.True(false);
            }

            if (hashTable.LookUp("477") != 477)
            {
                Assert.True(false);
            }

            TreeHashTable <string, int> treeHashTable = new TreeHashTable <string, int>();

            for (int i = 1; i < 1000; i++)
            {
                treeHashTable.Add(i.ToString(), i);
            }

            if (treeHashTable.LookUp("643") != 643)
            {
                Assert.Equal(643, treeHashTable.LookUp("643"));
            }

            if (treeHashTable.LookUp("56") != 56)
            {
                Assert.Equal(56, treeHashTable.LookUp("56"));
            }

            if (treeHashTable.LookUp("275") != 275)
            {
                Assert.True(false);
            }

            if (treeHashTable.LookUp("477") != 477)
            {
                Assert.True(false);
            }
        }
Example #2
0
        public static void LogHashTable()
        {
            HashTable <string, int> hashTable = new HashTable <string, int>();

            for (int i = 1; i < 2000; i++)
            {
                hashTable.Add(i.ToString(), i);

                if (i == 795)
                {
                    Console.WriteLine(hashTable.LookUp("685"));
                }
            }

            Console.WriteLine(hashTable.LookUp("685"));
            Console.WriteLine();

            ChainableHashTable <string, int> chainableHashTable = new ChainableHashTable <string, int>();

            for (int i = 1; i < 2000; i++)
            {
                chainableHashTable.Add(i.ToString(), i);

                if (i == 795)
                {
                    Console.WriteLine(chainableHashTable.LookUp("685"));
                }
            }

            Console.WriteLine(chainableHashTable.LookUp("685"));
            Console.WriteLine();

            HeadHashTable <string, int> headHashTable = new HeadHashTable <string, int>();

            for (int i = 1; i < 2000; i++)
            {
                headHashTable.Add(i.ToString(), i);

                if (i == 795)
                {
                    Console.WriteLine(headHashTable.LookUp("685"));
                }
            }

            Stopwatch watch = Stopwatch.StartNew();

            int value = headHashTable.LookUp("685");

            watch.Stop();

            Console.WriteLine(value + " :" + watch.Elapsed.Ticks);
            Console.WriteLine();

            TreeHashTable <string, int> treeHashTable = new TreeHashTable <string, int>();

            for (int i = 1; i < 2000; i++)
            {
                treeHashTable.Add(i.ToString(), i);

                if (i == 795)
                {
                    Console.WriteLine(treeHashTable.LookUp("685"));
                }
            }
            watch = Stopwatch.StartNew();

            value = treeHashTable.LookUp("685");

            watch.Stop();

            Console.WriteLine(value + " :" + watch.Elapsed.Ticks);

            treeHashTable.Remove("685");

            Console.WriteLine(treeHashTable.LookUp("685"));
        }