pub fn create_raw_dict_from_slice<W: Write>(
all: &[u8],
output: &mut W,
dict_size: usize,
) -> Result<()>Available on crate feature
dict-builder only.Expand description
Create a “raw content” dictionary of at most dict_size bytes, with no
entropy tables, from a corpus already in memory, writing it to output.
The corpus has no sample sizes, so it is cut into at least sixteen samples
of at most 128 KiB, and the content is what optimize_fastcover_dict
picks over them at its defaults, as zstd --train does. A corpus no larger
than dict_size is its own content; one the trainer refuses (a
dict_size under MIN_TRAINED_DICT_SIZE, too little to search) gives
its last dict_size bytes.
§Errors
Returns an error writing to output or allocating the trainer’s tables.
§Examples
use structured_zstd::dictionary::create_raw_dict_from_slice;
let corpus: Vec<u8> = (0..20_000u32)
.flat_map(|i| format!("record {} value {}\n", i % 100, i % 7).into_bytes())
.collect();
let mut dict = Vec::new();
create_raw_dict_from_slice(&corpus, &mut dict, 4096).unwrap();
assert!(!dict.is_empty() && dict.len() <= 4096);