123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- // #include "simple/support/debug.hpp"
- #include "simple/compress/lz77.hpp"
- #include "simple/compress/iterator.hpp" // out_bits
- #include "simple/support/iterator.hpp" // offset_expander
- #include <cassert>
- #include <vector>
- #include <string>
- #include <cstdio>
- using namespace simple::compress;
- void Endecode(std::string text)
- // void Endecode(std::vector<unsigned> text)
- {
- std::vector<std::byte> encoded;
- encoded.reserve(text.size());
- lz77_encode(text.begin(), text.end(), out_bits(simple::support::offset_expander(encoded)));
- #if defined SIMPLE_SUPPORT_DEBUG_HPP
- simple::support::print('\n');
- simple::support::print("INPUT SIZE: ", text.size(), '\n');
- simple::support::print("COMPRESSED SIZE: ", encoded.size(), '\n');
- #endif
- std::string decoded;
- // std::vector<unsigned> decoded;
- decoded.resize(text.size());
- lz77_decode(encoded.begin(), decoded.begin(), decoded.end());
- assert(text == decoded);
- }
- int main(int argc, char const* argv[])
- {
- std::string text = "abcd aaaa bbbb cccc aaaa abcd aaaa aaaa aaaa aaaaa aaaa aaaaaaaaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaa";
- // std::vector<unsigned> text(1000);
- if(argc > 1)
- {
- auto f = std::fopen(argv[1], "rb");
- std::fseek(f,0,SEEK_END);
- text.resize(std::ftell(f));
- // text.resize(std::ftell(f) / sizeof(unsigned));
- std::fseek(f,0,SEEK_SET);
- auto unused [[maybe_unused]] = std::fread(text.data(), text.size(), 1 ,f);
- // auto unused [[maybe_unused]] = std::fread(reinterpret_cast<std::byte*>(text.data()), text.size() * sizeof(unsigned), 1 ,f);
- #if defined SIMPLE_SUPPORT_DEBUG_HPP
- simple::support::print("s: ", text.size(), '\n');
- #endif
- }
- Endecode(std::move(text));
- return 0;
- }
|