public void GenerationalDictionary() { GenerationalDictionary <int, uint> gd = new GenerationalDictionary <int, uint>(); Random rnd = new Random(1001); const int generations = 1004; const int depth = 10000; const int modulo = 2; int[] genskip = new int[depth]; for (int i = 0; i < depth; i++) { genskip[i] = rnd.Next(23) + modulo + 1; // need to be bigger than modulo } for (uint g = 0; g < generations; g++) { gd.NextGeneration(); for (int i = 0; i < depth; i++) { if (g % genskip[i] == modulo) { // System.Diagnostics.Debug.WriteLine("{0} Add {1}", (g+1), i); gd[i] = g; } } } Stopwatch sw = new Stopwatch(); sw.Start(); long time = sw.ElapsedMilliseconds; //File.WriteAllText(@"c:\code\time.txt", "Time taken " + time); for (uint g = 0; g < generations; g++) { var dict = gd.Get(g + 1); // System.Diagnostics.Debug.WriteLine("At gen {0} get {1} {2}", g + 1, dict.Count, string.Join(",",dict.Values)); for (int i = 0; i < depth; i++) { bool present = g % genskip[i] == modulo; if (present) { Check.That(dict[i]).Equals(g); } else if (g < modulo) { Check.That(dict.ContainsKey(i)).IsFalse(); } else { Check.That(dict[i]).IsNotEqualTo(g); } } //foreach( var kvp in dict) { System.Diagnostics.Debug.WriteLine("{0} {1}={2}", g+1, kvp.Key, kvp.Value); } //System.Diagnostics.Debug.WriteLine(""); } for (uint g = 0; g < generations; g++) { var values = gd.GetValues(g + 1); for (int i = 0; i < depth; i++) { bool present = g % genskip[i] == modulo; if (present) { Check.That(values[i]).Equals(g); } else if (g < modulo) { Check.That(values.Contains((uint)i)).IsFalse(); } else { Check.That(values[i]).IsNotEqualTo(g); } } //foreach( var kvp in dict) { System.Diagnostics.Debug.WriteLine("{0} {1}={2}", g+1, kvp.Key, kvp.Value); } //System.Diagnostics.Debug.WriteLine(""); } //1004x10000 = release 3035 }
public List <MaterialCommodityMicroResource> Get(uint gen) { return(items.GetValues(gen)); }