pub struct DictCompressorRefN<'a, const N: usize = DEFAULT_DICT_ENTRIES> { /* private fields */ }Expand description
A reusable dict block compressor (borrowing) with N entries per table.
DictCompressorRef is the standard-sized alias (two 8 KB tables). Use this
generic form to pick smaller tables for memory-constrained targets, e.g.
DictCompressorRefN::<1024>::new(dict) for two 2 KB tables. N must be a
power of two (checked at compile time).
This is the no-alloc dict API. With alloc, use
DictCompressor instead. Without a dictionary, use
CompressorRef.
§Example
use lz4rip_encode::{DictCompressorRef, get_maximum_output_size};
let dict = b"the quick brown fox";
let mut comp = DictCompressorRef::new(dict);
let input = b"the quick brown fox jumps";
let mut output = vec![0u8; get_maximum_output_size(input.len())];
let compressed_len = comp.compress_into(input, &mut output).unwrap();Implementations§
Source§impl<'a, const N: usize> DictCompressorRefN<'a, N>
impl<'a, const N: usize> DictCompressorRefN<'a, N>
Sourcepub fn new(dict: &'a [u8]) -> Self
pub fn new(dict: &'a [u8]) -> Self
Create a new compressor seeded with an external dictionary.
If dict is longer than the LZ4 window it is trimmed to the last
WINDOW_SIZE bytes. A dictionary shorter than
4 bytes is ignored (no dict matches); use CompressorRef for that case.
Sourcepub fn compress_into(
&mut self,
input: &[u8],
output: &mut [u8],
) -> Result<usize, CompressError>
pub fn compress_into( &mut self, input: &[u8], output: &mut [u8], ) -> Result<usize, CompressError>
Compress input into output, returning the number of compressed bytes.
output must be at least get_maximum_output_size(input.len()) bytes.