Meshbeyn / Projects

Namespace FastBWT

public abstract void ASorter.GenerateVector

This method generates the sorting vector for source bytes.

Syntax

public abstract void GenerateVector(
    byte[] SourceBlock,
    ICollection Index,
    long DataSize = 0
)

Parameters

byte[] SourceBlock

Array with source bytes.

ICollection Index

Array for sorting vector. The type of this array depends on concrete sorter. Read the documentation of concrete sorter.

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.

Exceptions

IndexOutOfRangeException

This exception is thrown if DataSize is too big or if the Index 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 another sorter.

Remarks

This method performs the actual BWT sorting. Its result is the Sorting Vector, that will be applied later to SourceBlock to calculate sorted bytes. Consider to use this method with the method FillSortedBlock to sort multiple blocks. You may reuse Sorting Vector for sorting the next block. Method Sort creates and clears the sorting vector during each invocation.

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

Example

static void SortPages(byte[][] Source, byte[][] Target, int[] Idx)
{
    uint BlockSize = (uint)Source[0].Length;
    ASorter BWT = new BWT_Medium_Sorter(BlockSize);
    //Sorting vector
    uint[] Vector = new uint[BlockSize];
    //Variable for target blocks
    byte[] Res = new byte[BlockSize];
    for (int i = 0; i < Source.Length; i++)
    {
        BWT.GenerateVector(Source[i], Vector);
        Idx[i] = (int)ASorter.FillSortedBlock(Source[i], Res, Vector);
        Target[i] = Res;
        //Take source block for the next target
        Res = Source[i];
        Source[i] = null;
    }
}

This example sorts a collection of pages (same-sized blocks). It reuses arrays from Source collection for target blocks (usually you don't need source block after sorting). After you call this method, Source array has nulls as its members, and the corresponding elements of Target and Ids have sorted blocks and indices. You may use this method like that:

byte[][] Source = GetSourceBlocks();
byte[][] Target = new byte[Source.Length][];
int[] Idx = new int[Source.Length];
SortPages(Source, Target, Idx);

See also

ASorter.FillSortedBlock method

ASorter class

BWT_Small_Sorter class

BWT_Medium_Sorter class

ADesorter class

StatisticStep class

Project FastBWT