Octane v1.01.20 - The Open Compression Toolkit for C++ | http://octane.sourceforge.net/ |
#include <mtfll.hpp>
Inheritance diagram for mtfllCompressor:
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 OctaneCompressor * | MakeCompressorInstantiation () |
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. |
|
optionally provide a longer (maybe 20-60 characters) description
Reimplemented from OctaneCompressor. Definition at line 32 of file mtfll.hpp.
00032 {return "Move To Front using linked list";} |
|
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.
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 } |
|
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.
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 } |