Files
tidb/br/pkg/utils/math.go
2022-05-13 17:28:35 +08:00

17 lines
358 B
Go

// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
package utils
// NextPowerOfTwo returns the smallest power of two greater than or equal to `i`
// Caller should guarantee that i > 0 and the return value is not overflow.
func NextPowerOfTwo(i int64) int64 {
if i&(i-1) == 0 {
return i
}
i *= 2
for i&(i-1) != 0 {
i &= i - 1
}
return i
}