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)
| 29 | // Algorithm is from |
| 30 | // https://web.archive.org/web/20180327073507/graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2. |
| 31 | func 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. |