diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index bf51bf5..5e0ab9e 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "arbitrary" @@ -10,7 +10,7 @@ checksum = "c38b6b6b79f671c25e1a3e785b7b82d7562ffc9cd3efdc98627e5668a2472490" [[package]] name = "arithmetic-coding" -version = "0.1.1" +version = "0.5.0" dependencies = [ "arithmetic-coding-core", "bitstream-io", @@ -19,7 +19,7 @@ dependencies = [ [[package]] name = "arithmetic-coding-core" -version = "0.1.0" +version = "0.4.2" dependencies = [ "thiserror", ] @@ -36,9 +36,12 @@ dependencies = [ [[package]] name = "bitstream-io" -version = "1.2.0" +version = "4.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521f9cfb75191e53bc98586398c3104a2b10812475930f09eeccb5144fc3e68b" +checksum = "60d4bd9d1db2c6bdf285e223a7fa369d5ce98ec767dec949c6ca62863ce61757" +dependencies = [ + "core2", +] [[package]] name = "cc" @@ -46,15 +49,24 @@ version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +[[package]] +name = "core2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" +dependencies = [ + "memchr", +] + [[package]] name = "fenwick" -version = "1.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad8c7269456fd609f700340399dca5fa160c4785c9623f87b6079e5a479f28b" +checksum = "8da8259e81fd417a39d43d803d72458fcfac27206470d303e85be455e3361030" [[package]] name = "fenwick-model" -version = "0.1.0" +version = "0.1.1" dependencies = [ "arithmetic-coding-core", "fenwick", @@ -72,6 +84,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + [[package]] name = "once_cell" version = "1.10.0" @@ -80,47 +98,47 @@ checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" [[package]] name = "proc-macro2" -version = "1.0.36" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.16" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4af2ec4714533fcdf07e886f17025ace8b997b9ce51204ee69b6da831c3da57" +checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" dependencies = [ "proc-macro2", ] [[package]] name = "syn" -version = "1.0.89" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea297be220d52398dcc07ce15a209fce436d361735ac1db700cab3b6cdfb9f54" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] name = "thiserror" -version = "1.0.30" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.30" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ "proc-macro2", "quote", @@ -128,7 +146,7 @@ dependencies = [ ] [[package]] -name = "unicode-xid" -version = "0.2.2" +name = "unicode-ident" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 31e2c9e..e70441b 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -11,7 +11,7 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4" arithmetic-coding = { path = ".." } -bitstream-io = "1.2.0" +bitstream-io = "4.9.0" fenwick-model = { path = "../fenwick-model" } # Prevent this from interfering with workspaces diff --git a/fuzz/fuzz_targets/round_trip.rs b/fuzz/fuzz_targets/round_trip.rs index 1b44655..a32b739 100644 --- a/fuzz/fuzz_targets/round_trip.rs +++ b/fuzz/fuzz_targets/round_trip.rs @@ -17,9 +17,10 @@ where M: Model, { let mut bitwriter = BitWriter::endian(Vec::new(), BigEndian); - let mut encoder = Encoder::::new(model); + let encoder = Encoder::new(model, &mut bitwriter); - encoder.encode_all(input, &mut bitwriter).expect("failed to encode data!"); + encoder.encode_all(input).expect("failed to encode data!"); + bitwriter.byte_align().expect("failed to byte-align the stream"); bitwriter.into_writer() @@ -30,7 +31,7 @@ where M: Model, { let bitreader = BitReader::endian(buffer, BigEndian); - let mut decoder = Decoder::new(model, bitreader).unwrap(); + let mut decoder = Decoder::new(model, bitreader); decoder.decode_all().map(Result::unwrap).collect() } diff --git a/src/encoder.rs b/src/encoder.rs index 76db9ac..ed6ec6f 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -16,16 +16,16 @@ use crate::{ /// An arithmetic decoder converts a stream of symbols into a stream of bits, /// using a predictive [`Model`]. #[derive(Debug)] -pub struct Encoder<'a, M, W> +pub struct Encoder where M: Model, W: BitWrite, { model: M, - state: State<'a, M::B, W>, + state: State, } -impl<'a, M, W> Encoder<'a, M, W> +impl Encoder where M: Model, W: BitWrite, @@ -48,7 +48,7 @@ where /// /// If these constraints cannot be satisfied this method will panic in debug /// builds - pub fn new(model: M, bitwriter: &'a mut W) -> Self { + pub fn new(model: M, bitwriter: W) -> Self { let frequency_bits = model.max_denominator().log2() + 1; let precision = M::B::BITS - frequency_bits; Self::with_precision(model, bitwriter, precision) @@ -67,7 +67,7 @@ where /// /// If these constraints cannot be satisfied this method will panic in debug /// builds - pub fn with_precision(model: M, bitwriter: &'a mut W, precision: u32) -> Self { + pub fn with_precision(model: M, bitwriter: W, precision: u32) -> Self { let state = State::new(precision, bitwriter); Self::with_state(state, model) } @@ -76,7 +76,7 @@ where /// /// This is useful for manually chaining a shared buffer through multiple /// encoders. - pub fn with_state(state: State<'a, M::B, W>, model: M) -> Self { + pub fn with_state(state: State, model: M) -> Self { #[cfg(debug_assertions)] assert_precision_sufficient::(model.max_denominator(), state.state.precision); Self { model, state } @@ -143,7 +143,7 @@ where } /// Return the internal model and state of the encoder. - pub fn into_inner(self) -> (M, State<'a, M::B, W>) { + pub fn into_inner(self) -> (M, State) { (self.model, self.state) } @@ -151,7 +151,7 @@ where /// /// Allows for chaining multiple sequences of symbols into a single stream /// of bits - pub fn chain(self, model: X) -> Encoder<'a, X, W> + pub fn chain(self, model: X) -> Encoder where X: Model, { @@ -161,7 +161,7 @@ where /// A convenience struct which stores the internal state of an [`Encoder`]. #[derive(Debug)] -pub struct State<'a, B, W> +pub struct State where B: BitStore, W: BitWrite, @@ -169,10 +169,10 @@ where #[allow(clippy::struct_field_names)] state: common::State, pending: u32, - output: &'a mut W, + output: W, } -impl<'a, B, W> State<'a, B, W> +impl State where B: BitStore, W: BitWrite, @@ -181,7 +181,7 @@ where /// /// Normally this would be done automatically using the [`Encoder::new`] /// method. - pub fn new(precision: u32, output: &'a mut W) -> Self { + pub fn new(precision: u32, output: W) -> Self { let state = common::State::new(precision); let pending = 0;