One level of the tree becomes the next by pairing adjacent hashes and hashing each pair into a parent. Today you build one level up, for an even number of nodes.
Turn a level with an even number of hashes into the next level by pairing and hashing adjacent hashes.
Going up one level is a single idea repeated: take the level’s hashes two at a time,
left then right, and hash each pair into a parent with HashNode. Four hashes become
two; two would become one. The parents keep their left-to-right order, so the tree
stays aligned with the data underneath.
Today assumes an even count so every hash has a partner - the four-leaf case lands on exactly two parents. What happens when a level has an odd number of nodes, and the last one is left without a partner, is the very next lesson. For now, pin the clean even case; it is the heart of the build loop.
func pairUp(level []Hash) []Hash {var next []Hashfor i := 0; i+1 < len(level); i += 2 {next = append(next, HashNode(level[i], level[i+1]))}return next}