MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / HuffDecode

Function HuffDecode

compression/huffmancoding.go:106–118  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

104// current stores the current node of the traversing algorithm.
105// out stores the current decoded string.
106func 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}

Callers 1

TestHuffmanFunction · 0.92

Calls

no outgoing calls

Tested by 1

TestHuffmanFunction · 0.74