Skip to main content

SequenceReplay

Struct SequenceReplay 

Source
pub struct SequenceReplay<'s> { /* private fields */ }
Expand description

A Matcher that reports a given parse instead of searching, so the ordinary block pipeline builds a frame from it (C ZSTD_compressSequences). The parse is consumed as blocks are cut: wherever the encoder ends a block, a sequence running across the cut is split there, and a match piece shorter than MIN_MATCH goes out as literals. Block delimiters, if any, end blocks: each delimited region is a block of its own, cut further only where it exceeds the block size.

The parse should pass validate_parse: offsets are taken as given.

use structured_zstd::encoding::sequences::{ExternalSequence, SequenceReplay};
use structured_zstd::encoding::{CompressionLevel, FrameCompressor};

let input = b"abcabcabcabc";
let parse = [ExternalSequence { offset: 3, lit_len: 3, match_len: 9, rep: 0 }];
let replay = SequenceReplay::new(&parse, 1 << 10);
let mut frame = Vec::new();
let mut compressor = FrameCompressor::new_with_matcher(replay, CompressionLevel::Default);
compressor.set_source(&input[..]);
compressor.set_drain(&mut frame);
compressor.compress();

Implementations§

Source§

impl<'s> SequenceReplay<'s>

Source

pub fn new(sequences: &'s [ExternalSequence], window_size: u64) -> Self

Replay sequences into frames whose window is window_size bytes, which every offset must respect.

Source

pub fn with_dictionary(self) -> Self

Let the frame use the compressor’s dictionary: its ID goes in the header and its entropy and repeat offsets seed the first block, so offsets may reach into its content.

Trait Implementations§

Source§

impl Matcher for SequenceReplay<'_>

Source§

fn fixed_block_len(&self) -> Option<usize>

The rest of the region up to the next block delimiter, skipping regions with nothing in them.

Source§

fn get_last_space(&mut self) -> &[u8] ⓘ

The block most recently claimed by commit_filled.
Source§

fn fill_in_place( &mut self, capacity: usize, fill: &mut dyn FnMut(&mut HistoryBuf) -> (usize, bool), ) -> (usize, bool)

Read input straight into the matcher’s history buffer. Read more
Source§

fn uncommitted_input(&self) -> &[u8] ⓘ

Bytes read by fill_in_place that no block has claimed yet.
Source§

fn commit_filled(&mut self, len: usize)

Claim len bytes from the head of uncommitted_input as the next block.
Source§

fn skip_matching(&mut self)

Just process the data in the last committed space for future matching.
Source§

fn start_matching(&mut self, handle_sequence: impl FnMut(Sequence))

Process the data in the last committed space for future matching AND report its sequences, in order, covering the whole block (see Sequence).
Source§

fn reset(&mut self, _level: CompressionLevel)

Reset this matcher so it can be used for the next new frame
Source§

fn supports_dictionary_priming(&self) -> bool

Returns whether this matcher can consume dictionary priming state and produce dictionary-dependent sequences. Defaults to false for custom matchers.
Source§

fn window_size(&self) -> u64

The size of the window the decoder will need to execute all sequences produced by this matcher. Read more
Source§

fn skip_matching_with_hint(&mut self, _incompressible_hint: Option<bool>)

Hint-aware skip path used internally to thread a precomputed block incompressibility verdict to matcher backends. Read more
Source§

fn set_source_size_hint(&mut self, _size: u64)

Provide a hint about the total uncompressed size for the next frame. Read more
Source§

fn set_dictionary_size_hint(&mut self, _sizes: DictionarySizes)

Hint the sizes of the dictionary that will be primed into the next frame. The built-in runtime matcher resolves the frame’s cParams from the dictionary’s CDict tier (upstream ZSTD_createCDict, keyed by the serialized size) and sizes its dictionary tables from the content. Default no-op for custom matchers and test stubs; consumed at the next reset.
Source§

fn clear_param_overrides(&mut self)

Drop any per-frame fine-grained parameter overrides installed via the public parameter API, reverting to plain level-based geometry at the next reset. Called by FrameCompressor::set_compression_level so switching back to a bare level after a customized frame does not keep the old overrides sticky. Default no-op for custom matchers.
Source§

fn prime_with_dictionary( &mut self, _dict_content: &[u8], _offset_hist: [u32; 3], )

Prime matcher state with dictionary history before compressing the next frame. Default implementation is a no-op for custom matchers that do not support this.
Source§

fn dictionary_is_resident(&self) -> bool

Whether the most recent reset re-borrowed a resident attach-mode dictionary (kept the dict bytes + cached index in place). When true the caller MUST skip Self::prime_with_dictionary and only reapply the offset history via Self::reapply_resident_dictionary.
Source§

fn reapply_resident_dictionary(&mut self, _offset_hist: [u32; 3])

Reapply the dictionary’s offset history to a re-borrowed frame — the cheap tail of priming, without the dict commit / re-index. Default no-op.
Source§

fn restore_primed_dictionary(&mut self, _level: CompressionLevel) -> bool

CDict-equivalent fast path for repeated frames sharing one dictionary. Restore the matcher state captured by Self::capture_primed_dictionary at the SAME level (a table copy) instead of re-running Self::prime_with_dictionary (which re-hashes every dictionary position). Returns true when a matching snapshot was restored; false (the default) means the caller must prime then capture.
Source§

fn capture_primed_dictionary(&mut self, _level: CompressionLevel)

Snapshot the post-prime matcher state for the given level so later frames can Self::restore_primed_dictionary it. Default no-op.
Source§

fn invalidate_primed_dictionary(&mut self)

Drop any captured prime snapshot (dictionary or level changed). Default no-op.
Source§

fn seed_dictionary_entropy( &mut self, _huff: Option<&HuffmanTable>, _ll: Option<&FSETable>, _ml: Option<&FSETable>, _of: Option<&FSETable>, )

Seed matcher cost model with dictionary entropy tables before the next frame. Default implementation is a no-op for custom matchers.
Source§

fn block_samples_match_dict(&self, _block: &[u8]) -> bool

Whether a sample of block hashes to a match in an attached dictionary. The raw-fast-path uses this to avoid skipping the scan on a block that looks incompressible but compresses against the dictionary (an external match the block’s own content cannot reveal). Defaults to false for custom matchers (and the no-dict case), leaving the content-only verdict.
Source§

fn matches_beyond_window_tables(&self) -> bool

Whether this matcher finds matches beyond what its regular tables reach (long-distance matching). A block that looks incompressible can then still be a repeat from far back, so the encoder searches every block instead of writing one off on a sample. Defaults to false.
Source§

fn settle_block_cut(&mut self, window: usize, cut: usize) -> usize

Where to cut the next block, given the cut the block splitter proposes cut bytes into the window bytes of uncommitted_input it looked at. A matcher that already knows a match crossing the cut moves it out of the match, at most to window; cutting inside one only makes the next block start by repeating it. Defaults to cut.
Source§

fn heap_size(&self) -> usize

Heap bytes this matcher’s allocations hold (tables, history, scratch), excluding the inline struct itself. Lets a context report its true footprint via ZSTD_sizeof_CCtx. Defaults to 0 for custom matchers.

Auto Trait Implementations§

§

impl<'s> Freeze for SequenceReplay<'s>

§

impl<'s> RefUnwindSafe for SequenceReplay<'s>

§

impl<'s> Send for SequenceReplay<'s>

§

impl<'s> Sync for SequenceReplay<'s>

§

impl<'s> Unpin for SequenceReplay<'s>

§

impl<'s> UnsafeUnpin for SequenceReplay<'s>

§

impl<'s> UnwindSafe for SequenceReplay<'s>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.