#ifndef _DELTA_ROW_COMPRESSION_H
#define _DELTA_ROW_COMPRESSION_H
#include <Debug.h>
class AbstractDeltaRowCompressor {
public:
AbstractDeltaRowCompressor(int rowSize,
uchar initialSeed);
virtual ~AbstractDeltaRowCompressor();
status_t InitCheck();
void Reset();
int CalculateSize(const uchar* row,
bool updateSeedRow = false);
void Compress(const uchar* row);
protected:
virtual void AppendByteToDeltaRow(uchar byte) = 0;
inline int CurrentDeltaRowSize()
{
return fDeltaRowIndex;
}
private:
inline int DiffersIndex(const uchar* row, int index)
{
while (index < fSize) {
if (fSeedRow[index] != row[index])
return index;
index ++;
}
return -1;
}
inline int DiffersLength(const uchar* row, int index)
{
int startIndex = index;
while (index < fSize) {
if (fSeedRow[index] == row[index])
break;
index ++;
}
return index - startIndex;
}
int CompressRaw(const uchar* row, bool updateSeedRow,
bool updateDeltaRow);
void Put(uchar byte)
{
if (fUpdateDeltaRow)
AppendByteToDeltaRow(byte);
fDeltaRowIndex ++;
}
uchar* fSeedRow;
int fSize;
uchar fInitialSeed;
int fDeltaRowIndex;
bool fUpdateDeltaRow;
};
class DeltaRowCompressor : public AbstractDeltaRowCompressor
{
public:
DeltaRowCompressor(int rowSize, uchar initialSeed)
:
AbstractDeltaRowCompressor(rowSize, initialSeed)
{}
void SetDeltaRow(uchar* deltaRow)
{
fDeltaRow = deltaRow;
}
protected:
virtual void AppendByteToDeltaRow(uchar byte)
{
fDeltaRow[CurrentDeltaRowSize()] = byte;
}
private:
uchar* fDeltaRow;
};
#endif