diff options
Diffstat (limited to 'bv1/codec/src/huff.rs')
-rw-r--r-- | bv1/codec/src/huff.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/bv1/codec/src/huff.rs b/bv1/codec/src/huff.rs index 6d74c42..0dbb6ce 100644 --- a/bv1/codec/src/huff.rs +++ b/bv1/codec/src/huff.rs @@ -22,7 +22,6 @@ pub fn write_huff(buf: &[u8], w: &mut impl Write) -> Result<usize> { tree.create_lut(&mut table, 1); tree.write(&mut w)?; - for b in buf { let mut k = table[*b as usize]; while k != 1 { @@ -30,7 +29,7 @@ pub fn write_huff(buf: &[u8], w: &mut impl Write) -> Result<usize> { k >>= 1; } } - + w.flush()?; Ok(w.position) } @@ -76,7 +75,7 @@ impl HT { while parts.len() != 1 { parts.sort_by_key(|e| -(e.0 as isize)); let ((ap, at), (bp, bt)) = (parts.pop().unwrap(), parts.pop().unwrap()); - parts.push((ap + bp + 1, HT::Branch(box at, box bt))) + parts.push((ap + bp + 1, HT::Branch(Box::new(at), Box::new(bt)))) } parts[0].1.clone() } @@ -119,7 +118,10 @@ impl HT { } pub fn read(r: &mut BitIO<impl Read>) -> Result<Self> { match r.rbit()? { - false => Ok(Self::Branch(box Self::read(r)?, box Self::read(r)?)), + false => Ok(Self::Branch( + Box::new(Self::read(r)?), + Box::new(Self::read(r)?), + )), true => Ok(Self::Terminal(r.rbyte()?)), } } |