add import storage and test
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
package util
|
||||
|
||||
import "math"
|
||||
|
||||
func FloorDiv(a, b int32) int32 {
|
||||
return (a - ((a%b + b) % b)) / b
|
||||
}
|
||||
|
||||
func BpeByNum(x float64) uint8 {
|
||||
return uint8(math.Ceil(math.Log2(x)))
|
||||
}
|
||||
|
||||
@@ -65,3 +65,19 @@ func MinSlice[T cmp.Ordered](s []T) (ret T) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type Numeric interface {
|
||||
~int | ~int8 | ~int16 | ~int32 | ~int64 |
|
||||
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
|
||||
~float32 | ~float64
|
||||
}
|
||||
|
||||
func SliceRange[T Numeric](s, e T) (ret []T) {
|
||||
if s > e {
|
||||
return
|
||||
}
|
||||
for v := s; v < e; v++ {
|
||||
ret = append(ret, v)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user