pub trait Matcher {
Show 18 methods
// Required methods
fn get_next_space(&mut self) -> Vec<u8> ⓘ;
fn get_last_space(&mut self) -> &[u8] ⓘ;
fn commit_space(&mut self, space: Vec<u8>);
fn skip_matching(&mut self);
fn start_matching(
&mut self,
handle_sequence: impl for<'a> FnMut(Sequence<'a>),
);
fn reset(&mut self, level: CompressionLevel);
fn window_size(&self) -> u64;
// Provided methods
fn skip_matching_with_hint(&mut self, _incompressible_hint: Option<bool>) { ... }
fn set_source_size_hint(&mut self, _size: u64) { ... }
fn set_dictionary_size_hint(&mut self, _size: usize) { ... }
fn clear_param_overrides(&mut self) { ... }
fn prime_with_dictionary(
&mut self,
_dict_content: &[u8],
_offset_hist: [u32; 3],
) { ... }
fn restore_primed_dictionary(&mut self, _level: CompressionLevel) -> bool { ... }
fn capture_primed_dictionary(&mut self, _level: CompressionLevel) { ... }
fn invalidate_primed_dictionary(&mut self) { ... }
fn seed_dictionary_entropy(
&mut self,
_huff: Option<&HuffmanTable>,
_ll: Option<&FSETable>,
_ml: Option<&FSETable>,
_of: Option<&FSETable>,
) { ... }
fn supports_dictionary_priming(&self) -> bool { ... }
fn heap_size(&self) -> usize { ... }
}Expand description
Trait used by the encoder that users can use to extend the matching facilities with their own algorithm making their own tradeoffs between runtime, memory usage and compression ratio
This trait operates on buffers that represent the chunks of data the matching algorithm wants to work on. Each one of these buffers is referred to as a space. One or more of these buffers represent the window the decoder will need to decode the data again.
This library asks the Matcher for a new buffer using get_next_space to allow reusing of allocated buffers when they are no longer part of the
window of data that is being used for matching.
The library fills the buffer with data that is to be compressed and commits them back to the matcher using commit_space.
Then it will either call start_matching or, if the space is deemed not worth compressing, skip_matching is called.
This is repeated until no more data is left to be compressed.
Required Methods§
Sourcefn get_next_space(&mut self) -> Vec<u8> ⓘ
fn get_next_space(&mut self) -> Vec<u8> ⓘ
Get a space where we can put data to be matched on. Will be encoded as one block. The maximum allowed size is 128 kB.
Sourcefn get_last_space(&mut self) -> &[u8] ⓘ
fn get_last_space(&mut self) -> &[u8] ⓘ
Get a reference to the last committed space
Sourcefn commit_space(&mut self, space: Vec<u8>)
fn commit_space(&mut self, space: Vec<u8>)
Commit a space to the matcher so it can be matched against
Sourcefn skip_matching(&mut self)
fn skip_matching(&mut self)
Just process the data in the last committed space for future matching.
Sourcefn start_matching(&mut self, handle_sequence: impl for<'a> FnMut(Sequence<'a>))
fn start_matching(&mut self, handle_sequence: impl for<'a> FnMut(Sequence<'a>))
Process the data in the last committed space for future matching AND generate matches for the data
Sourcefn reset(&mut self, level: CompressionLevel)
fn reset(&mut self, level: CompressionLevel)
Reset this matcher so it can be used for the next new frame
Sourcefn window_size(&self) -> u64
fn window_size(&self) -> u64
The size of the window the decoder will need to execute all sequences produced by this matcher.
Must return a positive (non-zero) value; returning 0 causes
StreamingEncoder to reject the first write with an invalid-input error
(InvalidInput with std, Other with no_std).
Must remain stable for the lifetime of a frame.
It may change only after reset() is called for the next frame
(for example because the compression level changed).
Provided Methods§
Sourcefn skip_matching_with_hint(&mut self, _incompressible_hint: Option<bool>)
fn skip_matching_with_hint(&mut self, _incompressible_hint: Option<bool>)
Hint-aware skip path used internally to thread a precomputed block incompressibility verdict to matcher backends.
Default implementation preserves backwards compatibility for external
custom matchers by delegating to skip_matching.
Sourcefn set_source_size_hint(&mut self, _size: u64)
fn set_source_size_hint(&mut self, _size: u64)
Provide a hint about the total uncompressed size for the next frame.
Implementations may use this to select smaller hash tables and windows
for small inputs, matching the C zstd source-size-class behavior.
Called before reset when the caller knows the input
size (e.g. from pledged content size or file metadata).
The default implementation is a no-op for custom matchers and
test stubs. The built-in runtime matcher (MatchGeneratorDriver)
overrides this hook and applies the hint during level resolution.
Sourcefn set_dictionary_size_hint(&mut self, _size: usize)
fn set_dictionary_size_hint(&mut self, _size: usize)
Hint the byte size of the dictionary that will be primed into the next
frame. The built-in runtime matcher uses it to size the binary-tree /
hash-chain match-finder tables from the dictionary’s cParams tier rather
than the source window (donor CDict economics), while keeping the
eviction window source-sized. Default no-op for custom matchers and test
stubs; consumed at the next reset.
Sourcefn clear_param_overrides(&mut self)
fn clear_param_overrides(&mut self)
Drop any per-frame fine-grained parameter overrides installed via
the public parameter API, reverting to plain level-based geometry
at the next reset. Called by
FrameCompressor::set_compression_level
so switching back to a bare level after a customized frame does not
keep the old overrides sticky. Default no-op for custom matchers.
Sourcefn prime_with_dictionary(
&mut self,
_dict_content: &[u8],
_offset_hist: [u32; 3],
)
fn prime_with_dictionary( &mut self, _dict_content: &[u8], _offset_hist: [u32; 3], )
Prime matcher state with dictionary history before compressing the next frame. Default implementation is a no-op for custom matchers that do not support this.
Sourcefn restore_primed_dictionary(&mut self, _level: CompressionLevel) -> bool
fn restore_primed_dictionary(&mut self, _level: CompressionLevel) -> bool
CDict-equivalent fast path for repeated frames sharing one dictionary.
Restore the matcher state captured by Self::capture_primed_dictionary
at the SAME level (a table copy) instead of re-running
Self::prime_with_dictionary (which re-hashes every dictionary
position). Returns true when a matching snapshot was restored;
false (the default) means the caller must prime then capture.
Sourcefn capture_primed_dictionary(&mut self, _level: CompressionLevel)
fn capture_primed_dictionary(&mut self, _level: CompressionLevel)
Snapshot the post-prime matcher state for the given level so later
frames can Self::restore_primed_dictionary it. Default no-op.
Sourcefn invalidate_primed_dictionary(&mut self)
fn invalidate_primed_dictionary(&mut self)
Drop any captured prime snapshot (dictionary or level changed). Default no-op.
Sourcefn seed_dictionary_entropy(
&mut self,
_huff: Option<&HuffmanTable>,
_ll: Option<&FSETable>,
_ml: Option<&FSETable>,
_of: Option<&FSETable>,
)
fn seed_dictionary_entropy( &mut self, _huff: Option<&HuffmanTable>, _ll: Option<&FSETable>, _ml: Option<&FSETable>, _of: Option<&FSETable>, )
Seed matcher cost model with dictionary entropy tables before the next frame. Default implementation is a no-op for custom matchers.
Sourcefn supports_dictionary_priming(&self) -> bool
fn supports_dictionary_priming(&self) -> bool
Returns whether this matcher can consume dictionary priming state and produce
dictionary-dependent sequences. Defaults to false for custom matchers.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".