private void Rehash(string value) { HashSet_D map = new HashSet_D(capacity * 2); int key = Hash(value); for (int i = 0; i < capacity; i++) { string fileName = String.Format(@"hashEntry{0}.dat", i); string text = System.IO.File.ReadAllText(fileName); int byteLength = Encoding.ASCII.GetBytes(text).Count(); if (byteLength > 0) { using (var reader = new StreamReader(fileName)) { string line; while ((line = reader.ReadLine()) != null) { map.Put(line); } } } } map.Put(value); chainsCounter = map.chainsCounter; rehashesCounter++; }
public static void HashSetDTest() { Random rand = new Random(); List <string> names = File.ReadAllLines(@"E:\Programavimas\Semestras_04\Algortimu_sudarymas\Labaratorinis_01\HashTable\HashTable\vardai.txt").ToList(); List <string> surenames = File.ReadAllLines(@"E:\Programavimas\Semestras_04\Algortimu_sudarymas\Labaratorinis_01\HashTable\HashTable\pavardes.txt").ToList(); int operationsCount = 0; int quantity = 100; Console.WriteLine("Maisos lentele su sarasais isorineje atmintyje:"); Console.WriteLine("______________________________________________________________"); Console.WriteLine("| Elementu kiekis | Paieskos laikas | Grandineliu skaicius |"); Console.WriteLine("|-----------------|-------------------|----------------------|"); for (int i = 1; i <= 7; i++) { HashSet_D hashSetD = new HashSet_D(quantity); List <string> result = new List <string>(); for (int m = 0; m < quantity; m++) { int rndName = rand.Next(names.Count - 1); int rndSureName = rand.Next(surenames.Count - 1); hashSetD.Put(names[rndName] + " " + surenames[rndSureName]); result.Add(names[rndName] + " " + surenames[rndSureName]); } hashSetD.Print(); var watch = System.Diagnostics.Stopwatch.StartNew(); for (int j = 0; j < result.Count; j++) { hashSetD.Contains(result[j]); // operationsCount = operationsCount + 3; } watch.Stop(); Console.WriteLine("| {0,15} | {1,17} | {2,20} |", result.Count, watch.Elapsed, hashSetD.GetChains()); watch.Reset(); operationsCount = 0; hashSetD.Clean(); quantity = quantity * 2; } Console.WriteLine("|-----------------|-------------------|----------------------|"); }