pub fn create_legacy_dict_from_slice<W: Write>(
samples: &[u8],
sample_sizes: &[usize],
output: &mut W,
dict_size: usize,
selectivity: u32,
finalize: FinalizeOptions,
) -> Result<()>Available on crate feature
dict-builder only.Expand description
Train and finalize a dictionary with the reference’s original trainer, the
one zstd --train-legacy runs (ZDICT_trainFromBuffer_legacy).
samples is every sample back to back and sample_sizes their lengths:
the trainer searches the corpus as a whole, and the number of samples sets
how often a segment has to repeat to be kept, samples >> selectivity
times and at least 4. A higher selectivity keeps more, rarer segments;
zero is DEFAULT_SELECTIVITY. Corpus past 2000 MiB is dropped a whole
sample at a time from the end.
§Errors
InvalidInput when dict_size is below 256 bytes, when the corpus is under
512 bytes, when it repeats too little to yield 128 bytes of content, or when
sample_sizes does not add up to samples.len().
§Examples
use structured_zstd::dictionary::{create_legacy_dict_from_slice, FinalizeOptions};
let mut samples = Vec::new();
let mut sizes = Vec::new();
for i in 0..200u32 {
let line = format!("tenant=demo table=orders key={i} region=eu status=shipped\n");
sizes.push(line.len());
samples.extend_from_slice(line.as_bytes());
}
let mut dict = Vec::new();
create_legacy_dict_from_slice(&samples, &sizes, &mut dict, 4096, 0, FinalizeOptions::default())
.unwrap();
assert!(dict.starts_with(&[0x37, 0xA4, 0x30, 0xEC]));