Enum bitstream_io::huffman::ReadHuffmanTree [] [src]

pub enum ReadHuffmanTree<T: Clone> {
    Leaf(T),
    Tree(Box<ReadHuffmanTree<T>>, Box<ReadHuffmanTree<T>>),
}

Variants

Methods

impl<T: Clone> ReadHuffmanTree<T>
[src]

Given a vector of symbol/code pairs, compiles a Huffman tree for reading. Code must be 0 or 1 bits and are always consumed from the stream from least-significant in the list to most signficant (which makes them easier to read for humans).

Each code in the tree must be unique, but symbols may occur multiple times. All possible codes must be assigned some symbol.

Example 1

use bitstream_io::huffman::ReadHuffmanTree;
assert!(ReadHuffmanTree::new(vec![(1i32, vec![0]),
                                  (2i32, vec![1, 0]),
                                  (3i32, vec![1, 1])]).is_ok());

Example 2

Note how the 1 0 code has no symbol, so this tree cannot be built for reading.

use bitstream_io::huffman::ReadHuffmanTree;
assert!(ReadHuffmanTree::new(vec![(1i32, vec![0]),
                                  (3i32, vec![1, 1])]).is_err());