pub struct RangeCoder { /* private fields */ }Expand description
Multi-symbol range coder with table-based Q15 CDF lookup.
Uses a byte-oriented range coder where both encoder and decoder renormalise
whenever range < BOT (BOT = 2¹⁶). The encoder emits the top byte of
low on each renorm step; the decoder consumes one byte from the bitstream.
Both sides use identical arithmetic, so the decoder faithfully tracks the
encoder’s interval.
§Design
Invariant: range ∈ [BOT, 2³²) after every renormalisation.
Last-symbol optimisation: for the highest-probability symbol (the last
entry in a CDF row) the encoder sets range -= step * cum_lo instead of
step * (cum_hi - cum_lo). This avoids integer rounding errors that would
make low + range > 2³².
Flush: emit exactly 4 bytes of low, which together with the preceding
renorm bytes uniquely identify the encoded sequence. The decoder primes its
code register with those same 4 leading bytes of the bitstream.
Implementations§
Source§impl RangeCoder
impl RangeCoder
Sourcepub fn init_from_slice(&mut self, data: &[u8]) -> Result<(), CodecError>
pub fn init_from_slice(&mut self, data: &[u8]) -> Result<(), CodecError>
Switch to decode mode, priming the code register from data.
§Errors
Returns CodecError::InvalidBitstream if data is empty.
Trait Implementations§
Source§impl Clone for RangeCoder
impl Clone for RangeCoder
Source§fn clone(&self) -> RangeCoder
fn clone(&self) -> RangeCoder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for RangeCoder
impl RefUnwindSafe for RangeCoder
impl Send for RangeCoder
impl Sync for RangeCoder
impl Unpin for RangeCoder
impl UnsafeUnpin for RangeCoder
impl UnwindSafe for RangeCoder
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more