Struct bitstream_io::huffman::WriteHuffmanTree [] [src]

pub struct WriteHuffmanTree<T: Ord> { /* fields omitted */ }

Methods

impl<T: Ord + Clone> WriteHuffmanTree<T>
[src]

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;
assert!(WriteHuffmanTree::new(vec![(1i32, vec![0]),
                                   (2i32, vec![1, 0]),
                                   (3i32, vec![1, 1])]).is_ok());

Returns true if symbol is in tree.

Given symbol, returns big-endian (bits, value) pair for writing code. Panics if symbol is not found.

Given symbol, returns little-endian (bits, value) pair for writing code. Panics if symbol is not found.