(tree)
| 45 | } |
| 46 | |
| 47 | function createCodebook(tree) { |
| 48 | return recurse(tree, "", {}); |
| 49 | |
| 50 | function recurse(node, bitstring, dict) { |
| 51 | if (!node.left && !node.right) { |
| 52 | dict[node.key] = bitstring; |
| 53 | } else { |
| 54 | if (node.left) { |
| 55 | recurse(node.left, `${bitstring}0`, dict); |
| 56 | } |
| 57 | |
| 58 | if (node.right) { |
| 59 | recurse(node.right, `${bitstring}1`, dict); |
| 60 | } |
| 61 | } |
| 62 | return dict; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | huffmanDecode(bitstring, tree) { |
no test coverage detected