Exemplo n.º 1
0
        private List <File> SortPhase(File sourceFile, uint bufferSize, int nSortRuns)
        {
            SortBuffer sortBuffer = new SortBuffer(
                nBlocks: bufferSize,
                blockSize: sourceFile.blockSize);

            List <File> runFiles = new List <File>();

            for (int runIndex = 0; runIndex < nSortRuns; runIndex++)
            {
                var outFile = SortPass(sourceFile, bufferSize, sortBuffer, runIndex);
                runFiles.Add(outFile);
            }
            return(runFiles);
        }
Exemplo n.º 2
0
        private File SortPass(File sourceFile, uint bufferSize, SortBuffer sortBuffer, int runIndex = 0)
        {
            sortBuffer.loadBlocks(
                sourceFile: sourceFile,
                startingBlock: (int)(runIndex * bufferSize)
                );

            sortBuffer.Sort();

            File outFile = new File(
                nBlocks: bufferSize,
                blockSize: sourceFile.blockSize,
                initializer: 0);

            sortBuffer.writeBack(outFile);
            return(outFile);
        }
Exemplo n.º 3
0
        //TODO: add block transfer counting to evaluate performance

        public File ExternalMergeSort(File sourceFile, uint bufferSize)
        {
            //Check wether there is enough blocks in the buffer?

            File sortedFile;
            int  nSortRuns = (int)Math.Ceiling((decimal)(sourceFile.nBlocks / bufferSize));

            if (nSortRuns > 1)
            {
                var runFiles = SortPhase(sourceFile, bufferSize, nSortRuns);

                sortedFile = MergePhase(sourceFile, bufferSize, runFiles);
            }
            else
            {
                SortBuffer sortBuffer = new SortBuffer(
                    nBlocks: bufferSize,
                    blockSize: sourceFile.blockSize);

                sortedFile = SortPass(sourceFile, bufferSize, sortBuffer);
            }

            return(sortedFile);
        }