pub(crate) struct HuffmanTree {
tree: Vec<HuffmanTreeNode>,
max_nodes: usize,
num_nodes: usize,
}
Expand description
Huffman tree
Fields§
§tree: Vec<HuffmanTreeNode>
§max_nodes: usize
§num_nodes: usize
Implementations§
source§impl HuffmanTree
impl HuffmanTree
fn is_full(&self) -> bool
sourcefn assign_children(&mut self, node_index: usize) -> usize
fn assign_children(&mut self, node_index: usize) -> usize
Turns a node from empty into a branch and assigns its children
sourcefn init(num_leaves: usize) -> ImageResult<HuffmanTree>
fn init(num_leaves: usize) -> ImageResult<HuffmanTree>
Init a huffman tree
sourcefn code_lengths_to_codes(code_lengths: &[u16]) -> ImageResult<Vec<Option<u16>>>
fn code_lengths_to_codes(code_lengths: &[u16]) -> ImageResult<Vec<Option<u16>>>
Converts code lengths to codes
sourcefn add_symbol(
&mut self,
symbol: u16,
code: u16,
code_length: u16,
) -> ImageResult<()>
fn add_symbol( &mut self, symbol: u16, code: u16, code_length: u16, ) -> ImageResult<()>
Adds a symbol to a huffman tree
sourcepub(crate) fn build_implicit(code_lengths: Vec<u16>) -> ImageResult<HuffmanTree>
pub(crate) fn build_implicit(code_lengths: Vec<u16>) -> ImageResult<HuffmanTree>
Builds a tree implicitly, just from code lengths
sourcepub(crate) fn build_explicit(
code_lengths: Vec<u16>,
codes: Vec<u16>,
symbols: Vec<u16>,
) -> ImageResult<HuffmanTree>
pub(crate) fn build_explicit( code_lengths: Vec<u16>, codes: Vec<u16>, symbols: Vec<u16>, ) -> ImageResult<HuffmanTree>
Builds a tree explicitly from lengths, codes and symbols
sourcepub(crate) fn read_symbol(&self, bit_reader: &mut BitReader) -> ImageResult<u16>
pub(crate) fn read_symbol(&self, bit_reader: &mut BitReader) -> ImageResult<u16>
Reads a symbol using the bitstream
Trait Implementations§
source§impl Clone for HuffmanTree
impl Clone for HuffmanTree
source§fn clone(&self) -> HuffmanTree
fn clone(&self) -> HuffmanTree
Returns a copy 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 moresource§impl Debug for HuffmanTree
impl Debug for HuffmanTree
source§impl Default for HuffmanTree
impl Default for HuffmanTree
source§fn default() -> HuffmanTree
fn default() -> HuffmanTree
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for HuffmanTree
impl RefUnwindSafe for HuffmanTree
impl Send for HuffmanTree
impl Sync for HuffmanTree
impl Unpin for HuffmanTree
impl UnwindSafe for HuffmanTree
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> 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 moresource§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian()
.