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

Function least

compression/huffmancoding.go:61–72  ·  view source on GitHub ↗

least removes the node with lowest weight from q1, q2. It returns the node with lowest weight and the slices q1, q2 after the update.

(q1 []Node, q2 []Node)

Source from the content-addressed store, hash-verified

59// least removes the node with lowest weight from q1, q2.
60// It returns the node with lowest weight and the slices q1, q2 after the update.
61func least(q1 []Node, q2 []Node) (Node, []Node, []Node) {
62 if len(q1) == 0 {
63 return q2[0], q1, q2[1:]
64 }
65 if len(q2) == 0 {
66 return q1[0], q1[1:], q2
67 }
68 if q1[0].weight <= q2[0].weight {
69 return q1[0], q1[1:], q2
70 }
71 return q2[0], q1, q2[1:]
72}
73
74// HuffEncoding recursively traverses the Huffman tree pointed by node to obtain
75// the map codes, that associates a rune with a slice of booleans.

Callers 1

HuffTreeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected