X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=libcds%2Fsrc%2Fcoders%2Fhuff.cpp;h=52b95f9e88a8facbfa60df7e39b3c44ee0d36c8a;hb=a9846746dc7a55764591fcc273fd48c6049df962;hp=deb0e70cffd843a9264380eebafca00fda89dd1e;hpb=efe894650813a19a0e1408eb5807e59f037afc3b;p=SXSI%2FXMLTree.git diff --git a/libcds/src/coders/huff.cpp b/libcds/src/coders/huff.cpp index deb0e70..52b95f9 100644 --- a/libcds/src/coders/huff.cpp +++ b/libcds/src/coders/huff.cpp @@ -1,4 +1,23 @@ +/* huff.cpp + Copyright (C) 2008, Gonzalo Navarro, all rights reserved. + Canonical Huffman + + 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 + +*/ // implements canonical Huffman #include @@ -180,16 +199,17 @@ ulong decodeHuff (THuff H, uint *symb, uint *stream, ulong ptr) */ void saveHuff (THuff H, FILE *f) - { uint *symb = (uint*)malloc((H.lim+1)*sizeof(uint)); + { uint *symb = new uint[H.lim+1]; uint i; + for(i=0;i<(H.lim+1);i++) symb[i] = 0; for (i=0;i<=H.max;i++) - if (H.s.spos[i] != (uint)~0) symb[H.s.spos[i]] = i; + if (H.s.spos[i] != (uint)~0) symb[H.s.spos[i]] = i; uint l=fwrite (&H.max,sizeof(uint),1,f); l += fwrite (&H.lim,sizeof(uint),1,f); l += fwrite (&H.depth,sizeof(uint),1,f); l += fwrite (symb,sizeof(uint),H.lim+1,f); l += fwrite (H.num,sizeof(uint),H.depth+1,f); - free (symb); + delete [] (symb); } uint sizeHuff (THuff H) @@ -235,5 +255,3 @@ THuff loadHuff (FILE *f, int enc) } return H; } - -