tools/utils/generators/deflate_generator/huff_codes.cpp
// on input, codes contain the code lengths
// on output, code contains:
// 31:24 code length
// 15:0  code value in low order bits
// returns max code value
on input, codes contain the code lengths
on output, code contains:
31:24 code length
15:0  code value in low order bits
returns max code value
on input codes contain the code lengths on output code contains : 31 : 24 code length 15 : 0 code value in low order bits returns max code value
uint32_t compute_codes_cl(uint32_t *codes, uint32_t num_codes, uint32_t *bl_count,
                              uint32_t max_code_len)
    {
        uint32_t code, bits, i;
        uint32_t next_code[MAX_CODE_LEN + 1];
        uint32_t max_code = 0;
        code      = bl_count[0] = 0;
        for (bits = 1; bits <= max_code_len; bits++)
        {
            code = (code + bl_count[bits - 1]) << 1;
            next_code[bits] = code;
        }
        for (i = 0; i < num_codes; i++)
        {
            code = codes[i];
            if (code != 0)
            {
                codes[i] = (code << 24) | bit_reverse(next_code[code], code);
                next_code[code] += 1;
                max_code = i;
            }
        }
        return max_code;
    }
uint32_t compute_codes_cl ( uint32_t * codes , uint32_t num_codes , uint32_t * bl_count , uint32_t max_code_len ) { uint32_t code , bits , i ; uint32_t next_code [ MAX_CODE_LEN + 1 ] ; uint32_t max_code = 0 ; code = bl_count [ 0 ] = 0 ; for ( bits = 1 ; bits <= max_code_len ; bits ++ ) { code = ( code + bl_count [ bits - 1 ] ) << 1 ; next_code [ bits ] = code ; } for ( i = 0 ; i < num_codes ; i ++ ) { code = codes [ i ] ; if ( code != 0 ) { codes [ i ] = ( code << 24 ) | bit_reverse ( next_code [ code ] , code ) ; next_code [ code ] += 1 ; max_code = i ; } } return max_code ; }
on input, codes contain the code lengths
on output, code contains:
31:24 code length
15:0  code value in low order bits
returns max code value
on input codes contain the code lengths on output code contains : 31 : 24 code length 15 : 0 code value in low order bits returns max code value