예제 #1
0
        public static void TestArrayRAM(int amount, int step, int seed,
                                        Action <Array, ArrayLong, ArrayLong, ArrayLong, ArrayLong> algorithm)
        {
            var title = " " + algorithm.Method.DeclaringType.Name + ": Array in RAM";

            Console.WriteLine(new string('_', 119));
            Console.WriteLine("{0,-34}{1,14}{2,10}{3,22}",
                              title, "Current", "Total", "Elapsed time (ms)");

            for (var i = 0; i < RunCount; i++)
            {
                ComparisonCount = 0;
                SwapCount       = 0;

                var sample = new ArrayRAM(amount, seed);
                var a      = new ArrayLongRAM(amount);
                var t      = new ArrayLongRAM(amount);
                var count  = new ArrayLongRAM(1 << RadixSort.GroupLength);
                var pref   = new ArrayLongRAM(1 << RadixSort.GroupLength);

                _stopwatch = Stopwatch.StartNew();
                algorithm(sample, a, t, count, pref);
                _stopwatch.Stop();

                DrawTextProgressBar(amount, amount);
                Console.WriteLine();
                LogResults(title, amount);
                amount *= step;
            }
        }
        public LinkedListDisk(string fileName, int count, int seed)
        {
            Count = count;

            var data = new ArrayRAM(count, seed).Data;

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            try
            {
                using (var writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
                {
                    for (var i = 0; i < count; i++)
                    {
                        writer.Write(i * 12 + 4);
                        writer.Write(data[i]);
                    }

                    writer.Write(count * 12 + 4);
                }
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }