using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication20 { class HashovaciTabulka { string[] pole; int pocet; public HashovaciTabulka(int N) { pole = new string[N]; pocet = 0; } private int f(string s, int N) { int soucet = 0; for (int i = 0; i < s.Length; i++) { soucet = (soucet + ((i+1)* (i + 1)*1000)*s[i]) % N; } return soucet; } public void Pridej(string s) { if (pocet > pole.Length * 0.8) { Console.WriteLine("uz je plno!!"); return; } int kam = f(s, pole.Length); while (pole[kam]!=null) { if (pole[kam] == s) return; // uz tam to 's' je! kam = (kam + 1) % pole.Length; } // nasel jsme prazdne misto pole[kam] = s; pocet++; } } class Program { static void Main(string[] args) { for (int velikost = 1; velikost <= 100; velikost++) { Random rnd = new Random(1234); HashovaciTabulka ht = new HashovaciTabulka(1000 * 1000); //System.Collections.Hashtable ht = new System.Collections.Hashtable(); DateTime start = DateTime.Now; for (int i = 1; i < 10000 * velikost; i++) { int x = rnd.Next(1000 * 1000 * 1000); ht.Pridej(x.ToString()); } TimeSpan ts = DateTime.Now - start; Console.WriteLine("{0}0.000: {1}ms", velikost, ts.TotalMilliseconds); } } } }