Giter VIP home page Giter VIP logo

Comments (2)

smx-smx avatar smx-smx commented on May 20, 2024

Hi, thanks for your contribution.
Yes that could be a problem, and i'll refactor the lzhs initialization code to fix it (perhaps a quick&dirty singleton initializer guard).
However i am not sure the lookup table should be moved to struct lzhs_ctx, because the tables are fixed/hardcoded, and the lookup table doesn't depend on the input data.

Let's pick the charlen table for example. A match is obtained by looping (incrementing ctx->i) until

huff_charlen[ctx->i]->len == ctx->len &&
huff_charlen[ctx->i]->code == ctx->code

Which means we're looking for an element (inside huff_charlen, which is the hardcoded table) whose len and code match the ones we are looking for.
The search will always produce the same index, because there can be only 1 element with given len/code, no duplicates allowed.

As such, it shouldn't be necessary to store multiple copies of the same lookup table, because they would be filled with the same data.

Multithreading shouldn't be an issue either, because if thread 1 accesses the lookup table while thread 2 writes an index to it (worst case) it will not find a cached index (value -1), and it will do an extra loop.

Going a step further, one could fill the lookup table ahead of time, by:

  • looping for all elements of the table
  • converting each element (code/len pairs) to lookup keys
  • filling the table with index -> key

As you can see, this process is not dependant on the input data we're decoding. It was done the way i did to build the lookup table lazily, as-needed

from epk2extract.

boom1 avatar boom1 commented on May 20, 2024

Sorry, it was just a guess that the lookup table would depend on the input data. I must admit that I don't understand the huffman algorithm. I thought that this lookup table is the tree of symbols or something.
Thanks for fixing it.

from epk2extract.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.