MCPcopy Create free account
hub / github.com/arguiot/TheoremJS / createCodebook

Function createCodebook

src/includes/functions/cryptography/huffman.js:47–64  ·  view source on GitHub ↗
(tree)

Source from the content-addressed store, hash-verified

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
67huffmanDecode(bitstring, tree) {

Callers 2

huffman.jsFile · 0.85
huffmanEncodeMethod · 0.85

Calls 1

recurseFunction · 0.85

Tested by

no test coverage detected