HuffEncode encodes the string in by applying the mapping defined by codes.
(codes map[rune][]bool, in string)
| 93 | |
| 94 | // HuffEncode encodes the string in by applying the mapping defined by codes. |
| 95 | func HuffEncode(codes map[rune][]bool, in string) []bool { |
| 96 | out := make([]bool, 0) |
| 97 | for _, s := range in { |
| 98 | out = append(out, codes[s]...) |
| 99 | } |
| 100 | return out |
| 101 | } |
| 102 | |
| 103 | // HuffDecode recursively decodes the binary code in, by traversing the Huffman compression tree pointed by root. |
| 104 | // current stores the current node of the traversing algorithm. |