Пример #1
0
        /// <summary>
        /// Sorts file by batches. Splits to batches, sorts it and writes in temp files.
        /// Then merge temp files and sorts during the splitting. Writes to output sorted file.
        /// </summary>
        private static void Sort(
            string fileName, long fileSize, string sortFilePath, ISorter sorter, Stopwatch timer)
        {
            char[] chars = Settings.Chars.ToArray();

            Console.WriteLine("File size too big - splitting and sorting batches of the file....");

            var batchService = new BatchService(
                fileName,
                fileSize,
                new BatchCreator(chars),
                new BatchWriter(),
                sorter);

            BatchInfo[] batches = batchService.Execute();

            Console.WriteLine($"The file was batched to '{batches.Length}' peaces: {timer.Elapsed:g}.");
            Console.WriteLine("Merging...");

            var mergeService = new MergeService(sortFilePath, chars, sorter, new Comparer());

            mergeService.Merge(batches);
        }