2 #include <huffman_codes.h>
4 huffman_codes::huffman_codes(uint * symb, uint n) {
7 max_v = max(max_v,symb[i]);
8 uint * occ = new uint[max_v+1];
9 for(uint i=0;i<max_v+1;i++)
13 huff_table = createHuff(occ, max_v);
17 huffman_codes::huffman_codes() {
20 huffman_codes::~huffman_codes() {
24 uint huffman_codes::max_length() {
25 return huff_table.depth;
28 uint huffman_codes::size() {
29 return sizeof(huffman_codes)+sizeHuff(huff_table);
32 ulong huffman_codes::encode(uint symb, uint * stream, ulong pos) {
33 return encodeHuff(huff_table, symb, stream, pos);
36 ulong huffman_codes::decode(uint * symb, uint * stream, ulong pos) {
37 return decodeHuff(huff_table, symb, stream, pos);
40 uint huffman_codes::save(FILE *fp) {
41 saveHuff(huff_table,fp);
45 huffman_codes * huffman_codes::load(FILE * fp) {
46 huffman_codes * ret = new huffman_codes();
47 ret->huff_table = loadHuff(fp,1);