bugfix for char '0' in dynhuff.{c,p}
Graham Toal
gtoal at tharr.UUCP
Thu Sep 6 20:48:46 AEST 1990
Archive-name: dynhuff.bug
A few days back I posted a huffman-coding program here; I've since
been playing with it to try modifying the algorithm for delta
compression; while I was doing that I discovered that it only worked
correctly for 1..255; 0 went wrong. Here's a filthy fix -- I've
extended the alphabet by 1, and every time I store what should be a
zero, I store 256 instead. It's a 1-1 mapping, so reverses OK.
The same hack works with both Pascal and C versions.
(Sorry about the diff - must get a real one sometime...)
Diff files 'huff.c' and 'huff2.c'
------------------------------------------------------- top level declarations
change c.huff, line 29 to 29
#define n 256
to
#define n 257 /* 0 doesn't work, so cheat :-) (change 256 to 257) */
------------------------------------------------------ EncodeAndTransmit(int j)
after c.huff line 108:
add c.huff2 line 109:
if (j == 0) j = 256; /* 0 -> 256 */
-------------------------------------------------------- ReceiveAndDecode(void)
change c.huff, line 161 to 161
return(alpha[q]);
to c.huff2, line 163 to 164
i = alpha[q]; if (i == 256) i = 0; /* 256 -> 0 */
return(i);
----------------------------------------------------------------- Update(int k)
after c.huff line 290:
/* Set q to the node whose weight should increase */
add c.huff2 line 294:
if (k == 0) k = 256; /* 0 -> 256 */
-------------------------------------------------------------------------------
More information about the Alt.sources
mailing list