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
impl DictTrainer
Sourcepub fn new(max_dict_size: usize) -> Self
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).
Sourcepub fn add_sample(&mut self, data: &[u8])
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.
Sourcepub fn sample_count(&self) -> usize
pub fn sample_count(&self) -> usize
Number of samples added so far.
Sourcepub fn total_bytes(&self) -> usize
pub fn total_bytes(&self) -> usize
Total bytes of sample data added so far.
Auto Trait Implementations§
impl Freeze for DictTrainer
impl RefUnwindSafe for DictTrainer
impl Send for DictTrainer
impl Sync for DictTrainer
impl Unpin for DictTrainer
impl UnsafeUnpin for DictTrainer
impl UnwindSafe for DictTrainer
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