pub struct ExpGolomb<N> { /* private fields */ }
Expand description

Zero-sized marker struct for Exponential-Golomb Coding.

See Wikipedia.

This is not a super practical code. It’s provided here mainly to show that the symbol code traits can be used for codes with (essentially) infinitely sized codebooks.

Example

use constriction::{
    symbol::{DefaultQueueEncoder, WriteBitStream, ReadBitStream},
    symbol::exp_golomb::ExpGolomb,
    UnwrapInfallible,
};

let codebook = ExpGolomb::<u32>::new();
let mut encoder = DefaultQueueEncoder::new();
encoder.encode_iid_symbols(&[3, 7, 0, 1], &codebook).unwrap();
let mut decoder = encoder.into_decoder().unwrap_infallible();
let bit_string = decoder.clone().map(
    |bit| if bit.unwrap_infallible() { '1' } else { '0' }
).collect::<String>();

// (Note that the `DefaultQueueEncoder` pads to full words with zeros.
// This is not be a problem since we're using a prefix code.)
assert_eq!(bit_string, "00100000100010100000000000000000");

let decoded = decoder.decode_iid_symbols(4, &codebook).collect::<Result<Vec<_>, _>>().unwrap();
assert_eq!(decoded, [3, 7, 0, 1]);

Implementations§

source§

impl<N> ExpGolomb<N>

source

pub fn new() -> Self

Trait Implementations§

source§

impl<N: Clone> Clone for ExpGolomb<N>

source§

fn clone(&self) -> ExpGolomb<N>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<N> Codebook for ExpGolomb<N>

§

type Symbol = N

source§

impl<N: Debug> Debug for ExpGolomb<N>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<N: Unsigned + PrimInt + WrappingAdd + WrappingSub> DecoderCodebook for ExpGolomb<N>

§

type InvalidCodeword = InvalidCodeword

source§

fn decode_symbol<BackendError>( &self, source: impl Iterator<Item = Result<bool, BackendError>> ) -> Result<Self::Symbol, CoderError<SymbolCodeError<Self::InvalidCodeword>, BackendError>>

source§

impl<N> Default for ExpGolomb<N>

source§

fn default() -> Self

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

impl<N: Unsigned + PrimInt + WrappingAdd + WrappingSub> EncoderCodebook for ExpGolomb<N>

source§

fn encode_symbol_prefix<BackendError>( &self, symbol: impl Borrow<Self::Symbol>, emit: impl FnMut(bool) -> Result<(), BackendError> ) -> Result<(), CoderError<DefaultEncoderFrontendError, BackendError>>

source§

fn encode_symbol_suffix<BackendError>( &self, symbol: impl Borrow<Self::Symbol>, emit: impl FnMut(bool) -> Result<(), BackendError> ) -> Result<(), CoderError<DefaultEncoderFrontendError, BackendError>>

Auto Trait Implementations§

§

impl<N> RefUnwindSafe for ExpGolomb<N>
where N: RefUnwindSafe,

§

impl<N> Send for ExpGolomb<N>
where N: Send,

§

impl<N> Sync for ExpGolomb<N>
where N: Sync,

§

impl<N> Unpin for ExpGolomb<N>
where N: Unpin,

§

impl<N> UnwindSafe for ExpGolomb<N>
where N: UnwindSafe,

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.