/// Build a decoding hash table based on the encoding table code:
///	- short codes (<= HUF_DECBITS) are resolved with a single table access;
///	- long code entry allocations are not optimized, because long codes are
///	  unfrequent;
///	- decoding tables are used by hufDecode();
Build a decoding hash table based on the encoding table code:
short codes (<= HUF_DECBITS) are resolved with a single table access;
long code entry allocations are not optimized, because long codes are
unfrequent;
decoding tables are used by hufDecode().
Build a decoding hash table based on the encoding table code : short codes ( < = HUF_DECBITS ) are resolved with a single table access ; long code entry allocations are not optimized because long codes are unfrequent ; decoding tables are used by hufDecode () .
fn build_decoding_table(
    encoding_table: &[u64],
    min_code_index: usize,
    max_code_index: usize,
) -> Result<Vec<Code>>
{
    let mut decoding_table = vec![Code::Empty; DECODING_TABLE_SIZE]; // not an array because of code not being copy
    for (code_index, &encoded_code) in encoding_table[..= max_code_index].iter().enumerate().skip(min_code_index) {
        let code_index = u32::try_from(code_index).unwrap();
        let code = code(encoded_code);
        let length = length(encoded_code);
        if code >> length != 0 {
            return Err(Error::invalid(INVALID_TABLE_ENTRY));
        }
        if length > DECODE_BITS {
            let long_code = &mut decoding_table[u64_to_usize(code >> (length - DECODE_BITS))];
            match long_code {
                Code::Empty => *long_code = Code::Long(smallvec![code_index]),
                Code::Long(lits) => lits.push(code_index),
                _ => { return Err(Error::invalid(INVALID_TABLE_ENTRY)); }
            }
        }
        else if length != 0 {
            let default_value = Code::Short(ShortCode {
                value: code_index,
                len: length as u8,
            });
            let start_index = u64_to_usize(code << (DECODE_BITS - length));
            let count = u64_to_usize(1 << (DECODE_BITS - length));
            for value in &mut decoding_table[start_index .. start_index + count] {
                *value = default_value.clone();
            }
        }
    }
    Ok(decoding_table)
}
fn build_decoding_table ( encoding_table : & [ u64 ] , min_code_index : usize , max_code_index : usize , ) -> Result < Vec < Code > > { let mut decoding_table = vec ! [ Code Empty DECODING_TABLE_SIZE ] ; // not an array because of code not being copy for ( code_index , & encoded_code ) in encoding_table [ .. = max_code_index ] . iter ( ) . enumerate ( ) . skip ( min_code_index ) { let code_index = u32 :: try_from ( code_index ) . unwrap ( ) ; let code = code ( encoded_code ) ; let length = length ( encoded_code ) ; if code >> length != 0 { return Err ( Error :: invalid ( INVALID_TABLE_ENTRY ) ) ; } if length > DECODE_BITS { let long_code = & mut decoding_table [ u64_to_usize ( code >> ( length - DECODE_BITS ) ) ] ; match long_code { Code :: Empty => * long_code = Code :: Long ( smallvec ! [ code_index ] ) , Code :: Long ( lits ) => lits . push ( code_index ) , _ => { return Err ( Error :: invalid ( INVALID_TABLE_ENTRY ) ) ; } } } else if length != 0 { let default_value = Code :: Short ( ShortCode { value : code_index , len : length as u8 , } ) ; let start_index = u64_to_usize ( code << ( DECODE_BITS - length ) ) ; let count = u64_to_usize ( 1 << ( DECODE_BITS - length ) ) ; for value in & mut decoding_table [ start_index .. start_index + count ] { * value = default_value . clone ( ) ; } } } Ok ( decoding_table ) }
Build a decoding hash table based on the encoding table code:
 short codes (<= HUF_DECBITS) are resolved with a single table access;
 long code entry allocations are not optimized, because long codes are
unfrequent;
 decoding tables are used by hufDecode();
Build a decoding hash table based on the encoding table code : short codes ( < = HUF_DECBITS ) are resolved with a single table access ; long code entry allocations are not optimized because long codes are unfrequent ; decoding tables are used by hufDecode () ;
encoding_table
&[u64]
min_code_index
usize
max_code_index
usize