35 int expected_length,
const uint8_t expected_len_counts[])
38 uint8_t len_counts[17];
39 int actual_length = 0,
i;
44 for (
i = 0;
i < nprobs;
i++) {
51 unsigned code = 0, count = 0;
52 for (
int i = 1;
i <=
L; ++
i) {
53 count += len_counts[
i];
55 code += len_counts[
i];
58 fprintf(stderr,
"Huffman tree overdetermined/invalid\n");
61 if (count != nprobs) {
62 fprintf(stderr,
"Total count %u does not match expected value %d\n",
67 for (
unsigned i = 0;
i < count; ++
i) {
68 if (val_counts[
i].
prob != probs[val_counts[
i].
value]) {
69 fprintf(stderr,
"PTable not properly reordered\n");
72 if (
i && val_counts[
i - 1].
prob > val_counts[
i].
prob) {
73 fprintf(stderr,
"PTable not order ascendingly: [%u] = %d > [%u] = %d\n",
78 for (j = 0; j < count; ++j)
79 if (val_counts[j].
value ==
i)
82 fprintf(stderr,
"Element %u missing after sorting\n",
i);
88 for (
int end = j + len_counts[
len]; j < end; ++j)
93 if (actual_length != expected_length)
ret = 1;
98 "Expected length: %d\n",
99 actual_length, expected_length);
109 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,
113 2, 0, 0, 0, 0, 1, 0, 0, 20, 0, 2, 0, 10, 5, 1, 1, 9, 1, 1, 6, 0, 5, 0, 1, 0, 7, 6,
114 1, 1, 5, 0, 0, 0, 0, 11, 0, 0, 0, 51, 1, 0, 20, 0, 1, 0, 0, 0, 0, 6, 106, 1, 0, 1,
115 0, 2, 1, 16, 0, 0, 5, 0, 0, 0, 4, 3, 15, 4, 4, 0, 0, 0, 3, 0, 0, 1, 0, 3, 0, 3, 2,
116 2, 0, 0, 4, 3, 40, 1, 2, 0, 22, 0, 0, 0, 9, 0, 0, 0, 0, 1, 1, 0, 1, 6, 11, 4, 10,
117 28, 6, 1, 0, 0, 9, 9, 4, 0, 0, 0, 0, 8, 33844, 2, 0, 2, 1, 1, 5, 0, 0, 1, 9, 1, 0,
118 4, 14, 4, 0, 0, 3, 8, 0, 51, 9, 6, 1, 1, 2, 2, 3, 1, 5, 5, 29, 0, 0, 0, 0, 14, 29,
119 6, 4, 13, 12, 2, 3, 1, 0, 5, 4, 1, 1, 0, 0, 29, 1, 0, 0, 0, 0, 4, 0, 0, 1, 0, 1,
120 7, 0, 42, 0, 0, 0, 0, 0, 2, 0, 3, 9, 0, 0, 0, 2, 1, 0, 0, 6, 5, 6, 1, 2, 3, 0, 0,
121 0, 3, 0, 0, 28, 0, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 23, 0, 0, 0, 0,
122 0, 21, 1, 0, 3, 24, 2, 0, 0, 7, 0, 0, 1, 5, 1, 2, 0, 5
125 0, 1, 0, 0, 1, 2, 7, 11, 18, 31, 28, 40, 0, 1, 0, 0, 116,
129 74, 8, 14, 7, 9345, 40, 0, 2014, 2, 1, 115, 0, 2, 1, 194, 388, 20, 0, 0, 2, 1, 121,
130 1, 1583, 0, 16, 21, 2, 132, 2, 15, 9, 13, 1, 0, 2293, 2, 8, 5, 2, 30, 0, 0, 4, 54,
131 783, 4, 1, 2, 4, 0, 22, 93, 1, 143, 19, 0, 36, 32, 4, 6, 33, 3, 45, 0, 8, 1, 0, 18,
132 17, 1, 0, 1, 0, 0, 1, 1004, 38, 3, 8, 90, 23, 0, 2819, 3, 0, 970, 158, 9, 6, 4, 48,
133 4, 0, 1, 0, 0, 60, 3, 62, 0, 2, 2, 2, 279, 66, 16, 1, 20, 0, 7, 9, 32, 1411, 6, 3,
134 27, 1, 5, 49, 0, 0, 0, 0, 0, 2, 10, 1, 1, 2, 3, 801, 3, 25, 5, 1, 1, 0, 632, 0, 14,
135 18, 5, 8, 200, 4, 4, 22, 12, 0, 4, 1, 0, 2, 4, 9, 3, 16, 7, 2, 2, 213, 0, 2, 620,
136 39303, 0, 1, 0, 2, 1, 183781, 1, 0, 0, 0, 94, 7, 3, 4, 0, 4, 306, 43, 352, 76, 34,
137 13, 11, 0, 51, 1, 13, 19, 0, 26, 0, 7276, 4, 207, 31, 1, 2, 4, 6, 19, 8, 17, 4, 6,
138 0, 1085, 0, 0, 0, 3, 489, 36, 1, 0, 1, 9420, 294, 28, 0, 57, 5, 0, 9, 2, 0, 1, 2,
139 2, 0, 0, 9, 2, 29, 2, 2, 7, 0, 5, 490, 0, 7, 5, 0, 1, 8, 0, 0, 23255, 0, 1
142 0, 1, 0, 2, 1, 2, 2, 5, 5, 7, 7, 8, 17, 23, 16, 24, 136,
147 int main(
int argc,
char **argv)
155 {.
value = 0, .prob = 1},
156 {.value = 1, .prob = 2},
157 {.value = 2, .prob = 5},
158 {.value = 3, .prob = 10},
159 {.value = 4, .prob = 21},
162 static const uint8_t expected[MAX_LEN + 1] = {
166 uint8_t len_counts[MAX_LEN + 1];
174 if (len_counts[
i] != expected[
i]) {
176 "Built huffman does not equal expectations. "
177 "Expected: %d codes of length %u, "
178 "Actual: %d codes of length %u\n",
180 (
int)len_counts[
i],
i);
185 if (val_counts[
i - 1].
prob > val_counts[
i].
prob) {
186 fprintf(stderr,
"Probability table not ordered ascendingly. "
187 "val_counts[%u] == %d, val_counts[%u] == %d\n",