static void TestHashTable1()
        {
            var table = new HashTable1(5);

            table.Put(6, "A");
            table.Put(8, "B");
            table.Put(11, "C");
            table.Put(6, "A+");
            table.Put(12, "D");
            table.Put(14, "E");

            //table.Put(14, "E+");
            //table.Put(1, "F");


            table.Remove(16);
            table.Remove(10);
            Console.WriteLine(table.Get(7));
            Console.WriteLine(table.Get(8));
        }
Exemple #2
0
        private void button2_Click(object sender, EventArgs e) //HASH BUTTON
        {
            //Declaring a new instance of HashTable and displaying properties to the Windows Form
            HashTable1 Hash1 = new HashTable1();

            richTextBox2.AppendText(Hash1.AccessTime + "        ");
            richTextBox2.AppendText(Hash1.SearchTime + "\n");
            richTextBox2.AppendText(Hash1.InsertTime + "        ");
            richTextBox2.AppendText(Hash1.DeleteTime + "\n");
            richTextBox2.AppendText(Hash1.SpaceComplexity + "\n");
            richTextBox2.AppendText("These values represent worst case scenarios,\n" +
                                    "the expected running time for search, insert, and delete are usually: O(1)");

            //Displaying the Advantages and Disadvantages of HashTables to the Windows Form
            richTextBox1.AppendText(Hash1.Advantages("HASH TABLE: \n"));
            richTextBox1.AppendText(Hash1.Advantages("A hash table is a data structure that maps keys to values for highly efficient lookup.  \n" +
                                                     "Watch out for collisions where two different hash keys map to the same index.\n" +
                                                     "Lookup time is usually: O(1) \n" +
                                                     "Can be O(n) if number of collisions is very high. \n" +
                                                     "Alternatively, we can use a balanced binary search tree with lookup of O(log n), this will also use less space.  And it’s possible to iterate through the keys in order."));
            richTextBox1.AppendText("\n\n");
            richTextBox1.AppendText(Hash1.Disadvantages("The disadvantages of using a Hash Table in C# are: \n" +
                                                        "-Hash collisions are practically unavoidable.\n" +
                                                        "-Hash tables become quite inefficient when there are many collisions.\n" +
                                                        "-Hash table does not allow null values, like hash map.\n" +
                                                        "-There is also the extra space consideration when using a hash table."));

            //Displaying extra notes from a rich text file in the bin
            using (StreamReader Reader = new StreamReader(@"C:\Users\Clayt\source\repos\CSC205\CSC205_StudyProject\CSC205_StudyProject\bin\HashTable.rtf"))
            {
                while (!Reader.EndOfStream)
                {
                    richTextBox5.AppendText(Reader.ReadLine());
                }
            }
        }