(tree, max_code, bl_count)
| 22704 | * zero code length. |
| 22705 | */ |
| 22706 | function gen_codes(tree, max_code, bl_count) |
| 22707 | // ct_data *tree; /* the tree to decorate */ |
| 22708 | // int max_code; /* largest code with non zero frequency */ |
| 22709 | // ushf *bl_count; /* number of codes at each bit length */ |
| 22710 | { |
| 22711 | var next_code = new Array(MAX_BITS + 1); /* next code value for each bit length */ |
| 22712 | var code = 0; /* running code value */ |
| 22713 | var bits; /* bit index */ |
| 22714 | var n; /* code index */ |
| 22715 | |
| 22716 | /* The distribution counts are first used to generate the code values |
| 22717 | * without bit reversal. |
| 22718 | */ |
| 22719 | for (bits = 1; bits <= MAX_BITS; bits++) { |
| 22720 | next_code[bits] = code = (code + bl_count[bits - 1]) << 1; |
| 22721 | } |
| 22722 | /* Check that the bit counts in bl_count are consistent. The last code |
| 22723 | * must be all ones. |
| 22724 | */ |
| 22725 | //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1, |
| 22726 | // "inconsistent bit counts"); |
| 22727 | //Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); |
| 22728 | |
| 22729 | for (n = 0; n <= max_code; n++) { |
| 22730 | var len = tree[n * 2 + 1]/*.Len*/; |
| 22731 | if (len === 0) { continue; } |
| 22732 | /* Now reverse the bits */ |
| 22733 | tree[n * 2]/*.Code*/ = bi_reverse(next_code[len]++, len); |
| 22734 | |
| 22735 | //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", |
| 22736 | // n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1)); |
| 22737 | } |
| 22738 | } |
| 22739 | |
| 22740 | |
| 22741 | /* =========================================================================== |
no test coverage detected