31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

9.11 Move-To-Front Coder II ( MTF2Coder )<br />

1. Definition<br />

This is a variant of the Move-To-Front coder from the previous section. It was proposed<br />

by Balkenhol and Shtarkov [7] and sometimes yields better compression than MTFCoder<br />

(when used with BWTCoder as preprocessor and A0Coder as postprocessor). <strong>The</strong> idea<br />

is not to exchange the symbol at the head of MTF list L whenever a new symbol is<br />

encountered.<br />

<strong>The</strong> details are as follows: Let us call the position of a symbol c in L the rank of c where<br />

the rank of the head symbol is 0. Whenever a symbol of rank greater than 1 appears we<br />

move it to position 1, i.e. behind the head. When a symbol of rank 1 is encountered it<br />

is moved to position 0 only if the previous symbol was not the head of L. Otherwise it<br />

remains at position 1.<br />

#include < <strong>LEDA</strong>/coding/MTF2.h ><br />

2. Creation<br />

MTF2Coder C(streambuf ∗ src stream = 0, streambuf ∗ tgt stream = 0,<br />

bool own streams = false);<br />

creates an instance C which uses the given source and target<br />

streams. If own streams is set, then C is responsible for the destruction<br />

of the streams, otherwise the pointers src stream and tgt stream<br />

must be valid during the life-time of C.<br />

MTF2Coder C(const char ∗ src file name, const char ∗ tgt file name);<br />

3. Operations<br />

Standard Operations<br />

creates an instance C which uses file-streams for input and output.<br />

void C.encode( ) encodes the source stream and writes the output to<br />

the target stream.<br />

void C.decode( ) decodes the source stream and writes the output to<br />

the target stream.<br />

uint32 C.encode memory chunk(const char ∗ in buf , uint32 in len, char ∗ out buf ,<br />

uint32 out len)<br />

encodes the memory chunk starting at in buf with<br />

size in len into the buffer starting at out buf with size<br />

out len. <strong>The</strong> function returns actual length of the<br />

encoded chunk which may be smaller than out len. If<br />

the output buffer is too small for the encoded data<br />

the failure flag will be set (see below).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!