41 while (root * 2 + 1 < size) {
42 int child = root * 2 + 1;
43 if (child < size - 1 && h[child].
val > h[child+1].
val)
45 if (h[root].
val > h[child].
val) {
61 for (offset = 1; ; offset <<= 1) {
62 for (i=0; i <
size; i++) {
64 h[i].
val = (stats[i] << 8) + offset;
66 for (i = size / 2 - 1; i >= 0; i--)
69 for (next = size; next < size * 2 - 1; next++) {
71 uint64_t min1v = h[0].
val;
81 len[2 * size - 2] = 0;
82 for (i = 2 * size - 3; i >=
size; i--)
83 len[i] = len[up[i]] + 1;
84 for (i = 0; i <
size; i++) {
85 dst[i] = len[up[i]] + 1;
86 if (dst[i] >= 32)
break;
93 Node *nodes,
int node,
94 uint32_t pfx,
int pl,
int *pos,
int no_zero_count)
99 if (s !=
HNODE || (no_zero_count && !nodes[node].
count)) {
110 get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0 + 1, pfx, pl,
124 &pos, no_zero_count);
125 return ff_init_vlc_sparse(vlc,
FF_HUFFMAN_BITS, pos, lens, 2, 2, bits, 4, 4, xlat, 1, 1, 0);
140 for (i = 0; i < nb_codes; i++) {
143 sum += nodes[i].
count;
148 "Too high symbol frequencies. "
149 "Tree construction is not possible\n");
152 qsort(nodes, nb_codes,
sizeof(
Node), cmp);
154 nodes[nb_codes*2-1].
count = 0;
155 for (i = 0; i < nb_codes * 2 - 1; i += 2) {
156 uint32_t cur_count = nodes[i].
count + nodes[i+1].
count;
159 for(j = cur_node; j > i + 2; j--){
160 if(cur_count > nodes[j-1].
count ||
161 (cur_count == nodes[j-1].
count &&
164 nodes[j] = nodes[j - 1];
167 nodes[j].
count = cur_count;