(tree, max_code, bl_count)
| 10722 | * zero code length. |
| 10723 | */ |
| 10724 | function gen_codes(tree, max_code, bl_count) |
| 10725 | // ct_data *tree; /* the tree to decorate */ |
| 10726 | // int max_code; /* largest code with non zero frequency */ |
| 10727 | // ushf *bl_count; /* number of codes at each bit length */ |
| 10728 | { |
| 10729 | var next_code = new Array(MAX_BITS + 1); /* next code value for each bit length */ |
| 10730 | var code = 0; /* running code value */ |
| 10731 | var bits; /* bit index */ |
| 10732 | var n; /* code index */ |
| 10733 | |
| 10734 | /* The distribution counts are first used to generate the code values |
| 10735 | * without bit reversal. |
| 10736 | */ |
| 10737 | for (bits = 1; bits <= MAX_BITS; bits++) { |
| 10738 | next_code[bits] = code = (code + bl_count[bits - 1]) << 1; |
| 10739 | } |
| 10740 | /* Check that the bit counts in bl_count are consistent. The last code |
| 10741 | * must be all ones. |
| 10742 | */ |
| 10743 | //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1, |
| 10744 | // "inconsistent bit counts"); |
| 10745 | //Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); |
| 10746 | |
| 10747 | for (n = 0; n <= max_code; n++) { |
| 10748 | var len = tree[n * 2 + 1]/*.Len*/; |
| 10749 | if (len === 0) { continue; } |
| 10750 | /* Now reverse the bits */ |
| 10751 | tree[n * 2]/*.Code*/ = bi_reverse(next_code[len]++, len); |
| 10752 | |
| 10753 | //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", |
| 10754 | // n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1)); |
| 10755 | } |
| 10756 | } |
| 10757 | |
| 10758 | |
| 10759 | /* =========================================================================== |
no test coverage detected