Beispiel #1
0
        private void SortMb <T>(int totalSize, int blockSize, bool ascending)
            where T : class, IComparable <T>
        {
            using (var temp = new TempFileFactory())
                using (var temp2 = new TempFileFactory())
                    using (var temp3 = new TempFileFactory()) {
                        if (typeof(T) == typeof(OrdersTab))
                        {
                            CreateTempFile(totalSize, temp, ascending);
                        }
                        else
                        {
                            CreateTempFileHeaderFooter(totalSize, temp, ascending);
                        }

                        var sorter = new BigFileSorter(blockSize);
                        sorter.Sort(temp, temp2);

                        var sorter2 = new BigFileSorter <T>(blockSize);
                        sorter2.Sort(temp, temp3);

                        if (!ascending)
                        {
                            ReverseFile(temp);
                        }

                        AssertSameFile(temp, temp2);
                        AssertSameFile(temp, temp3);
                    }
        }
Beispiel #2
0
        /// <summary>
        /// Use BigFileSorter to sort the generated file
        /// </summary>
        /// <param name="file">File to process</param>
        private static int TestBigFileSorter(string inputFile, string outputFile, int blockSize)
        {
            var sorter = new BigFileSorter <FixedSampleRecordSortable>(blockSize); // 10 Mb blocks

            sorter.Sort(inputFile, outputFile);
            return(sorter.BlockFileSizeInBytes);
        }
        //-> File:SortingWithoutRecord.cs
        public override void Run()
        {
            // Implements http://en.wikipedia.org/wiki/External_sorting
            // Uses the comparison in the construct

            var sorter = new BigFileSorter((x, y) => x.CompareTo(y));
            sorter.DeleteTempFiles = true;
            sorter.Sort("unsorted.txt", "sorted.txt");
        }
Beispiel #4
0
        //-> File:SortingWithoutRecord.cs
        public override void Run()
        {
            // Implements http://en.wikipedia.org/wiki/External_sorting
            // Uses the comparison in the construct

            var sorter = new BigFileSorter((x, y) => x.CompareTo(y));

            sorter.DeleteTempFiles = true;
            sorter.Sort("unsorted.txt", "sorted.txt");
        }
Beispiel #5
0
        //-> File:SortingWithRecord.cs
        public override void Run()
        {
            // Implements http://en.wikipedia.org/wiki/External_sorting
            // OrdersTab is IComparable<OrdersTab>

            var sorter = new BigFileSorter <OrdersTab>(10 * 1024 * 1024); // 10 Mb

            sorter.DeleteTempFiles = true;
            sorter.Sort("unsorted.txt", "sorted.txt");
        }
        //-> Implements <a href="http://en.wikipedia.org/wiki/External_sorting">External Sorting (wikipedia)</a>

        //-> You don't need to declare a record class to sort a file, you can sort with a compare method
        //-> You can use any sort you want, for example sorting by line length

        protected override void Run()
        {
            //-> File:SortingWithoutRecord.cs

            // Sort comparing the raw lines
            var sorter = new BigFileSorter((x, y) =>
                                           string.Compare(x, y, StringComparison.Ordinal));

            sorter.Sort("input.txt", "sorted.txt");
            //-> /File
        }
        //-> File:SortingWithoutRecord.cs
        public override void Run()
        {
            // Implements http://en.wikipedia.org/wiki/External_sorting

            var sorter = new BigFileSorter(
                (x, y) => {
                    // You can add here any custom function
                    return x.Length.CompareTo(y.Length);
                });
            sorter.DeleteTempFiles = true;
            sorter.Sort("unsorted.txt", "sorted.txt");
        }
        //-> Implements <a href="http://en.wikipedia.org/wiki/External_sorting">External Sorting (wikipedia)</a>

        //-> You don't need to declare a record class to sort a file, you can sort with a compare method

        public override void Run()
        {
            //-> File:SortingWithoutRecord.cs

            // Sort comparing the raw lines
            var sorter = new BigFileSorter((x, y) =>
                    string.Compare(x, y, StringComparison.Ordinal));


            sorter.Sort("unsorted.txt", "sorted.txt");
            //-> /File
        }
Beispiel #9
0
        //-> If you need to sort a really big file (20Mb and more) you have the BigFileSorter

        //-> Implements <a href="http://en.wikipedia.org/wiki/External_sorting">External Sorting (wikipedia)</a>

        //-> The Sorter will split the file in blocks, write them to temp files, and finally join all in a sorted file

        public override void Run()
        {
            //-> File:SortingWithRecord.cs

            // OrdersTab must be IComparable<OrdersTab>

            // We recommend to split in blocks between 1 and 40 Mb
            var sorter = new BigFileSorter <OrdersTab>(10 * 1024 * 1024); // 10 Mb blocks

            sorter.Sort("unsorted.txt", "sorted.txt");

            //-> /File
        }
Beispiel #10
0
        //-> File:SortingWithoutRecord.cs
        public override void Run()
        {
            // Implements http://en.wikipedia.org/wiki/External_sorting

            var sorter = new BigFileSorter(
                (x, y) => {
                // You can add here any custom function
                return(x.Length.CompareTo(y.Length));
            });

            sorter.DeleteTempFiles = true;
            sorter.Sort("unsorted.txt", "sorted.txt");
        }
        //-> Implements <a href="http://en.wikipedia.org/wiki/External_sorting">External Sorting (wikipedia)</a>

        //-> You can use any sort you want, for example sorting by line length

        public override void Run()
        {
            //-> File:SortingWithoutRecord.cs

            var sorter = new BigFileSorter(
                (x, y) => {
                // You can add here any custom function
                return(x.Length.CompareTo(y.Length));
            });

            sorter.Sort("unsorted.txt", "sorted.txt");

            //-> /File
        }
        //-> Implements <a href="http://en.wikipedia.org/wiki/External_sorting">External Sorting (wikipedia)</a>

        //-> You can use any sort you want, for example sorting by line length

        public override void Run()
        {
            //-> File:SortingWithoutRecord.cs

            var sorter = new BigFileSorter(
                (x, y) => {
                    // You can add here any custom function
                    return x.Length.CompareTo(y.Length);
                });

            sorter.Sort("unsorted.txt", "sorted.txt");

            //-> /File
        }