Ask HN: How would you improve this (C) code?
I've been working on some C code to do video encoding for a while, and I'm curious as to how I might improve it.
I'd be interested to hear what you all think of my Huffman coding implementation, and what I could do to make it better: https://github.com/julian-goldsmith/uChat/blob/master/huffman.c
I'd also welcome any comments on the rest of the code, particularly lzw.c. (The rest is available at https://github.com/julian-goldsmith/uChat .)
5 comments
[ 2.8 ms ] story [ 24.9 ms ] threadAlso, Huffman is fast becoming obsolete with the introduction of ANS.
And that's a nice find on the ANS. I hadn't heard of that before, but will have to look into it.
For ANS info start with this link that leads to a thread by its creator:
https://encode.ru/threads/2078-List-of-Asymmetric-Numeral-Sy...
Other small things you might want to consider is being more consistent with the types. E.g you are using int and unsigned int in places where size_t probably would be better. Using unsigned short for the frequencies array will cause bugs on specially crafted input data.
I think you also should consider what your goal is. If it is speed, then you would develop your code on way, if it is memory efficiency another and, if it is readability of the source code a third.