nextPowerOfTwo and BuildMerkleTreeStore is copy from github.com/btcsuite/btcd/blockchain/merkle.go nextPowerOfTwo returns the next highest power of two from a given number if it is not already a power of two. This is a helper function used during the calculation of a merkle tree.
(n int)
| 54 | // it is not already a power of two. This is a helper function used during the |
| 55 | // calculation of a merkle tree. |
| 56 | func nextPowerOfTwo(n int) int { |
| 57 | // Return the number if it's already a power of 2. |
| 58 | if n&(n-1) == 0 { |
| 59 | return n |
| 60 | } |
| 61 | |
| 62 | // Figure out and return the next power of two. |
| 63 | exponent := uint(math.Log2(float64(n))) + 1 |
| 64 | return 1 << exponent // 2^exponent |
| 65 | } |
| 66 | |
| 67 | func buildMerkleTreeStore(hashes []*hash.Hash) []*hash.Hash { |
| 68 | // Calculate how many entries are required to hold the binary merkle |
no outgoing calls
no test coverage detected