home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1784 < prev    next >
Internet Message Format  |  1990-12-28  |  2KB

  1. From: gtoal@tharr.UUCP (Graham Toal)
  2. Newsgroups: alt.sources,alt.sources.d
  3. Subject: bugfix for char '0' in dynhuff.{c,p}
  4. Message-ID: <956@tharr.UUCP>
  5. Date: 6 Sep 90 10:48:46 GMT
  6.  
  7. Archive-name: dynhuff.bug
  8.  
  9. A few days back I posted a huffman-coding program here; I've since
  10. been playing with it to try modifying the algorithm for delta
  11. compression; while I was doing that I discovered that it only worked
  12. correctly for 1..255; 0 went wrong.  Here's a filthy fix -- I've
  13. extended the alphabet by 1, and every time I store what should be a
  14. zero, I store 256 instead.  It's a 1-1 mapping, so reverses OK.
  15.  
  16. The same hack works with both Pascal and C versions.
  17.  
  18. (Sorry about the diff - must get a real one sometime...)
  19.  
  20. Diff files 'huff.c' and 'huff2.c'
  21. ------------------------------------------------------- top level declarations
  22. change c.huff, line 29 to 29
  23. #define  n  256
  24. to
  25. #define  n  257        /* 0 doesn't work, so cheat :-) (change 256 to 257) */
  26. ------------------------------------------------------ EncodeAndTransmit(int j)
  27. after c.huff line  108: 
  28. add c.huff2 line  109:
  29.    if (j == 0) j = 256;                           /* 0 -> 256 */
  30. -------------------------------------------------------- ReceiveAndDecode(void)
  31. change c.huff, line 161 to 161
  32.    return(alpha[q]);
  33. to c.huff2, line 163 to 164
  34.    i = alpha[q]; if (i == 256) i = 0;             /* 256 -> 0 */
  35.    return(i);
  36. ----------------------------------------------------------------- Update(int k)
  37. after c.huff line  290:
  38.    /* Set q to the node whose weight should increase */
  39. add c.huff2 line  294:
  40.    if (k == 0) k = 256;                           /* 0 -> 256 */
  41. -------------------------------------------------------------------------------
  42.