Compare commits

..

No commits in common. "fd0662b66d7a487c1c890c13774188b9bf6a32b6" and "8caa7d894ff5fd519a922f7e9f5350cb6b9be999" have entirely different histories.

2 changed files with 6 additions and 13 deletions

View file

@ -10,14 +10,14 @@ pub trait CompressionScheme {
/// Encode some bytes into `buf`, returning a [`Header`][Self::Header]. /// Encode some bytes into `buf`, returning a [`Header`][Self::Header].
/// ///
/// This does not necessarily have to be deterministic, /// This does not necessarily have to be deterministic,
/// but it **must** be decodable by [`decode`](Self::decode). /// but it **must** always be decodable by [`decode`](Self::decode).
/// That is, [`decode`](Self::decode) ∘ [`encode`](Self::encode) = `id`. /// That is, [`decode`](Self::decode) ∘ [`encode`](Self::encode) = `id`.
fn encode(src: &[u8], buf: &mut BitVec) -> Self::Header; fn encode(src: &[u8], buf: &mut BitVec) -> Self::Header;
/// Decode the given bits and header into `buf`. /// Decode the given bits and header into `buf`.
/// ///
/// This may panic on arbitrary input, /// This may panic on arbitrary input,
/// but it **must** successfully decode outputs of [`encode`](Self::encode). /// but it **must** always decode outputs of [`encode`](Self::encode).
/// That is, [`decode`](Self::decode) ∘ [`encode`](Self::encode) = `id`. /// That is, [`decode`](Self::decode) ∘ [`encode`](Self::encode) = `id`.
fn decode(src: &BitSlice, header: &Self::Header, buf: &mut Vec<u8>); fn decode(src: &BitSlice, header: &Self::Header, buf: &mut Vec<u8>);

View file

@ -6,10 +6,8 @@ mod rle;
#[cfg(test)] #[cfg(test)]
mod test; mod test;
use bitvec::vec::BitVec;
pub use compression_scheme::CompressionScheme; pub use compression_scheme::CompressionScheme;
pub use freq::Freq; pub use freq::Freq;
pub use rle::Rle;
fn main() -> Result<(), io::Error> { fn main() -> Result<(), io::Error> {
let mut buf = Vec::new(); let mut buf = Vec::new();
@ -17,16 +15,11 @@ fn main() -> Result<(), io::Error> {
println!("Original: {len_src}"); println!("Original: {len_src}");
let mut bitbuf = BitVec::new(); // let len_rle = rle::Encoder::new(&buf).count() * 2;
// println!(" Rle'd: {len_rle}");
let () = Rle::encode(&buf, &mut bitbuf); // let len_freq = len_freq_table + len_freq_bits;
let len_rle = bitbuf.len().div_ceil(8); // println!(" Freq'd: {len_freq}");
println!(" Rle'd: {len_rle}");
bitbuf.clear();
let header = Freq::encode(&buf, &mut bitbuf);
let len_freq = Freq::header_size(&header) + bitbuf.len().div_ceil(8);
println!(" Freq'd: {len_freq}");
Ok(()) Ok(())
} }