pub struct TansEncoder { /* private fields */ }Expand description
tANS encoder for a single stream.
Uses Arc<[T]> for immutable tables, making Clone O(1) instead of O(n).
Only the mutable state field is copied on clone.
Implementations§
Source§impl TansEncoder
impl TansEncoder
Sourcepub fn from_decode_table(decode_table: &FseTable) -> Self
pub fn from_decode_table(decode_table: &FseTable) -> Self
Build a tANS encoder from a decode table.
Implements the exact algorithm from Zstd’s FSE_buildCTable_wksp.
Sourcepub fn init_state(&mut self, symbol: u8)
pub fn init_state(&mut self, symbol: u8)
Initialize encoder state for a specific symbol.
Implements FSE_initCState2 from Zstd:
nbBitsOut = (deltaNbBits + (1<<15)) >> 16 // with rounding
value = (nbBitsOut << 16) - deltaNbBits
state = stateTable[(value >> nbBitsOut) + deltaFindState]This sets up the encoder for the first (last in sequence) symbol without outputting any bits.
Sourcepub fn encode_symbol(&mut self, symbol: u8) -> (u32, u8)
pub fn encode_symbol(&mut self, symbol: u8) -> (u32, u8)
Encode a symbol and return (bits, num_bits).
Implements FSE_encodeSymbol from Zstd:
nbBitsOut = (state + deltaNbBits) >> 16
output low nbBitsOut bits of state
state = stateTable[(state >> nbBitsOut) + deltaFindState]Sourcepub fn get_state(&self) -> u32
pub fn get_state(&self) -> u32
Get current state for serialization.
The decoder reads this as the initial state. For the bitstream, we write (state - tableSize) masked to accuracy_log bits.
Sourcepub fn accuracy_log(&self) -> u8
pub fn accuracy_log(&self) -> u8
Get accuracy log.
Trait Implementations§
Source§impl Clone for TansEncoder
impl Clone for TansEncoder
Source§fn clone(&self) -> TansEncoder
fn clone(&self) -> TansEncoder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TansEncoder
impl RefUnwindSafe for TansEncoder
impl Send for TansEncoder
impl Sync for TansEncoder
impl Unpin for TansEncoder
impl UnwindSafe for TansEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more