Merge pull request #48 from lioncash/lz

LZBase/LZLookupTable: Minor cleanup
This commit is contained in:
2019-08-16 18:18:14 -07:00
committed by GitHub
4 changed files with 113 additions and 123 deletions

View File

@@ -1,35 +1,29 @@
#pragma once
#include <string>
#include "LZ77/LZLookupTable.hpp"
class LZBase {
public:
explicit LZBase(atInt32 minimumOffset = 1, atInt32 slidingWindow = 4096, atInt32 minimumMatch = 3,
atInt32 blockSize = 8);
virtual ~LZBase() {}
virtual ~LZBase();
virtual atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
virtual atUint32 decompress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
void setSlidingWindow(atInt32 SlidingWindow);
atInt32 slidingWindow();
atInt32 slidingWindow() const;
void setReadAheadBuffer(atInt32 ReadAheadBuffer);
atInt32 readAheadBuffer();
atInt32 readAheadBuffer() const;
void setMinMatch(atInt32 minimumMatch);
atInt32 minMatch();
atInt32 minMatch() const;
void setBlockSize(atInt32 BlockSize);
atInt32 blockSize();
atInt32 blockSize() const;
void setMinimumOffset(atUint32 minimumOffset);
atUint32 minimumOffset();
private:
atInt32 subMatch(const atUint8* str1, const uint8_t* str2, const atInt32 len);
LZLengthOffset windowSearch(atUint8* beginSearchPtr, atUint8* searchPosPtr, atUint8* endLABufferPtr,
atUint8* startLBPtr);
atUint32 minimumOffset() const;
protected:
LZLengthOffset search(atUint8* posPtr, atUint8* dataBegin, atUint8* dataEnd);
LZLengthOffset search(const atUint8* posPtr, const atUint8* dataBegin, const atUint8* dataEnd) const;
atInt32 m_slidingWindow;
atInt32 m_readAheadBuffer;

View File

@@ -1,15 +1,15 @@
#pragma once
#include <map>
#include <deque>
#include <vector>
#include <cstdint>
#include <map>
#include <vector>
#include <athena/Types.hpp>
struct LZLengthOffset {
atUint32 length; // The number of bytes compressed
atUint16 offset; // How far back in sliding window where bytes that match the lookAheadBuffer is located
bool compare_equal(const LZLengthOffset& lo_pair) { return length == lo_pair.length && offset == lo_pair.offset; }
bool operator==(const LZLengthOffset& lo_pair) const { return length == lo_pair.length && offset == lo_pair.offset; }
bool operator!=(const LZLengthOffset& lo_pair) const { return !operator==(lo_pair); }
};
class LZLookupTable {
@@ -17,14 +17,14 @@ public:
LZLookupTable();
LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow = 4096, atInt32 lookAheadWindow = 18);
~LZLookupTable();
LZLengthOffset search(atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd);
LZLengthOffset search(const atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd);
void setLookAheadWindow(atInt32 lookAheadWindow);
private:
typedef std::multimap<std::vector<uint8_t>, int32_t> LookupTable;
using LookupTable = std::multimap<std::vector<uint8_t>, int32_t>;
LookupTable table;
atInt32 m_minimumMatch;
atInt32 m_slidingWindow;
atInt32 m_lookAheadWindow;
atInt32 m_minimumMatch = 3;
atInt32 m_slidingWindow = 4096;
atInt32 m_lookAheadWindow = 18;
std::vector<uint8_t> m_buffer;
};