pub struct PpmModel { /* private fields */ }Expand description
The central PPM model. Maintains up to max_order contexts
and dynamically updates symbol frequencies as you encode or decode.
Higher max_order (e.g. Some(8)) means the model looks at up to 8 previous
bytes for each prediction:
- Pros: Better predictions and higher compression ratio
- Cons: More memory and CPU overhead
Lower max_order (e.g. None → default order 5) is faster and lighter,
but compresses less effectively.
§Examples
use ppmd_core::{encode_file, decode_file, PpmResult};
fn main() -> PpmResult<()> {
// Use default order = 5
encode_file("input.bin", "out.ppm", None)?;
// Use a custom order = 8 for potentially better compression
encode_file("input.bin", "out8.ppm", Some(8))?;
// Decode (always uses order 5)
decode_file("out.ppm", "decoded.bin")?;
Ok(())
}Implementations§
Source§impl PpmModel
impl PpmModel
Sourcepub fn new(max_order: u8) -> PpmResult<Self>
pub fn new(max_order: u8) -> PpmResult<Self>
Create a new PPM model with contexts up to max_order (1..=16).
§Panics
Panics if max_order == 0 or max_order > 16.
Sourcepub fn encode<R: Read, W: Write>(&mut self, input: R, output: W) -> PpmResult<W>
pub fn encode<R: Read, W: Write>(&mut self, input: R, output: W) -> PpmResult<W>
Encode the entire contents of input into output, updating the model
adaptively as you go.
Sourcepub fn decode_symbol<R: Read>(
&mut self,
decoder: &mut RangeDecoder<R>,
history: &mut Vec<u8>,
out: &mut [u8],
) -> PpmResult<()>
pub fn decode_symbol<R: Read>( &mut self, decoder: &mut RangeDecoder<R>, history: &mut Vec<u8>, out: &mut [u8], ) -> PpmResult<()>
Decode one symbol at a time from decoder, writing to out,
and update the model adaptively.
This is used by decode_file under the hood.
Auto Trait Implementations§
impl Freeze for PpmModel
impl RefUnwindSafe for PpmModel
impl Send for PpmModel
impl Sync for PpmModel
impl Unpin for PpmModel
impl UnsafeUnpin for PpmModel
impl UnwindSafe for PpmModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more