pub struct HuffmanEncoder { /* private fields */ }Expand description
Huffman encoder for lossless compression
Builds an optimal prefix-free code based on symbol frequencies, assigning shorter codes to more frequent symbols.
Implementations§
Source§impl HuffmanEncoder
impl HuffmanEncoder
Sourcepub fn from_frequencies(
frequencies: &HashMap<u32, u64>,
) -> TokenizerResult<Self>
pub fn from_frequencies( frequencies: &HashMap<u32, u64>, ) -> TokenizerResult<Self>
Build a Huffman encoder from symbol frequencies
§Arguments
frequencies- Map from symbol to frequency count
§Returns
A Huffman encoder with optimal prefix-free codes
§Example
ⓘ
let mut freqs = HashMap::new();
freqs.insert(0, 10); // Symbol 0 appears 10 times
freqs.insert(1, 5); // Symbol 1 appears 5 times
freqs.insert(2, 2); // Symbol 2 appears 2 times
let encoder = HuffmanEncoder::from_frequencies(&freqs);Sourcepub fn tree(&self) -> (&[HuffmanNode], usize)
pub fn tree(&self) -> (&[HuffmanNode], usize)
Get the Huffman tree (for decoder)
Auto Trait Implementations§
impl Freeze for HuffmanEncoder
impl RefUnwindSafe for HuffmanEncoder
impl Send for HuffmanEncoder
impl Sync for HuffmanEncoder
impl Unpin for HuffmanEncoder
impl UnwindSafe for HuffmanEncoder
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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