43 while (root * 2 + 1 < size) {
44 int child = root * 2 + 1;
45 if (child < size - 1 && h[child].val > h[child+1].val)
47 if (h[root].val > h[child].val) {
63 for (offset = 1; ; offset <<= 1) {
64 for (i=0; i <
size; i++) {
66 h[i].
val = (stats[i] << 8) + offset;
68 for (i = size / 2 - 1; i >= 0; i--)
71 for (next = size; next < size * 2 - 1; next++) {
73 uint64_t min1v = h[0].
val;
83 len[2 * size - 2] = 0;
84 for (i = 2 * size - 3; i >=
size; i--)
85 len[i] = len[up[i]] + 1;
86 for (i = 0; i <
size; i++) {
87 dst[i] = len[up[i]] + 1;
88 if (dst[i] >= 32)
break;
95 Node *nodes,
int node,
96 uint32_t pfx,
int pl,
int *pos,
int no_zero_count)
101 if (s !=
HNODE || (no_zero_count && !nodes[node].count)) {
112 get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0 + 1, pfx, pl,
126 &pos, no_zero_count);
127 return ff_init_vlc_sparse(vlc, 9, pos, lens, 2, 2, bits, 4, 4, xlat, 1, 1, 0);
142 for (i = 0; i < nb_codes; i++) {
145 sum += nodes[i].
count;
150 "Too high symbol frequencies. "
151 "Tree construction is not possible\n");
154 qsort(nodes, nb_codes,
sizeof(
Node), cmp);
156 nodes[nb_codes*2-1].
count = 0;
157 for (i = 0; i < nb_codes * 2 - 1; i += 2) {
160 nodes[cur_node].
n0 = i;
161 for (j = cur_node; j > 0; j--) {
162 if (nodes[j].count > nodes[j - 1].count ||
163 (nodes[j].count == nodes[j - 1].count &&
165 nodes[j].n0 == j - 1 || nodes[j].n0 == j - 2 ||
166 (nodes[j].sym!=
HNODE && nodes[j-1].sym!=
HNODE))))