util.go (524B)
1 package hashmap 2 3 import ( 4 "strconv" 5 ) 6 7 const ( 8 // intSizeBytes is the size in byte of an int or uint value. 9 intSizeBytes = strconv.IntSize >> 3 10 ) 11 12 // roundUpPower2 rounds a number to the next power of 2. 13 func roundUpPower2(i uintptr) uintptr { 14 i-- 15 i |= i >> 1 16 i |= i >> 2 17 i |= i >> 4 18 i |= i >> 8 19 i |= i >> 16 20 i |= i >> 32 21 i++ 22 return i 23 } 24 25 // log2 computes the binary logarithm of x, rounded up to the next integer. 26 func log2(i uintptr) uintptr { 27 var n, p uintptr 28 for p = 1; p < i; p += p { 29 n++ 30 } 31 return n 32 }