Huffman codec implementation. This implementation was shared by Graham on Rune-Server. The below implementation has been converted to Kotlin and slightly cleaned up.