Huffman coding: Difference between revisions

m
(Added Kotlin implementation)
Line 5,796:
This code was adapted from Perl, Python and most of the other examples.
<lang zkl>fcn buildHuffman(text){ //-->(encode dictionary, decode dictionary)
ft:=DDictionary();
foreach c in (text){ ft[c]=ft.find(c,0)+1 } // leafs w/count
 
Line 5,815:
if(T.isType(i))return(Void.Void,i,self.fcn); i });
encodeTable:=tree.toDictionary(); // symbol:Huffman code
decodeTable:=encodeTable.pump(DDictionary(),"reverse"); // code:symbol
return(encodeTable,decodeTable);
}</lang>
Anonymous user