MCPcopy Create free account
hub / github.com/RsyncProject/rsync / gen_codes

Function gen_codes

zlib/trees.c:565–594  ·  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. */

Source from the content-addressed store, hash-verified

563 * zero code length.
564 */
565local void gen_codes(ct_data *tree, int max_code, ushf *bl_count)
566{
567 ush next_code[MAX_BITS+1]; /* next code value for each bit length */
568 ush code = 0; /* running code value */
569 int bits; /* bit index */
570 int n; /* code index */
571
572 /* The distribution counts are first used to generate the code values
573 * without bit reversal.
574 */
575 for (bits = 1; bits <= MAX_BITS; bits++) {
576 next_code[bits] = code = (code + bl_count[bits-1]) << 1;
577 }
578 /* Check that the bit counts in bl_count are consistent. The last code
579 * must be all ones.
580 */
581 Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
582 "inconsistent bit counts");
583 Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
584
585 for (n = 0; n <= max_code; n++) {
586 int len = tree[n].Len;
587 if (len == 0) continue;
588 /* Now reverse the bits */
589 tree[n].Code = bi_reverse(next_code[len]++, len);
590
591 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
592 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
593 }
594}
595
596/* ===========================================================================
597 * 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