mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-24 12:37:16 +00:00
7c15ed59e4
* Enable prealloc linter * Set inital slice len to 0
49 lines
845 B
Go
49 lines
845 B
Go
package bor
|
|
|
|
func AppendBytes32(data ...[]byte) []byte {
|
|
var result []byte
|
|
for _, v := range data {
|
|
paddedV, err := ConvertTo32(v)
|
|
if err == nil {
|
|
result = append(result, paddedV[:]...)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func NextPowerOfTwo(n uint64) uint64 {
|
|
if n == 0 {
|
|
return 1
|
|
}
|
|
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
|
n--
|
|
n |= n >> 1
|
|
n |= n >> 2
|
|
n |= n >> 4
|
|
n |= n >> 8
|
|
n |= n >> 16
|
|
n |= n >> 32
|
|
n++
|
|
return n
|
|
}
|
|
|
|
func ConvertTo32(input []byte) (output [32]byte, err error) {
|
|
l := len(input)
|
|
if l > 32 || l == 0 {
|
|
return
|
|
}
|
|
copy(output[32-l:], input)
|
|
return
|
|
}
|
|
|
|
func Convert(input [][32]byte) [][]byte {
|
|
output := make([][]byte, 0, len(input))
|
|
for _, in := range input {
|
|
newInput := make([]byte, len(in[:]))
|
|
copy(newInput, in[:])
|
|
output = append(output, newInput)
|
|
|
|
}
|
|
return output
|
|
}
|