A C++ STL based implementation of LZW (Lempel–Ziv–Welch) compression algorithm; inspired by the following repos:
- https://github.com/pieroxy/lz-string (author website: http://pieroxy.net/blog/pages/lz-string/index.html)
- https://github.com/jawa-the-hutt/lz-string-csharp
Implemented the following encoder/decoders:
- basic implementation
CompressandDecompress - UTF16
CompressToUTF16andDecompressFromUTF16 - Base64
CompressToBase64andDecompressFromBase64
Not yet implemented:
- encode to/decode from EncodeURIComponent (mainly for JavaScript)
Util functions:
ToWStr: convertstd::stringtostd::wstringToStr: truncted version of string convertion; convertstd::wstringtostd::stringbased onMSDN: If wcstombs_s encounters a wide character it cannot convert to a multibyte character, it puts 0 in *pReturnValue, sets the destination buffer to an empty string, sets errno to EILSEQ, and returns EILSEQ. (wcstombsandwsctombs_salways return error code42, any one knows how to do it correctly?)
Each method provides 2 APIs for different parameters std::string and std::wstring, respectively.
Test case (non-standard / messy version):
The file data.json is used for test purpose; below is the output of local machine (seconds):
[Test Default algorithm]
string length:1161516 compress ratio:23
time elapsed (s): 0.486
checking correctness: [string compressed == decompressed]:1
[Test UTF16]
string length:1161516 compress ratio:21
time elapsed (s): 0.457
checking correctness: [string compressed == decompressed]:1
[Test Base64]
string length:1161516 compress ratio:8
time elapsed (s): 0.468
checking correctness: [string compressed == decompressed]:1