feat(compress): move dedicated dict support predicate to Rust
Dedicated dictionary search support is a pure compression-parameter policy check. Move its strategy and hash/chain-log comparisons into the Rust parameter module behind a by-value ZSTD_compressionParameters ABI, while leaving the existing C fallback path in createCDict_advanced2 unchanged. Test Plan: - `cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression dedicated_dict_search_support_matches_strategy_and_log_boundaries` -- passed - `make -B -C lib -j2 lib` -- passed - `make -C tests -j2 fuzzer` -- passed - `./tests/fuzzer -s4560 -t47 -i48 -v` -- passed - `cargo clippy --manifest-path rust/Cargo.toml --no-default-features --features compression` -- passed - The same clippy command with `--benches` and `--tests` -- passed - `cargo +nightly fmt --manifest-path rust/Cargo.toml` -- passed - `git diff --cached --check` -- passed
This commit is contained in:
@@ -431,6 +431,14 @@ fn cdict_indices_are_tagged(cparams: ZSTD_compressionParameters) -> bool {
|
||||
cparams.strategy == ZSTD_FAST || cparams.strategy == ZSTD_DFAST
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn dedicated_dict_search_is_supported(cparams: ZSTD_compressionParameters) -> bool {
|
||||
cparams.strategy >= ZSTD_GREEDY
|
||||
&& cparams.strategy <= ZSTD_LAZY2
|
||||
&& cparams.hashLog > cparams.chainLog
|
||||
&& cparams.chainLog <= 24
|
||||
}
|
||||
|
||||
/// C ABI for `ZSTD_CDictIndicesAreTagged()`.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn ZSTD_rust_params_cdictIndicesAreTagged(
|
||||
@@ -439,6 +447,14 @@ pub extern "C" fn ZSTD_rust_params_cdictIndicesAreTagged(
|
||||
c_int::from(cdict_indices_are_tagged(cparams))
|
||||
}
|
||||
|
||||
/// C ABI for `ZSTD_dedicatedDictSearch_isSupported()`.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn ZSTD_rust_params_dedicatedDictSearchIsSupported(
|
||||
cparams: ZSTD_compressionParameters,
|
||||
) -> c_int {
|
||||
c_int::from(dedicated_dict_search_is_supported(cparams))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn dict_and_window_log(window_log: u32, src_size: u64, dict_size: u64) -> u32 {
|
||||
/* 1ULL << ZSTD_WINDOWLOG_MAX, which is smaller for 32-bit builds. */
|
||||
@@ -1224,6 +1240,24 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dedicated_dict_search_support_matches_strategy_and_log_boundaries() {
|
||||
let supported = |strategy, chain_log, hash_log| {
|
||||
ZSTD_rust_params_dedicatedDictSearchIsSupported(ZSTD_compressionParameters {
|
||||
strategy,
|
||||
chainLog: chain_log,
|
||||
hashLog: hash_log,
|
||||
..ZSTD_compressionParameters::default()
|
||||
})
|
||||
};
|
||||
|
||||
assert_eq!(supported(ZSTD_GREEDY, 24, 25), 1);
|
||||
assert_eq!(supported(ZSTD_LAZY2, 24, 25), 1);
|
||||
assert_eq!(supported(ZSTD_BTLAZY2, 24, 25), 0);
|
||||
assert_eq!(supported(ZSTD_LAZY2, 24, 24), 0);
|
||||
assert_eq!(supported(ZSTD_LAZY2, 25, 26), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_sequence_validation_preserves_its_int_mode() {
|
||||
for mode in [c_int::MIN, -1, 0, 1, c_int::MAX] {
|
||||
|
||||
Reference in New Issue
Block a user