main.cpp

Example code for using this class.

//============================================================================
// Name        : HuffmanCoder.cpp
// Author      : Ruediger Knoerig
// Version     :
// Copyright   : GPL
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include "HuffmanCoder.h"

using namespace std;
using namespace itpp;

int main() {
        unsigned int data[]={0,1,2,2,3,1,2,2};
        Vec<unsigned int> x(data,8);
        cout << "Input data: " << x << endl;
        HuffmanCoder hcoder(2);
        double mcl = hcoder.train(x);
        cout << "Got a " << (hcoder.isTrained() ? "trained" : "untrained") << " and "
        << (hcoder.isInitialized() ? "initialized" : "uninitialized")
        << " huffman coder with an input range of [0.." << hcoder.getN()-1 << "]." << endl;
        cout << endl << " x\t|\thuffmancode(x)" << endl;
        for(int k=0;k<x.length();k++) cout << x(k) << "\t|\t" << hcoder.code(x(k)) << endl;
        bvec coded = hcoder.code(x);
        Vec<unsigned int> xr=hcoder.decode(coded);
        cout << endl << "Vector x kodiert: " << coded << endl;
        cout << "Mean code length: " << mcl << endl
                << "Code table: " << hcoder.getCodeTable() << endl
                << "Decode table: " << hcoder.getDecodeTable() << endl
                << "Decoded: " << xr << endl
                << ((xr==x) ? "Übereinstimmung mit x" : "Stimmt nicht mit x überein!") << endl;
}

Generated on Mon Feb 9 17:46:23 2009 for Huffman-Coder by  doxygen 1.5.8