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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

9.2 Static Arithmetic Coder ( A0sCoder )<br />

1. Definition<br />

An instance C of A0sCoder is a static arithmetic coder of order zero. (We assume that<br />

the reader is familiar with the definition of the class A0Coder from the previous section.)<br />

A0sCoder is called static because it uses a fixed model for encoding. <strong>The</strong> input is scanned<br />

twice. In the first scan the frequencies of the characters are counted. This information is<br />

used to precompute the model. In the second scan the actual coding takes place.<br />

Since the model is fixed the static coder is usually faster than the adaptive coder (despite<br />

the two scans) but the compression rates are often slightly inferior.<br />

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

2. Creation<br />

A0sCoder 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 />

A0sCoder<br />

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

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

3. Operations<br />

Standard Operations<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!