using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication27 { class Program { static int N = 20*1000; static int MAX = int.MaxValue; static public void VyrobNaplnASetridPole() { int[] pole = new int[N]; Random rnd = new Random(); for (int i = 0; i < N; i++) { pole[i] = rnd.Next(MAX); } for (int i = 0; i < N-1; i++) { for (int j = 0; j < N-1; j++) { if (pole[j+1] dict; public SeznamVDictionary() { dict = new Dictionary(); Pocet = 0; } public override void Pridej(string s) { if (!dict.ContainsKey(s)) { dict.Add(s, 1); Pocet++; } else dict[s]++; } } class SeznamJakoHashovaciTabulka : Seznam { int velikost; string[] pole; public SeznamJakoHashovaciTabulka(int velikost) { this.velikost = velikost; pole = new string[velikost]; Pocet = 0; } int f(string s) { int suma = 0; for (int i = 0; i < s.Length; i++) { suma = (suma + 273 * (i+1)*s[i] * (s[i]-'A') * s[i]) % velikost; } return suma; } public override void Pridej(string s) { System.Diagnostics.Debug.Assert(Pocet < velikost, "Seznam uz je plny"); int i = f(s); while (true) { if (pole[i]==null) { pole[i] = s; Pocet++; return; } if (pole[i]==s) { return; } i = (1 + i) % velikost; } } } class Program { static Random rnd = new Random(1); static string NahodnyString() { string s = ""; for (int i = 0; i < 5; i++) { s = s + (char)(rnd.Next(26) + 'A'); } return s; } static void Main(string[] args) { //Seznam seznam = new SeznamVPoli(1000*1000); //Seznam seznam = new SeznamJakoHashovaciTabulka(1000 * 1000*2); Seznam seznam = new SeznamVDictionary(); DateTime start = DateTime.Now; for (int i = 0; i < 1000*1000; i++) { seznam.Pridej( NahodnyString() ); if(i%10000==0) { DateTime ted = DateTime.Now; TimeSpan doba = ted - start; Console.WriteLine("{1}: {0} ms", doba.TotalMilliseconds,i); } } Console.WriteLine("Pocet = {0}",seznam.Pocet); DateTime cted = DateTime.Now; TimeSpan cdoba = cted - start; Console.WriteLine("Celkem: {0} ms", cdoba.TotalMilliseconds); } } }