Huffman encoding with tests

Implements Huffman encoding with lot of bit fiddling.