pub struct Encoder { /* private fields */ }Expand description
Stateful encoder that reuses internal hash-table buffers across calls.
The free functions encode, encode_better, encode_best, and
encode_snappy allocate a fresh hash table on every invocation. For
hot loops compressing many small blocks, allocating and zero-filling
that buffer every time is a measurable fraction of the call cost
(≈ 50–80 % for ≤ 1 KB inputs).
An Encoder holds these buffers and grows them lazily on first use,
so repeated calls in the same mode pay only the in-cache memset cost
instead of going through the system allocator. Output is bit-for-bit
identical to the equivalent free function for every input.
§Example
use minlz::Encoder;
let mut enc = Encoder::new();
let mut compressed_blocks: Vec<Vec<u8>> = (0..1000)
.map(|i| enc.encode(&[i as u8; 256]))
.collect();Implementations§
Source§impl Encoder
impl Encoder
Sourcepub fn encode(&mut self, src: &[u8]) -> Vec<u8> ⓘ
pub fn encode(&mut self, src: &[u8]) -> Vec<u8> ⓘ
Encode src using the standard (fast) algorithm. Equivalent to
the free encode() function but reuses internal hash-table
storage across calls.
Sourcepub fn encode_better(&mut self, src: &[u8]) -> Vec<u8> ⓘ
pub fn encode_better(&mut self, src: &[u8]) -> Vec<u8> ⓘ
Encode src using the better-compression algorithm. Equivalent
to the free encode_better() function with internal buffer
reuse.