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.

string C.get description( ) provides a description for C.<br />

Additional Operations<br />

uint32 C.get block size( ) returns the current block size.<br />

void<br />

C.set block size(uint32 block size)<br />

sets the block size.<br />

Coder∗ C.get coder( ) returns the instance of Coder which is actually used<br />

for encoding and decoding.<br />

4. Example<br />

<strong>The</strong> following example shows how BlockCoder can be used to speed up seek operations. We<br />

encode a file of about 3.85 MB, once with A0Coder and once with BlockCoder.<br />

We feed each encoded file into an autodecoding ifstream and perform random seeks. <strong>The</strong><br />

file encoded with BlockCoder is slightly longer but seek operations become much faster.<br />

#include <br />

#include <br />

#include <br />

#include <br />

using namespace <strong>LEDA</strong>;<br />

void test_random_seek(istream& is)<br />

{<br />

const int buffer_sz = 100; char buffer[buffer_sz];<br />

is.seekg(0, ios::end); streamoff size = (streamoff) is.tellg();<br />

// yields the size of the original file<br />

random_source rs;<br />

rs.set_seed(0); rs.set_range(0, size - buffer_sz - 1);<br />

}<br />

timer t("seek"); t.start();<br />

for (int i = 0; i < 100; ++i) {<br />

is.seekg(rs()); is.read(buffer, buffer_sz); // random seek<br />

}<br />

t.stop();<br />

int main()<br />

{<br />

typedef A0Coder Coder;<br />

string in_file = "D:\\ctemp\\bible.txt"; // 3,85MB

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

Saved successfully!

Ooh no, something went wrong!