Huffman coding: Difference between revisions

Content added Content deleted
(→‎{{header|Lua}}: update description)
Line 6,044: Line 6,044:
set encoding [walkTree [$pq get]]
set encoding [walkTree [$pq get]]
set map [dict create {*}[lreverse $encoding]]
if {$opts(-dump)} {
if {$opts(-dump)} {
foreach key [lsort -command compare [dict keys $map]] {
foreach {char huffCode} [lsort -index 1 -stride 2 -command compare $encoding] {
set char [dict get $map $key]
puts "$char\t[dict get $charcount $char]\t$huffCode"
puts "$char\t[dict get $charcount $char]\t$key"
}
}
}
}
$pq destroy
return $encoding
return $encoding