LZW Compressor
|
LZW file compressor. More...
#include <algorithm>
#include <array>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <exception>
#include <fstream>
#include <ios>
#include <iostream>
#include <istream>
#include <limits>
#include <memory>
#include <ostream>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
Go to the source code of this file.
Classes | |
class | EncoderDictionary |
Encoder's custom dictionary type. More... | |
struct | EncoderDictionary::Node |
Binary search tree node. More... | |
struct | ByteCache |
Helper structure for use in CodeWriter and CodeReader . More... | |
class | CodeWriter |
Variable binary width code writer. More... | |
class | CodeReader |
Variable binary width code reader. More... | |
Typedefs | |
using | CodeType = std::uint32_t |
Type used to store and retrieve codes. | |
Enumerations | |
enum | MetaCode : CodeType { Eof = 1u << CHAR_BIT } |
Special codes used by the encoder to control the decoder. More... | |
Functions | |
std::size_t | required_bits (unsigned long int n) |
Computes the minimum number of bits required to store the value of n . More... | |
void | compress (std::istream &is, std::ostream &os) |
Compresses the contents of is and writes the result to os . More... | |
void | decompress (std::istream &is, std::ostream &os) |
Decompresses the contents of is and writes the result to os . More... | |
void | print_usage (const std::string &s="", bool su=true) |
Prints usage information and a custom error message. More... | |
int | main (int argc, char *argv[]) |
Actual program entry point. More... | |
Variables | |
const CodeType | globals::dms {512 * 1024} |
Dictionary Maximum Size (when reached, the dictionary will be reset) | |
LZW file compressor.
This is the C++11 implementation of a Lempel-Ziv-Welch single-file command-line compressor. It was written with Doxygen comments.
Definition in file lzw_v6.cpp.
Special codes used by the encoder to control the decoder.
Enumerator | |
---|---|
Eof |
End-of-file. |
Definition at line 59 of file lzw_v6.cpp.
void compress | ( | std::istream & | is, |
std::ostream & | os | ||
) |
Compresses the contents of is
and writes the result to os
.
[in] | is | input stream |
[out] | os | output stream |
Definition at line 449 of file lzw_v6.cpp.
References CodeWriter::get_bits(), CodeWriter::increase_bits(), required_bits(), EncoderDictionary::reset(), CodeWriter::reset_bits(), EncoderDictionary::search_and_insert(), EncoderDictionary::search_initials(), EncoderDictionary::size(), and CodeWriter::write().
Referenced by main().
void decompress | ( | std::istream & | is, |
std::ostream & | os | ||
) |
Decompresses the contents of is
and writes the result to os
.
[in] | is | input stream |
[out] | os | output stream |
Definition at line 493 of file lzw_v6.cpp.
Referenced by main().
int main | ( | int | argc, |
char * | argv[] | ||
) |
Actual program entry point.
argc | number of command line arguments | |
[in] | argv | array of command line arguments |
EXIT_FAILURE | for failed operation |
EXIT_SUCCESS | for successful operation |
Definition at line 608 of file lzw_v6.cpp.
References compress(), decompress(), and print_usage().
void print_usage | ( | const std::string & | s = "" , |
bool | su = true |
||
) |
Prints usage information and a custom error message.
s | custom error message to be printed |
su | Show Usage information |
Definition at line 582 of file lzw_v6.cpp.
Referenced by main().
std::size_t required_bits | ( | unsigned long int | n | ) |
Computes the minimum number of bits required to store the value of n
.
n | number to be evaluated |
Definition at line 434 of file lzw_v6.cpp.
Referenced by compress().