2018-10-07 03:37:09 +00:00
|
|
|
#pragma once
|
2014-09-09 16:36:29 +00:00
|
|
|
|
2019-08-16 03:51:59 +00:00
|
|
|
#include <cstdint>
|
2014-09-09 16:36:29 +00:00
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
2016-03-04 23:00:12 +00:00
|
|
|
#include <athena/Types.hpp>
|
2014-09-09 16:36:29 +00:00
|
|
|
|
2018-12-08 05:18:17 +00:00
|
|
|
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
|
2019-08-16 03:39:43 +00:00
|
|
|
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); }
|
2014-09-09 16:36:29 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:18:17 +00:00
|
|
|
class LZLookupTable {
|
2014-09-09 16:36:29 +00:00
|
|
|
public:
|
2018-12-08 05:18:17 +00:00
|
|
|
LZLookupTable();
|
|
|
|
LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow = 4096, atInt32 lookAheadWindow = 18);
|
|
|
|
~LZLookupTable();
|
2019-08-16 03:39:43 +00:00
|
|
|
LZLengthOffset search(const atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd);
|
2018-12-08 05:18:17 +00:00
|
|
|
void setLookAheadWindow(atInt32 lookAheadWindow);
|
2015-05-19 03:24:56 +00:00
|
|
|
|
2018-12-08 05:18:17 +00:00
|
|
|
private:
|
2019-08-16 03:47:06 +00:00
|
|
|
using LookupTable = std::multimap<std::vector<uint8_t>, int32_t>;
|
2018-12-08 05:18:17 +00:00
|
|
|
LookupTable table;
|
2019-08-16 03:45:14 +00:00
|
|
|
atInt32 m_minimumMatch = 3;
|
|
|
|
atInt32 m_slidingWindow = 4096;
|
|
|
|
atInt32 m_lookAheadWindow = 18;
|
2018-12-08 05:18:17 +00:00
|
|
|
std::vector<uint8_t> m_buffer;
|
2014-09-09 16:36:29 +00:00
|
|
|
};
|