MCPcopy Create free account
hub / github.com/CovenantSQL/CovenantSQL / nextPowerOfTwo

Function nextPowerOfTwo

merkle/merkletrie_test.go:56–65  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

54// it is not already a power of two. This is a helper function used during the
55// calculation of a merkle tree.
56func 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
67func buildMerkleTreeStore(hashes []*hash.Hash) []*hash.Hash {
68 // Calculate how many entries are required to hold the binary merkle

Callers 1

buildMerkleTreeStoreFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected