Skip to main content

DictTrainer

Struct DictTrainer 

Source
pub struct DictTrainer { /* private fields */ }
Expand description

Trains an LZ4 dictionary from sample messages using the COVER algorithm.

§Example

use lz4rip_encode::DictTrainer;

let mut trainer = DictTrainer::new(2048);
for msg in &[b"hello world" as &[u8], b"hello rust", b"hello lz4"] {
    trainer.add_sample(msg);
}
let dict = trainer.train();
let compressor = lz4rip_encode::DictCompressor::new(&dict);

Implementations§

Source§

impl DictTrainer

Source

pub fn new(max_dict_size: usize) -> Self

Create a trainer targeting max_dict_size bytes of output.

Typical values: 2048 for small messages, 4096 for larger ones. The dict is capped at 65535 bytes (LZ4 max match distance).

Source

pub fn add_sample(&mut self, data: &[u8])

Add a training sample.

Samples shorter than 4 bytes or longer than max_dict_size are silently skipped.

Source

pub fn sample_count(&self) -> usize

Number of samples added so far.

Source

pub fn total_bytes(&self) -> usize

Total bytes of sample data added so far.

Source

pub fn train(self) -> Vec<u8>

Train a dictionary from the collected samples. Consumes the trainer, freeing all sample data.

Returns a raw byte buffer. If fewer than 2 samples were added, returns an empty vec.

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.