// 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 }