Struct bitstream_io::huffman::WriteHuffmanTree
[−]
[src]
pub struct WriteHuffmanTree<E: Endianness, T: Ord> { /* fields omitted */ }
Methods
impl<E: Endianness, T: Ord + Clone> WriteHuffmanTree<E, T>
[src]
fn new(values: Vec<(T, Vec<u8>)>)
-> Result<WriteHuffmanTree<E, T>, HuffmanTreeError>
-> Result<WriteHuffmanTree<E, T>, HuffmanTreeError>
Given a vector of symbol/code pairs, compiles a Huffman tree for writing. Code must be 0 or 1 bits and are always written to the stream from least-significant in the list to most signficant (which makes them easier to read for humans).
If the same symbol occurs multiple times, the first code is used. Unlike in read trees, not all possible codes need to be assigned a symbol.
Example
use bitstream_io::huffman::WriteHuffmanTree; use bitstream_io::BigEndian; assert!(WriteHuffmanTree::<BigEndian,i32>::new( vec![(1, vec![0]), (2, vec![1, 0]), (3, vec![1, 1])]).is_ok());
fn has_symbol(&self, symbol: T) -> bool
Returns true if symbol is in tree.
fn get(&self, symbol: T) -> (u32, u64)
Given symbol, returns (bits, value) pair for writing code. Panics if symbol is not found.