Huffman coding: Difference between revisions

Content added Content deleted
m (→‎Testing: add whitespace)
Line 3,736: Line 3,736:
===By building a tree===
===By building a tree===


This version uses nested <code>Array</code>s to builds a tree [https://commons.wikimedia.org/wiki/File:HuffmanCodeAlg.png like shown in this diagram], and then recursively traverses the finished tree to accumulate the prefixes.
This version uses nested <code>Array</code>s to build a tree [https://commons.wikimedia.org/wiki/File:HuffmanCodeAlg.png like shown in this diagram], and then recursively traverses the finished tree to accumulate the prefixes.


{{works with|rakudo|2015-12-17}}
{{works with|rakudo|2015-12-17}}
Line 3,752: Line 3,752:
multi walk ([$node1, $node2], $prefix) { walk $node1, $prefix ~ '0';
multi walk ([$node1, $node2], $prefix) { walk $node1, $prefix ~ '0';
walk $node2, $prefix ~ '1'; }</lang>
walk $node2, $prefix ~ '1'; }</lang>

===Without building a tree===
===Without building a tree===