123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include "simple/compress/lz77.hpp"
- #include "simple/compress/iterator.hpp"
- #include "simple/support/iterator.hpp"
- #include <cassert>
- #include <vector>
- #include <string>
- #include <cstdio>
- using namespace simple::compress;
- void Endecode(std::string 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;
-
- 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";
-
- if(argc > 1)
- {
- auto f = std::fopen(argv[1], "rb");
- std::fseek(f,0,SEEK_END);
- text.resize(std::ftell(f));
-
- std::fseek(f,0,SEEK_SET);
- auto unused [[maybe_unused]] = std::fread(text.data(), text.size(), 1 ,f);
-
- #if defined SIMPLE_SUPPORT_DEBUG_HPP
- simple::support::print("s: ", text.size(), '\n');
- #endif
- }
- Endecode(std::move(text));
- return 0;
- }
|