Compression: Adapthuff Buggy: Help!

Discussion in 'Software' started by HarryPotter, May 7, 2024.

  1. HarryPotter

    HarryPotter MajorGeek

    Hi! I've been working on file compression for years. Recently, I thought I made a breakthrough but then realized that my rendition of Adaptive Huffman codes is very buggy: starting at the first byte compressed with AdaptHuff, the whole file is corrupt. :( I attached some example code in the hopes that somebody here can find the bug(s). Any help would be appreciated.
     

    Attached Files:

  2. Maxwell

    Maxwell Folgers

    In comp huffman.c.txt:

    The code you've provided appears to be an implementation of **Adaptive Huffman coding**. While I don't see any glaring syntax errors, there are a few points to consider:
    1. **Initialization of `HuffEnv`**:
    - The `InitHuffTree` function initializes the `HuffEnv` structure. However, it seems that the variable `tmpcptr` is used without being declared or defined. You might want to ensure that `tmpcptr` is properly declared and initialized before using it in the loop.
    2. **Bit Manipulation**:
    - In the `WriteB2` function, the line `d=(d<<1)|e2->bit;` performs a bitwise left shift (`<<`) followed by a bitwise OR (`|`). This operation is commonly used for bit manipulation, but it's essential to understand its purpose in the context of Huffman coding.
    - Make sure that the `writeoutf` function (which is not defined in the provided code snippet) correctly handles the compressed data.
    3. **Boundary Conditions**:
    - The `GetHuffGreatestInBlock` function searches for the highest node with the current node's weight. However, the loop condition `tmpcptr>=c` might need further validation to ensure it doesn't go out of bounds.
    - Similarly, in the `UpdateHuffCode` function, the condition `if (n>=512)` should be carefully reviewed to avoid accessing invalid memory locations.
    4. **Missing Definitions**:
    - Some functions, such as `writeoutf`, are referenced but not defined in the snippet. You'll need to provide their implementations or replace them with appropriate I/O operations.
    5. **Overall Context**:
    - Without the complete context (including the missing parts of the code), it's challenging to identify any other potential issues or bugs.
    Remember to verify the missing parts of the code, ensure proper initialization, and test the implementation thoroughly.
     
  3. HarryPotter

    HarryPotter MajorGeek

    Everything you say seems to check out. When I get the first hit that is not a NYT, the wrong byte appears: one that appeared before but the wrong one. After that, the whole file is corrupt. :( I'm thinking I'm not writing the bits properly. Maybe I'm not updating the tree properly. Can you give me an URL to information on AdaptHuff that's better than Wikipedia's article? It's a little confusing.
     
  4. Maxwell

    Maxwell Folgers

  5. HarryPotter

    HarryPotter MajorGeek

    I downloaded the second link you provided and plan to look at it later. Thank you. BTW, I think my main problem is that I'm not swapping the right values when updating the tree. What values do I need to swap?
     
  6. HarryPotter

    HarryPotter MajorGeek

    Maybe I'm using different values for the bits compressed and decompressed. How do I handle specifying the right bits between the compressor and the decompressor?
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds