/// Run-length-decompresses all zero runs from the packed table to the encoding table
Run-length-decompresses all zero runs from the packed table to the encoding table
Run - length - decompresses all zero runs from the packed table to the encoding table
fn read_encoding_table(
    packed: &mut impl Read,
    min_code_index: usize,
    max_code_index: usize,
) -> Result<Vec<u64>>
{
    let mut code_bits = 0_u64;
    let mut code_bit_count = 0_u64;
    // TODO push() into encoding table instead of index stuff?
        let mut encoding_table = vec![0_u64; ENCODING_TABLE_SIZE];
    let mut code_index = min_code_index;
    while code_index <= max_code_index {
        let code_len = read_bits(6, &mut code_bits, &mut code_bit_count, packed)?;
        encoding_table[code_index] = code_len;
        if code_len == LONG_ZEROCODE_RUN {
            let zerun_bits = read_bits(8, &mut code_bits, &mut code_bit_count, packed)?;
            let zerun = usize::try_from(zerun_bits + SHORTEST_LONG_RUN).unwrap();
            if code_index + zerun > max_code_index + 1 {
                return Err(Error::invalid(TABLE_TOO_LONG));
            }
            for value in &mut encoding_table[code_index..code_index + zerun] {
                *value = 0;
            }
            code_index += zerun;
        }
        else if code_len >= SHORT_ZEROCODE_RUN {
            let duplication_count = usize::try_from(code_len - SHORT_ZEROCODE_RUN + 2).unwrap();
            if code_index + duplication_count > max_code_index + 1 {
                return Err(Error::invalid(TABLE_TOO_LONG));
            }
            for value in &mut encoding_table[code_index .. code_index + duplication_count] {
                *value = 0;
            }
            code_index += duplication_count;
        }
        else {
            code_index += 1;
        }
    }
    build_canonical_table(&mut encoding_table);
    Ok(encoding_table)
}
fn read_encoding_table ( packed : & mut impl Read , min_code_index : usize , max_code_index : usize , ) -> Result < Vec < u64 > > { let mut code_bits = 0_u64 ; let mut code_bit_count = 0_u64 ; // TODO push() into encoding table instead of index stuff? let mut encoding_table = vec ! [ 0_u64 ENCODING_TABLE_SIZE ] ; let mut code_index = min_code_index ; while code_index <= max_code_index { let code_len = read_bits ( 6 , & mut code_bits , & mut code_bit_count , packed ) ? ; encoding_table [ code_index ] = code_len ; if code_len == LONG_ZEROCODE_RUN { let zerun_bits = read_bits ( 8 , & mut code_bits , & mut code_bit_count , packed ) ? ; let zerun = usize :: try_from ( zerun_bits + SHORTEST_LONG_RUN ) . unwrap ( ) ; if code_index + zerun > max_code_index + 1 { return Err ( Error :: invalid ( TABLE_TOO_LONG ) ) ; } for value in & mut encoding_table [ code_index .. code_index + zerun ] { * value = 0 ; } code_index += zerun ; } else if code_len >= SHORT_ZEROCODE_RUN { let duplication_count = usize :: try_from ( code_len - SHORT_ZEROCODE_RUN + 2 ) . unwrap ( ) ; if code_index + duplication_count > max_code_index + 1 { return Err ( Error :: invalid ( TABLE_TOO_LONG ) ) ; } for value in & mut encoding_table [ code_index .. code_index + duplication_count ] { * value = 0 ; } code_index += duplication_count ; } else { code_index += 1 ; } } build_canonical_table ( & mut encoding_table ) ; Ok ( encoding_table ) }
Run-length-decompresses all zero runs from the packed table to the encoding table
Run - length - decompresses all zero runs from the packed table to the encoding table
packed
&mut impl Read
min_code_index
usize
max_code_index
usize