Octane v1.01.20 - The Open Compression Toolkit for C++ http://octane.sourceforge.net/
Homepage | Main | Modules | Class Hierarchy | Compound List | File List | Compound Members | Related Pages

mtfllCompressor Class Reference
[Compressors]

#include <mtfll.hpp>

Inheritance diagram for mtfllCompressor:

OctaneCompressor OctaneClass List of all members.

Detailed Description

Experimental move to front encoding using a linked list instead of tracing the array.

Move to front moves the recently encoded byte to the front, so when it appears the next time in the input stream it will be encoded with 00. If there comes another byte to the front the previous byte will be moved back by 1 position, so it will be encoded as 01.

Definition at line 25 of file mtfll.hpp.

Public Member Functions

 mtfllCompressor (bool registerme=false)
virtual std::string GetClassName ()
 Get the assigned name of an instantiated compressor.

virtual std::string GetDescription ()
 optionally provide a longer (maybe 20-60 characters) description

virtual OctaneCompressorMakeCompressorInstantiation ()
 Instantiate a compressor from this class (like a factory).


Protected Member Functions

virtual bool DoProtectedCompress (bitreader &s, bitwriter &d)
 This is the member function which does the actual compression, and this is the function that should be subclasses by derived classes.

virtual bool DoProtectedDecompress (bitreader &s, bitwriter &d)
 This is the member function which does the actual decompression, and this is the function that should be subclasses by derived classes.


Member Function Documentation

virtual std::string mtfllCompressor::GetDescription  )  [inline, virtual]
 

optionally provide a longer (maybe 20-60 characters) description

Returns:
a one line description

Reimplemented from OctaneCompressor.

Definition at line 32 of file mtfll.hpp.

00032 {return "Move To Front using linked list";}

bool mtfllCompressor::DoProtectedCompress bitreader s,
bitwriter d
[protected, virtual]
 

This is the member function which does the actual compression, and this is the function that should be subclasses by derived classes.

It is wrapped by the public API call Compress() which performs some measurements on compression speed and streamsize.

Note:
this function should never be called by an outside class - the API interface should be called instead.
Returns:
true on success

Implements OctaneCompressor.

Definition at line 25 of file mtfll.cpp.

References bitreader::empty(), bitreader::get_byte(), and bitwriter::put_byte().

00026 {
00027         unsigned int array[256], pointers[256];
00028 
00029         for (unsigned int i = 0; i < 256; i++) array[i] = pointers[i] = i;
00030 
00031         while (!s.empty())
00032         {
00033                 unsigned char b = s.get_byte();
00034                 d.put_byte((unsigned char)pointers[b]);
00035 
00036                 if (pointers[b])
00037                 {
00038                         for (unsigned char c = (unsigned char)pointers[b]; c; c--)
00039                         {
00040                                 array[c] = array[c-1];
00041                                 pointers[array[c]]++;
00042                         }
00043                         array[0] = b;
00044                         pointers[b] = 0;
00045                 }
00046         }
00047         return true;
00048 }

bool mtfllCompressor::DoProtectedDecompress bitreader s,
bitwriter d
[protected, virtual]
 

This is the member function which does the actual decompression, and this is the function that should be subclasses by derived classes.

It is wrapped by the public API call Decompress() which performs some measurements on decompression speed and streamsize.

Note:
this function should never be called by an outside class - the API interface should be called instead.
Returns:
true on success

Implements OctaneCompressor.

Definition at line 50 of file mtfll.cpp.

References bitreader::empty(), bitreader::get_byte(), and bitwriter::put_byte().

00051 {
00052         unsigned int array[256], pointers[256];
00053 
00054         for (unsigned int i = 0; i < 256; i++) array[i] = pointers[i] = i;
00055 
00056         while (!s.empty())
00057         {
00058                 unsigned char b = (unsigned char)array[s.get_byte()];
00059                 d.put_byte(b);
00060 
00061                 if (pointers[b])
00062                 {
00063                         for (unsigned char c = (unsigned char)pointers[b]; c; c--)
00064                         {
00065                                 array[c] = array[c-1];
00066                                 pointers[array[c]]++;
00067                         }
00068                         array[0] = b;
00069                         pointers[b] = 0;
00070                 }
00071         }
00072         return true;
00073 }


The documentation for this class was generated from the following files:  
Generated on 20 May 2004 by doxygen 1.3.3