pub struct DictCompressorN<const N: usize = DEFAULT_DICT_ENTRIES> { /* private fields */ }Expand description
A reusable dict block compressor (owning) with N entries per table.
DictCompressor is the standard-sized alias (two 8 KB tables). Use this
generic form to pick smaller tables, e.g. DictCompressorN::<1024>::new(dict)
for two 2 KB tables. N must be a power of two (checked at compile time).
This is the ergonomic owning dict API for use with alloc. For a no-alloc
variant that borrows the dictionary, see
DictCompressorRef.
Unlike the previous self-referential design, this owns its hash tables and
dictionary as sibling fields and needs no unsafe.
§Example
use lz4rip_encode::{DictCompressor, get_maximum_output_size};
let dict = b"the quick brown fox";
let mut comp = DictCompressor::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<const N: usize> DictCompressorN<N>
impl<const N: usize> DictCompressorN<N>
Sourcepub fn new(dict: &[u8]) -> Self
pub fn new(dict: &[u8]) -> Self
Create a new compressor seeded with an external dictionary.
The dictionary is cloned into owned storage. 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 Compressor 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.