// Huffman code compression/decompression.

#ifndef HUFFMAN_CODEC_H
#define HUFFMAN_CODEC_H

#include <iostream>
#include <vector>
#include <string>

/*************************************************************

 Huffman coding class

 Provides the encode and decode functions.
							     
 *************************************************************/

#include "binary_tree.h"

class huffman_codec
{
 public:

  huffman_codec() {}
  void encode(std::istream &, std::ostream &);
  void decode(std::istream &, std::ostream &);

 private:

  // Node_type is pair of int and unsigned char
  // The unsigned char is the character that the node represents
  // The int is the frequency of the character in the plaintext
  typedef std::pair<int, unsigned char> node_type;

  // Our tree type is a binary tree with the node type 
  // Defined above
  typedef binary_tree<node_type> tree_type;
  
  // Encoding tree is the actual tree that we used to 
  // Generate the encodings.
  tree_type * encoding_tree;

  // Character count is counter for each of the 256 characters.
  int character_count[256];

  // Character encoding is an array of 256 encodings.
  // Each encoding string of 1's and 0's.
  std::basic_string<bool> character_encoding[256];
};

#endif
