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)
| 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. |
| 61 | func 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. |