Boundary Package Merge step, numpresent is the amount of leaves, and c is the current chain.*/
| 940 | |
| 941 | /*Boundary Package Merge step, numpresent is the amount of leaves, and c is the current chain.*/ |
| 942 | static void boundaryPM(BPMLists* lists, BPMNode* leaves, size_t numpresent, int c, int num) { |
| 943 | unsigned lastindex = lists->chains1[c]->index; |
| 944 | |
| 945 | if(c == 0) { |
| 946 | if(lastindex >= numpresent) return; |
| 947 | lists->chains0[c] = lists->chains1[c]; |
| 948 | lists->chains1[c] = bpmnode_create(lists, leaves[lastindex].weight, lastindex + 1, 0); |
| 949 | } else { |
| 950 | /*sum of the weights of the head nodes of the previous lookahead chains.*/ |
| 951 | int sum = lists->chains0[c - 1]->weight + lists->chains1[c - 1]->weight; |
| 952 | lists->chains0[c] = lists->chains1[c]; |
| 953 | if(lastindex < numpresent && sum > leaves[lastindex].weight) { |
| 954 | lists->chains1[c] = bpmnode_create(lists, leaves[lastindex].weight, lastindex + 1, lists->chains1[c]->tail); |
| 955 | return; |
| 956 | } |
| 957 | lists->chains1[c] = bpmnode_create(lists, sum, lastindex, lists->chains1[c - 1]); |
| 958 | /*in the end we are only interested in the chain of the last list, so no |
| 959 | need to recurse if we're at the last one (this gives measurable speedup)*/ |
| 960 | if(num + 1 < (int)(2 * numpresent - 2)) { |
| 961 | boundaryPM(lists, leaves, numpresent, c - 1, num); |
| 962 | boundaryPM(lists, leaves, numpresent, c - 1, num); |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequencies, |
| 968 | size_t numcodes, unsigned maxbitlen) { |
no test coverage detected