Lines Matching refs:code
1 /* enough.c -- determine the maximum size of inflate's Huffman code tables over
19 Clean up code indentation
24 maximum code length in bits to determine the maximum table size for zilb's
29 in the same code for the counting, as do permutations of the assignments of
32 We build a code from shorter to longer lengths, determining how many symbols
34 be coded, what the last code length used was, and how many bit patterns of
35 that length remain unused. Then we add one to the code length and double the
36 number of unused patterns to graduate to the next code length. We then
37 assign all portions of the remaining symbols to that code length that
38 preserve the properties of a correct and eventually complete code. Those
48 entry is pointed to regardless of the bits that follow the short code. If
49 the code is longer than root bits, then the table entry points to a second-
50 level table. The size of that table is determined by the longest code with
51 that root-bit prefix. If that longest code has length len, then the table
54 total number of table entries required by the code is calculated
57 longest code length, resulting in a single, smaller, one-level table.
60 the log2 of the number of symbols), where the shortest code has more bits
62 code. This program, by design, does not handle that case, so it is verified
66 the default arguments), the intermediate states in the build-up of a code
69 the maximum code length in bits. However this is a very small price to pay
80 Beginning the code examination at (root + 1) bit codes, which is enabled by
90 symbols and a large maximum code length, so multiple-precision arithmetic
97 code length to the number of bits in a long long minus the number of bits
98 needed to represent the symbols in a flat code. The code_t type identifies
110 typedef unsigned long long big_t; /* type for code counting */
119 syms: number of symbols remaining to code
125 syms: 3..totsym (totsym == total symbols to code)
127 len: 1..max - 1 (max == maximum code length in bits)
129 syms == 2 is not saved since that immediately leads to a single code. left
132 left ends at syms-1 since left == syms immediately results in a single code.
133 (left > sym is not allowed since that would result in an incomplete code.)
134 len is less than max, since the code completes immediately when len == max.
171 local int root; /* size of base code table in bits */
172 local int large; /* largest code table so far */
174 local int *code; /* number of symbols assigned to each bit length */
175 local big_t *num; /* saved results array for code counting */
181 /* Free allocated space. Uses globals code, num, and done. */
194 if (code != NULL)
195 free(code);
212 /* see if only one possible code */
225 /* we need to use at least this many bit patterns so that the code won't be
233 no limit to the code length, this would become: most = left - 1) */
319 number of code structures used so far is mem, and the number remaining in
320 the current sub-table is rem. Uses the globals max, code, root, large, and
328 /* see if we have a complete code */
330 /* set the last code entry */
331 code[len] = left;
333 /* complete computation of memory used by this code */
341 /* if this is a new maximum, show the entries used and the sub-code */
346 if (code[use])
347 printf("%d[%d] ", code[use], use);
353 code[len] = 0;
361 /* we need to use at least this many bit patterns so that the code won't be
369 no limit to the code length, this would become: most = left - 1) */
384 code[len] = use;
395 code[len] = 0;
399 intermediate code states (syms, left, len). For each completed code,
401 tables. Find the maximum amount of memory required and show the code that
409 /* clear code */
411 code[n] = 0;
438 maximum number of symbols, initial root table size, and maximum code length
440 values are 286, 9, and 15 respectively, for the deflate literal/length code.
445 associated sub-code (starting at root + 1 == 10 bits) is shown.
450 For the deflate literal/length code, use "enough". For the deflate distance
451 code, use "enough 30 6".
460 int syms; /* total number of symbols to code */
461 int n; /* number of symbols to code for this run */
467 code = NULL;
471 /* get arguments -- default to the deflate literal/length code */
489 /* if not restricting the code length, the longest is syms - 1 */
499 fputs("abort: code length too long for internal types\n", stderr);
503 /* reject impossible code requests */
510 /* allocate code vector */
511 code = calloc(max + 1, sizeof(int));
512 if (code == NULL) {
567 puts("cannot handle minimum code lengths > root");