func (h *Hasher) writeNode(n *node, isLeft bool, s []byte) {
	var err error
	level := 1
	for {
		// at the root of the bmt just write the result to the result channel
		if n == nil {
			h.result <- s
			return
		}
		// otherwise assign child hash to left or right segment
		if isLeft {
			n.left = s
		} else {
			n.right = s
		}
		// the child-thread first arriving will terminate
		if n.toggle() {
			return
		}
		// the thread coming second now can be sure both left and right children are written
		// so it calculates the hash of left|right and pushes it to the parent
		s, err = doHash(n.hasher, n.left, n.right)
		if err != nil {
			select {
			case h.errc <- err:
			default:
			}
			return
		}
		isLeft = n.isLeft
		n = n.parent
		level++
	}
}
// writeNode pushes the data to the node.
// if it is the first of 2 sisters written, the routine terminates.
// if it is the second, it calculates the hash and writes it
// to the parent node recursively.
// since hashing the parent is synchronous the same hasher can be used.
writeNode pushes the data to the node.
if it is the first of 2 sisters written, the routine terminates.
if it is the second, it calculates the hash and writes it
to the parent node recursively.
since hashing the parent is synchronous the same hasher can be used.
// writeNode pushes the data to the node . // if it is the first of 2 sisters written the routine terminates . // if it is the second it calculates the hash and writes it // to the parent node recursively . // since hashing the parent is synchronous the same hasher can be used .
func (h *Hasher) writeNode(n *node, isLeft bool, s []byte) {
	var err error
	level := 1
	for {
		if n == nil {
			h.result <- s
			return
		}
		if isLeft {
			n.left = s
		} else {
			n.right = s
		}
		if n.toggle() {
			return
		}
		s, err = doHash(n.hasher, n.left, n.right)
		if err != nil {
			select {
			case h.errc <- err:
			default:
			}
			return
		}
		isLeft = n.isLeft
		n = n.parent
		level++
	}
}
func ( h * Hasher ) writeNode ( n * node , isLeft bool , s [ ] byte ) { var err error level := 1 for { if n == nil { h . result <- s return } if isLeft { n . left = s } else { n . right = s } if n . toggle ( ) { return } s , err = doHash ( n . hasher , n . left , n . right ) if err != nil { select { case h . errc <- err : default : } return } isLeft = n . isLeft n = n . parent level ++ } }
writeNode pushes the data to the node.
writeNode pushes the data to the node .
// at the root of the bmt just write the result to the result channel // otherwise assign child hash to left or right segment // the child-thread first arriving will terminate // the thread coming second now can be sure both left and right children are written // so it calculates the hash of left|right and pushes it to the parent