#pragma once #include #include #include #include namespace lzokay { enum class EResult { LookbehindOverrun = -4, OutputOverrun = -3, InputOverrun = -2, Error = -1, Success = 0, InputNotConsumed = 1, }; class DictBase { protected: static constexpr uint32_t HashSize = 0x4000; static constexpr uint32_t MaxDist = 0xbfff; static constexpr uint32_t MaxMatchLen = 0x800; static constexpr uint32_t BufSize = MaxDist + MaxMatchLen; /* List encoding of previous 3-byte data matches */ struct Match3 { std::array head; /* key -> chain-head-pos */ std::array chain_sz; /* key -> chain-size */ std::array chain; /* chain-pos -> next-chain-pos */ std::array best_len; /* chain-pos -> best-match-length */ }; /* Encoding of 2-byte data matches */ struct Match2 { std::array head; /* 2-byte-data -> head-pos */ }; struct Data { Match3 match3; Match2 match2; /* Circular buffer caching enough data to access the maximum lookback * distance of 48K + maximum match length of 2K. An additional 2K is * allocated so the start of the buffer may be replicated at the end, * therefore providing efficient circular access. */ std::array buffer; }; using storage_type = Data; storage_type* _storage; DictBase() = default; friend struct State; friend EResult compress(const uint8_t* src, std::size_t src_size, uint8_t* dst, std::size_t& dst_size, DictBase& dict); }; template