Skip to main content

PpmModel

Struct PpmModel 

Source
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

Source

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.