Skip to main content

EntropyEncoder

Struct EntropyEncoder 

Source
pub struct EntropyEncoder<S: EncoderVariantForS> { /* private fields */ }
Expand description

High-level entropy encoder using PMF distributions with bypass support.

Generic over S: RansParams (RansByte or Rans64).

§Example

use msrtc_rans::entropy::EntropyEncoder;
use msrtc_rans::RansByte;

let mut enc: EntropyEncoder<RansByte> = EntropyEncoder::new();
enc.initialize(
    &[4, 6],       // pmf_lengths
    &[1, 2],       // pmf_offsets
    &[1, 3, 1, 1, 1, 3, 5, 3, 1, 1],  // pmf_table
    16,            // symbol_bits
    4,             // bypass_bits
).unwrap();

let mut buffer = Vec::new();
enc.encode(&[0, 1], &[1, 1], &mut buffer).unwrap();

Implementations§

Source§

impl<S: EncoderVariantForS> EntropyEncoder<S>

Source

pub fn new() -> Self

Create a new uninitialized entropy encoder.

Source

pub fn initialize( &mut self, pmf_lengths: &[i32], pmf_offsets: &[i32], pmf_table: &[i32], symbol_bits: u32, bypass_bits: u32, ) -> Result<(), EntropyError>

Initialize the encoder with PMF distribution data.

  • pmf_lengths — number of symbols per distribution (including bypass sentinel)
  • pmf_offsets — value offsets per distribution
  • pmf_table — flat array of symbol frequencies for all distributions
  • symbol_bits — number of bits for symbol encoding (e.g. 16)
  • bypass_bits — number of bits for bypass encoding (e.g. 4)
Source

pub fn encode_batch( &self, indices: &[i32], values: &[i32], encoder: &mut <S as EncoderVariantForS>::RawEnc, ) -> Result<(), EntropyError>

Encode symbols onto an existing raw encoder for persistent streaming.

Unlike encode(), this does NOT flush the encoder or finalize output. Call encoder.flush() and extract units after all batches are pushed.

Source

pub fn encode( &self, indices: &[i32], values: &[i32], buffer: &mut Vec<u8>, ) -> Result<(), EntropyError>

One-shot encode: encode indices/values into buffer.

The encoded bytes are appended to buffer.

Trait Implementations§

Source§

impl<S: EncoderVariantForS> Default for EntropyEncoder<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.