X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Fcoders%2Fhuffman_codes.h;fp=src%2Fcoders%2Fhuffman_codes.h;h=7538225ce562d595c595e2bee94933850a2df9fe;hb=3fd4bcef236556c7f3bff1d2be8d3f4206245501;hp=0000000000000000000000000000000000000000;hpb=dc7a566a39187bfcea70737cda7278f858cd9842;p=SXSI%2Flibcds.git diff --git a/src/coders/huffman_codes.h b/src/coders/huffman_codes.h new file mode 100644 index 0000000..7538225 --- /dev/null +++ b/src/coders/huffman_codes.h @@ -0,0 +1,63 @@ +/* huffman_codes.h + Copyright (C) 2008, Francisco Claude, all rights reserved. + + Wrapper for huff written by Gonzalo Navarro + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#ifndef HUFFMAN_CODES_H +#define HUFFMAN_CODES_H + +#include +#include + +/** Wrapper for the canonical huffman implementation of Gonzalo Navarro. + * + * @author Francisco Claude + */ +class huffman_codes { + + public: + /** Creates the codes for the sequence seq of length n */ + huffman_codes(uint * seq, uint n); + huffman_codes(uchar * seq, uint n); + ~huffman_codes(); + + /** Encodes symb into stream at bit-position pos, return the ending position (bits) */ + ulong encode(uint symb, uint * stream, ulong pos); + + /** decodes into symb from stream at bit-position pos, returns the new position */ + ulong decode(uint * symb, uint * stream, ulong pos); + + /** Returns the maximum length of a code */ + uint max_length(); + + /** Returns the size of the table */ + uint size(); + + /** Saves the coder to a file */ + uint save(FILE *fp); + + /** Loads a coder from a file */ + static huffman_codes * load(FILE *fp); + + protected: + huffman_codes(); + THuff huff_table; +}; + +#endif