next up previous contents index
Next: RLE for Runs of Up: Lossless Compression Previous: Move-To-Front Coder ( MTFCoder   Contents   Index


Move-To-Front Coder II ( MTF2Coder )

Definition

This is a variant of the Move-To-Front coder from the previous section. It was proposed by Balkenhol and Shtarkov [7] and sometimes yields better compression than MTFCoder (when used with BWTCoder as preprocessor and A0Coder as postprocessor). The idea is not to exchange the symbol at the head of MTF list L whenever a new symbol is encountered.
The details are as follows: Let us call the position of a symbol c in L the rank of c where the rank of the head symbol is 0. Whenever a symbol of rank greater than 1 appears we move it to position 1, i.e. behind the head. When a symbol of rank 1 is encountered it is moved to position 0 only if the previous symbol was not the head of L. Otherwise it remains at position 1.

#include < LEDA/coding/MTF2.h >

Creation

MTF2Coder C(streambuf* src_stream = 0, streambuf* tgt_stream = 0, bool own_streams = false)
    creates an instance C which uses the given source and target streams. If own_streams is set, then C is responsible for the destruction of the streams, otherwise the pointers src_stream and tgt_stream must be valid during the life-time of C.

MTF2Coder C(const char* src_file_name, const char* tgt_file_name)
    creates an instance C which uses file-streams for input and output.

Operations

Standard Operations

void C.encode() encodes the source stream and writes the output to the target stream.

void C.decode() decodes the source stream and writes the output to the target stream.

uint32 C.encode_memory_chunk(const char* in_buf, uint32 in_len, char* out_buf, uint32 out_len)
    encodes the memory chunk starting at in_buf with size in_len into the buffer starting at out_buf with size out_len. The function returns actual length of the encoded chunk which may be smaller than out_len. If the output buffer is too small for the encoded data the failure flag will be set (see below).

uint32 C.decode_memory_chunk(const char* in_buf, uint32 in_len, char* out_buf, uint32 out_len)
    decodes a memory chunk. The meaning of the parameters and the return value is the same as in the previous function.

streambuf* C.get_src_stream() returns the current source stream.

void C.set_src_stream(streambuf* src_stream, bool own_stream = false)
    sets the source stream (cf. constructor).

void C.set_src_file(const char* file_name)
    sets a file as source stream.

streambuf* C.get_tgt_stream() returns the current target stream.

void C.set_tgt_stream(streambuf* tgt_stream, bool own_Stream = false)
    sets the target stream (cf. constructor).

void C.set_tgt_file(const char* file_name)
    sets a file as target stream.

void C.reset() puts C in exactly the same state as the default constructor.

bool C.failed() returns true if an error occured.

bool C.finished() returns true if the coding is finished.

string C.get_description() provides a description for C.


next up previous contents index
Next: RLE for Runs of Up: Lossless Compression Previous: Move-To-Front Coder ( MTFCoder   Contents   Index