From 9835e2ae736235810b4ea1c162ca5e65c547e770 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:50 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/ruzstd/src/decoding/scratch.rs | 128 ++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 vendor/ruzstd/src/decoding/scratch.rs (limited to 'vendor/ruzstd/src/decoding/scratch.rs') diff --git a/vendor/ruzstd/src/decoding/scratch.rs b/vendor/ruzstd/src/decoding/scratch.rs new file mode 100644 index 000000000..2bd753bde --- /dev/null +++ b/vendor/ruzstd/src/decoding/scratch.rs @@ -0,0 +1,128 @@ +use super::super::blocks::sequence_section::Sequence; +use super::decodebuffer::Decodebuffer; +use crate::decoding::dictionary::Dictionary; +use crate::fse::FSETable; +use crate::huff0::HuffmanTable; + +pub struct DecoderScratch { + pub huf: HuffmanScratch, + pub fse: FSEScratch, + pub buffer: Decodebuffer, + pub offset_hist: [u32; 3], + + pub literals_buffer: Vec, + pub sequences: Vec, + pub block_content_buffer: Vec, +} + +impl DecoderScratch { + pub fn new(window_size: usize) -> DecoderScratch { + DecoderScratch { + huf: HuffmanScratch { + table: HuffmanTable::new(), + }, + fse: FSEScratch { + offsets: FSETable::new(), + of_rle: None, + literal_lengths: FSETable::new(), + ll_rle: None, + match_lengths: FSETable::new(), + ml_rle: None, + }, + buffer: Decodebuffer::new(window_size), + offset_hist: [1, 4, 8], + + block_content_buffer: Vec::new(), + literals_buffer: Vec::new(), + sequences: Vec::new(), + } + } + + pub fn reset(&mut self, window_size: usize) { + self.offset_hist = [1, 4, 8]; + self.literals_buffer.clear(); + self.sequences.clear(); + self.block_content_buffer.clear(); + + self.buffer.reset(window_size); + + self.fse.literal_lengths.reset(); + self.fse.match_lengths.reset(); + self.fse.offsets.reset(); + self.fse.ll_rle = None; + self.fse.ml_rle = None; + self.fse.of_rle = None; + + self.huf.table.reset(); + } + + pub fn use_dict(&mut self, dict: &Dictionary) { + self.fse = dict.fse.clone(); + self.huf = dict.huf.clone(); + self.offset_hist = dict.offset_hist; + self.buffer.dict_content = dict.dict_content.clone(); + } + + /// parses the dictionary and set the tables + /// it returns the dict_id for checking with the frame's dict_id + pub fn load_dict( + &mut self, + raw: &[u8], + ) -> Result { + let dict = super::dictionary::Dictionary::decode_dict(raw)?; + + self.huf = dict.huf.clone(); + self.fse = dict.fse.clone(); + self.offset_hist = dict.offset_hist; + self.buffer.dict_content = dict.dict_content.clone(); + Ok(dict.id) + } +} + +#[derive(Clone)] +pub struct HuffmanScratch { + pub table: HuffmanTable, +} + +impl HuffmanScratch { + pub fn new() -> HuffmanScratch { + HuffmanScratch { + table: HuffmanTable::new(), + } + } +} + +impl Default for HuffmanScratch { + fn default() -> Self { + Self::new() + } +} + +#[derive(Clone)] +pub struct FSEScratch { + pub offsets: FSETable, + pub of_rle: Option, + pub literal_lengths: FSETable, + pub ll_rle: Option, + pub match_lengths: FSETable, + pub ml_rle: Option, +} + +impl FSEScratch { + pub fn new() -> FSEScratch { + FSEScratch { + offsets: FSETable::new(), + of_rle: None, + literal_lengths: FSETable::new(), + ll_rle: None, + match_lengths: FSETable::new(), + ml_rle: None, + } + } +} + +impl Default for FSEScratch { + fn default() -> Self { + Self::new() + } +} -- cgit v1.2.3