+/* 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 <huff.h>
*/
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)
}
return H;
}
-
-