RosettaCodeData/Task/Huffman-coding/Zkl/huffman-coding-3.zkl

11 lines
396 B
Plaintext

text:="this is an example for huffman encoding";
encodeTable,decodeTable := buildHuffman(text);
encodeTable.pump(Console.println,fcn(kv){"%s : %s".fmt(kv.xplode())});
e:=encode(text,encodeTable);
"Encode %d characters (%d bits) to %d bits (%d bytes):"
.fmt(text.len(),text.len()*8,e.len(),(e.len()+7)/8).println();
println(e);
0'|Bits decoded to: "%s"|.fmt(decode(e,decodeTable)).println();