huffman_encode

Functions

int main(int argc, char *argv[])

huffman_encode cbfile [ infile ]

  • cbfile str

    • ascii codebook

  • infile str

    • int-type symbol sequence

  • stdout

    • bool-type codeword sequence

The below example encodes data.i and decodes it.

huffman_encode cbfile < data.i | huffman_decode cbfile > data.i2
# data.i and data.i2 should be identical
Parameters:
  • argc[in] Number of arguments.

  • argv[in] Argument vector.

Returns:

0 on success, 1 on failure.

class HuffmanEncoding

Encode symbols to binary sequence.

The input is a symbol and the output is the corresponding codeword.

Public Functions

explicit HuffmanEncoding(std::ifstream *input_stream)
Parameters:

input_stream[in] Stream which contains codebook.

inline bool IsValid() const
Returns:

True if this object is valid.

bool Run(int input, std::vector<bool> *output) const
Parameters:
  • input[in] Symbol.

  • output[out] Codeword.

Returns:

True on success, false on failure.