Meshbeyn / Projects

Namespace FastBWT

public abstract void ASorter.Sort

This method sorts source block and saves the sorted bytes to target block.

Syntax

public abstract long Sort(
    byte[] SourceBlock,
    byte[] TargetBlock,
    long DataSize = 0
)

Parameters

byte[] SourceBlock

Array with source bytes.

byte[] TargetBlock

Array for sorted bytes.

long DataSize

Source data length. If source block is not filled completely, set the amount of source bytes using this parameter. Default value 0 means DataSize = SourceBlock.length.

Return value

Starting index for BWT desorter.

Exceptions

IndexOutOfRangeException

This exception is thrown if DataSize is too big or if the TargetBlock is too small.

OutOfMemoryException

This exception is thrown if the sorter needs more memory than the system has or if you try to sort a too big source array with the sorter, that doesn't support this. You may try to use a system with more (virtual) memory or use other sorter.

Remarks

This method sorts SourceBlock to TargetBlock. You may use this method if you need to sort only one block. To sort multiple blocks, consider to use methods GenerateVector and FillSortedBlock. Method Sort creates new array for sorting vector and discards it after using. If you need to sort multiple blocks, this strategy is not optimal.

The capabilities and memory usage of method Sort depend on concrete implementation. Read the description of concrete Sorter classes for this information.

Example

static void SortFile()
{
    //Read File
    FileStream FS = new FileStream("d:\\ToSort", FileMode.Open);
    int Len = (int)FS.Length;
    byte[] Source = new byte[Len], Target = new byte[Len];
    FS.Read(Source, 0, Len);
    FS.Close();

    //Sort Source to Target
    ASorter BWT = new BWT_Medium_Sorter((uint)Len);
    long Idx = BWT.Sort(Source, Target);

    //Write sorted file with BWT index encoded in the file name
    FS = new FileStream($"d:\\Sorted[{Idx}]", FileMode.Create);
    FS.Write(Target, 0, Len);
    FS.Close();
}

See also

BWT_Small_Sorter class

BWT_Medium_Sorter class

BWT_ASorter class

StatisticStep class

Project FastBWT