change REV_U8 array to invert function
parent
64751fc675
commit
ec8dd2ddee
15
src/lib.rs
15
src/lib.rs
|
@ -165,19 +165,20 @@ impl DynHuffman16 {
|
|||
with_codes!(clens, 15 => u16, |i: u16, code: u16, bits: u8| -> _ {
|
||||
let entry = i | (u16::from(bits) << 12);
|
||||
if bits <= 8 {
|
||||
let base = match (code << (8 - bits)).swap_bits() {
|
||||
Some(&v) => v,
|
||||
None => return Err("invalid length code")
|
||||
let base = match u8::try_from(code << (8 - bits)) {
|
||||
Ok(v) => v.swap_bits(),
|
||||
_ => return Err("invalid length code")
|
||||
};
|
||||
for rest in 0u8 .. 1 << (8 - bits) {
|
||||
patterns[(base | (rest << (bits & 7))) as usize] = entry;
|
||||
}
|
||||
} else {
|
||||
let low = match (code >> (bits - 8)).swap_bits() {
|
||||
Some(&v) => v,
|
||||
None => return Err("invalid length code")
|
||||
let low = match u8::try_from(code >> (bits - 8)) {
|
||||
Ok(v) => v.swap_bits(),
|
||||
_ => return Err("invalid length code")
|
||||
};
|
||||
let high = ((code << (16 - bits)) & 0xff).swap_bits();
|
||||
let high = (code << (16 - bits)) & 0xff;
|
||||
let high = (high as u8).swap_bits();
|
||||
let (min_bits, idx) = if patterns[low as usize] != 0xffff {
|
||||
let bits_prev = (patterns[low as usize] >> 12) as u8;
|
||||
(core::cmp::min(bits_prev, bits), patterns[low as usize] & 0x7ff)
|
||||
|
|
Loading…
Reference in New Issue