Update bmt.go

This commit is contained in:
kiel barry 2018-05-07 12:37:24 -07:00 committed by GitHub
parent c223d2bec6
commit 1fe86edb09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -438,27 +438,27 @@ func (h *Hasher) releaseTree() {
} }
func (h *Hasher) writeSegment(i int, s []byte, d int) { func (h *Hasher) writeSegment(i int, s []byte, d int) {
h := h.pool.hasher() hash := h.pool.hasher()
n := h.bmt.leaves[i] n := h.bmt.leaves[i]
if len(s) > h.size && n.parent != nil { if len(s) > h.size && n.parent != nil {
go func() { go func() {
h.Reset() hash.Reset()
h.Write(s) hash.Write(s)
s = h.Sum(nil) s = hash.Sum(nil)
if n.root { if n.root {
h.result <- s h.result <- s
return return
} }
h.run(n.parent, h, d, n.index, s) h.run(n.parent, hash, d, n.index, s)
}() }()
return return
} }
go h.run(n, h, d, i*2, s) go h.run(n, hash, d, i*2, s)
} }
func (h *Hasher) run(n *Node, h hash.Hash, d int, i int, s []byte) { func (h *Hasher) run(n *Node, hash hash.Hash, d int, i int, s []byte) {
isLeft := i%2 == 0 isLeft := i%2 == 0
for { for {
if isLeft { if isLeft {
@ -470,10 +470,10 @@ func (h *Hasher) run(n *Node, h hash.Hash, d int, i int, s []byte) {
return return
} }
if !n.unbalanced || !isLeft || i == 0 && d == 0 { if !n.unbalanced || !isLeft || i == 0 && d == 0 {
h.Reset() hash.Reset()
h.Write(n.left) hash.Write(n.left)
h.Write(n.right) hash.Write(n.right)
s = h.Sum(nil) s = hash.Sum(nil)
} else { } else {
s = append(n.left, n.right...) s = append(n.left, n.right...)