MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / gen_codes

Function gen_codes

zlib/trees.c:577–609  ·  view source on GitHub ↗

=========================================================================== * Generate the codes for a given tree and bit counts (which need not be * optimal). * IN assertion: the array bl_count contains the bit length statistics for * the given tree and the field len is set for all tree elements. * OUT assertion: the field code is set for all tree elements of non * zero code length. */

(tree, max_code, bl_count)

Source from the content-addressed store, hash-verified

575 * zero code length.
576 */
577local void gen_codes (tree, max_code, bl_count)
578 ct_data *tree; /* the tree to decorate */
579 int max_code; /* largest code with non zero frequency */
580 ushf *bl_count; /* number of codes at each bit length */
581{
582 ush next_code[MAX_BITS+1]; /* next code value for each bit length */
583 ush code = 0; /* running code value */
584 int bits; /* bit index */
585 int n; /* code index */
586
587 /* The distribution counts are first used to generate the code values
588 * without bit reversal.
589 */
590 for (bits = 1; bits <= MAX_BITS; bits++) {
591 next_code[bits] = code = (code + bl_count[bits-1]) << 1;
592 }
593 /* Check that the bit counts in bl_count are consistent. The last code
594 * must be all ones.
595 */
596 Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
597 "inconsistent bit counts");
598 Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
599
600 for (n = 0; n <= max_code; n++) {
601 int len = tree[n].Len;
602 if (len == 0) continue;
603 /* Now reverse the bits */
604 tree[n].Code = bi_reverse(next_code[len]++, len);
605
606 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
607 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
608 }
609}
610
611/* ===========================================================================
612 * Construct one Huffman tree and assigns the code bit strings and lengths.

Callers 2

tr_static_initFunction · 0.85
build_treeFunction · 0.85

Calls 1

bi_reverseFunction · 0.85

Tested by

no test coverage detected