pub struct CompressionParametersBuilder { /* private fields */ }Expand description
Builder for CompressionParameters. Each setter records one knob;
Self::build validates them against CParameter::bounds.
Implementations§
Source§impl CompressionParametersBuilder
impl CompressionParametersBuilder
Sourcepub fn row_match_finder(self, mode: RowMatchFinderMode) -> Self
pub fn row_match_finder(self, mode: RowMatchFinderMode) -> Self
Choose the finder the greedy, lazy and lazy2 strategies search instead
of leaving it to the window size. C ZSTD_c_useRowMatchFinder.
use structured_zstd::encoding::{
compress_with_parameters, CompressionLevel, CompressionParameters,
RowMatchFinderMode,
};
use structured_zstd::decoding::FrameDecoder;
let data = b"a row or a chain, the frame decodes the same ".repeat(2000);
let chain = CompressionParameters::builder(CompressionLevel::Level(7))
.row_match_finder(RowMatchFinderMode::Disable)
.build()
.unwrap();
let frame = compress_with_parameters(&data[..], &chain);
let mut decoded = Vec::with_capacity(data.len());
FrameDecoder::new()
.decode_all_to_vec(&frame, &mut decoded)
.unwrap();
assert_eq!(decoded, data);Sourcepub fn literal_compression(self, mode: LiteralCompressionMode) -> Self
pub fn literal_compression(self, mode: LiteralCompressionMode) -> Self
Decide whether literals are entropy-coded, overriding the level’s own
choice. C ZSTD_c_literalCompressionMode.
use structured_zstd::encoding::{
compress_with_parameters, CompressionLevel, CompressionParameters,
LiteralCompressionMode,
};
// Literal-heavy input: 32 distinct symbols and nothing for the match
// finder to repeat, so only entropy-coding the literals shrinks it.
let text: Vec<u8> = (0..8192u32)
.map(|i| b'a' + (i.wrapping_mul(2_654_435_761) >> 27) as u8)
.collect();
// Level -3 stores literals raw by default; asking for compression
// makes the frame smaller on input like this.
let compressed_literals = CompressionParameters::builder(CompressionLevel::Level(-3))
.literal_compression(LiteralCompressionMode::Enable)
.build()
.unwrap();
let plain = compress_with_parameters(
&text[..],
&CompressionParameters::builder(CompressionLevel::Level(-3)).build().unwrap(),
);
let coded = compress_with_parameters(&text[..], &compressed_literals);
assert!(coded.len() < plain.len());Sourcepub fn window_log(self, value: u32) -> Self
pub fn window_log(self, value: u32) -> Self
Override the maximum back-reference distance (log2). C
ZSTD_c_windowLog.
Sourcepub fn hash_log(self, value: u32) -> Self
pub fn hash_log(self, value: u32) -> Self
Override the match-finder hash table size (log2). C ZSTD_c_hashLog.
Sourcepub fn chain_log(self, value: u32) -> Self
pub fn chain_log(self, value: u32) -> Self
Override the match-finder chain table size (log2). C ZSTD_c_chainLog.
Sourcepub fn search_log(self, value: u32) -> Self
pub fn search_log(self, value: u32) -> Self
Override the search-attempts count (log2). C ZSTD_c_searchLog.
Sourcepub fn min_match(self, value: u32) -> Self
pub fn min_match(self, value: u32) -> Self
Override the minimum match length in bytes. C ZSTD_c_minMatch.
Sourcepub fn target_length(self, value: u32) -> Self
pub fn target_length(self, value: u32) -> Self
Override the “good enough” target match length. C ZSTD_c_targetLength.
Sourcepub fn strategy(self, value: Strategy) -> Self
pub fn strategy(self, value: Strategy) -> Self
Override the match-finder Strategy. C ZSTD_c_strategy.
Sourcepub fn enable_long_distance_matching(self, enable: bool) -> Self
pub fn enable_long_distance_matching(self, enable: bool) -> Self
Enable or disable long-distance matching. C
ZSTD_c_enableLongDistanceMatching. Off at every level preset.
This is the explicit activation toggle; the ldm_* knob setters
also enable LDM implicitly. The flag is plain last-write-wins, so
a trailing enable_long_distance_matching(false) disables LDM even
if an earlier ldm_* call set a knob (the knob is then ignored at
build).
Sourcepub fn ldm_hash_log(self, value: u32) -> Self
pub fn ldm_hash_log(self, value: u32) -> Self
Override the LDM hash table size (log2). C ZSTD_c_ldmHashLog.
Implies Self::enable_long_distance_matching(true).
Sourcepub fn ldm_min_match(self, value: u32) -> Self
pub fn ldm_min_match(self, value: u32) -> Self
Override the LDM minimum match length. C ZSTD_c_ldmMinMatch.
Implies Self::enable_long_distance_matching(true).
Sourcepub fn ldm_bucket_size_log(self, value: u32) -> Self
pub fn ldm_bucket_size_log(self, value: u32) -> Self
Override the LDM bucket size (log2). C ZSTD_c_ldmBucketSizeLog.
Implies Self::enable_long_distance_matching(true).
Sourcepub fn ldm_hash_rate_log(self, value: u32) -> Self
pub fn ldm_hash_rate_log(self, value: u32) -> Self
Override the LDM hash-insertion rate (log2). C ZSTD_c_ldmHashRateLog.
Implies Self::enable_long_distance_matching(true).
Sourcepub fn build(self) -> Result<CompressionParameters, ParameterError>
pub fn build(self) -> Result<CompressionParameters, ParameterError>
Validate every set knob against CParameter::bounds and
produce the resolved CompressionParameters.
§Errors
Returns ParameterError::OutOfBounds for the first knob whose
value falls outside its inclusive range.