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.25 Block Coder ( BlockCoder )<br />

1. Definition<br />

An instance of type BlockCoder encodes a source stream as follows: It divides<br />

the stream into equally sized blocks and encodes each block seperately with an instance<br />

of type Coder. If you later want to decode only parts of the encoded data then you do<br />

not have to decode the entire data but only the appropriate blocks, which is usually much<br />

faster. (<strong>The</strong> block size can be specified by the user; please note that the main memory of<br />

your computer has to be large enough to hold one block.)<br />

<strong>The</strong> class BlockCoder has been designed to speed up the seek operations of the class<br />

decoding ifstream (see Section 9.22). In order to gain the speed up simply replace<br />

the template parameter Coder in decoding ifstream by BlockCoder (see also the<br />

example below).<br />

<strong>The</strong>re is an important precondition for BlockCoder: In encoding mode the target stream<br />

must support seek operations which query the current position (i.e. seek(0, ios :: cur,<br />

ios :: out)). In decoding mode the source stream must be capable of random seek operations.<br />

<strong>The</strong>se conditions are surely fullfilled if the respective stream is a file. Moreover, if<br />

BlockCoder is used within a coder pipe the pipe will make sure that it operates properly.<br />

However, this configuration only makes sense if all coders in the pipe optimize seek<br />

operations. <strong>The</strong>n the whole pipe will offer fast seek operations.<br />

#include < <strong>LEDA</strong>/coding/block coder.h ><br />

2. Creation<br />

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

bool own streams = false,<br />

uint32 block size = DefaultBlockSize);<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. <strong>The</strong> initial block size is<br />

block size.<br />

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

uint32 block size = DefaultBlockSize);<br />

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

<strong>The</strong> block size is set to block size.

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

Saved successfully!

Ooh no, something went wrong!