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

Function upperPowOfTwo

merkle/merkletrie.go:31–41  ·  view source on GitHub ↗

we will not consider overflow because overflow means the length of slice is larger than 2^63 Algorithm is from https://web.archive.org/web/20180327073507/graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2.

(n uint64)

Source from the content-addressed store, hash-verified

29// Algorithm is from
30// https://web.archive.org/web/20180327073507/graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2.
31func upperPowOfTwo(n uint64) uint64 {
32 n--
33 n |= n >> 1
34 n |= n >> 2
35 n |= n >> 4
36 n |= n >> 8
37 n |= n >> 16
38 n |= n >> 32
39 n++
40 return n
41}
42
43// NewMerkle generate a merkle tree according
44// to some hashable values like transactions or blocks.

Callers 1

NewMerkleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected