/// <summary> /// The entry point of the program /// </summary> /// <param name="args"></param> public static void Main(string[] args) { IHashFunction hashFunction; HashTable hashTable; Console.WriteLine("Enter:\n 1 to use first hash function\n 2 to use second hash function"); uint enter = Convert.ToUInt16(Console.ReadLine()); while (enter != 1 && enter != 2) { Console.WriteLine("Enter the correct number!"); enter = Convert.ToUInt16(Console.ReadLine()); } if (enter == 1) { hashFunction = new HashFunction1(); } else { hashFunction = new HashFunction2(); } int size = 5; hashTable = new HashTable(size, hashFunction); hashTable.Add(5); hashTable.Add(6); hashTable.Add(7); hashTable.Add(8); hashTable.Add(9); hashTable.Add(12); hashTable.Add(17); if (hashTable.Check(7)) { Console.WriteLine("The element is found"); } else { Console.WriteLine("The element not found"); } hashTable.Remove(12); if (hashTable.Check(12)) { Console.WriteLine("The element is found"); } else { Console.WriteLine("The element not found"); } if (hashTable.Check(17)) { Console.WriteLine("The element is found"); } else { Console.WriteLine("The element not found"); } }
/// <summary> /// The entry point of the program /// </summary> /// <param name="args"></param> public static void Main(string[] args) { int size = 5; HashTable hashTable = new HashTable(size); hashTable.Add(5); hashTable.Add(6); hashTable.Add(7); hashTable.Add(8); hashTable.Add(9); hashTable.Add(12); hashTable.Add(17); if (hashTable.Check(7)) { Console.WriteLine("The element is found"); } else { Console.WriteLine("The element not found"); } hashTable.Remove(12); if(hashTable.Check(12)) { Console.WriteLine("The element is found"); } else { Console.WriteLine("The element not found"); } if (hashTable.Check(17)) { Console.WriteLine("The element is found"); } else { Console.WriteLine("The element not found"); } }
private void UpdateHashTable() { double maxLoadFactor = 0.7; if (loadFactor >= maxLoadFactor) { int updateSizeFactor = 2; var newHashTable = new HashTable(size * updateSizeFactor); for (int i = 0; i < size; ++i) { for (int j = 1; j <= buckets[i].Size; ++j) { newHashTable.Add(buckets[i].Get(j).answer); } } buckets = newHashTable.buckets; size = newHashTable.size; notEmptyBuckets = newHashTable.notEmptyBuckets; loadFactor = newHashTable.loadFactor; } }
public void Initialize() { hashTable = new HashTable(5); }