MCPcopy Create free account
hub / github.com/DFHack/dfhack / HuffmanTree_makeFromFrequencies

Function HuffmanTree_makeFromFrequencies

depends/lodepng/lodepng.cpp:1046–1058  ·  view source on GitHub ↗

Create the Huffman tree given the symbol frequencies*/

Source from the content-addressed store, hash-verified

1044
1045/*Create the Huffman tree given the symbol frequencies*/
1046static unsigned HuffmanTree_makeFromFrequencies(HuffmanTree* tree, const unsigned* frequencies,
1047 size_t mincodes, size_t numcodes, unsigned maxbitlen) {
1048 unsigned error = 0;
1049 while(!frequencies[numcodes - 1] && numcodes > mincodes) --numcodes; /*trim zeroes*/
1050 tree->lengths = (unsigned*)lodepng_malloc(numcodes * sizeof(unsigned));
1051 if(!tree->lengths) return 83; /*alloc fail*/
1052 tree->maxbitlen = maxbitlen;
1053 tree->numcodes = (unsigned)numcodes; /*number of symbols*/
1054
1055 error = lodepng_huffman_code_lengths(tree->lengths, frequencies, numcodes, maxbitlen);
1056 if(!error) error = HuffmanTree_makeFromLengths2(tree);
1057 return error;
1058}
1059#endif /*LODEPNG_COMPILE_ENCODER*/
1060
1061/*get the literal and length code tree of a deflated block with fixed tree, as per the deflate specification*/

Callers 1

deflateDynamicFunction · 0.85

Calls 3

lodepng_mallocFunction · 0.85

Tested by

no test coverage detected