HuffDecode recursively decodes the binary code in, by traversing the Huffman compression tree pointed by root. current stores the current node of the traversing algorithm. out stores the current decoded string.
(root, current *Node, in []bool, out string)
| 104 | // current stores the current node of the traversing algorithm. |
| 105 | // out stores the current decoded string. |
| 106 | func HuffDecode(root, current *Node, in []bool, out string) string { |
| 107 | if current.symbol != -1 { |
| 108 | out += string(current.symbol) |
| 109 | return HuffDecode(root, root, in, out) |
| 110 | } |
| 111 | if len(in) == 0 { |
| 112 | return out |
| 113 | } |
| 114 | if in[0] { |
| 115 | return HuffDecode(root, current.right, in[1:], out) |
| 116 | } |
| 117 | return HuffDecode(root, current.left, in[1:], out) |
| 118 | } |