platform_build_blueprint/proptools/utils.go
Yu Liu 82e444710d Write ninja file in parallel.
Bug: 335718784
Test: CI
Change-Id: I26f7babca349c654780711cfe0f0ece3faa5f436
2024-05-20 21:46:19 +00:00

25 lines
538 B
Go

package proptools
import (
"math"
)
func ShardBySize[T ~[]E, E any](toShard T, shardSize int) []T {
if len(toShard) == 0 {
return nil
}
ret := make([]T, 0, (len(toShard)+shardSize-1)/shardSize)
for len(toShard) > shardSize {
ret = append(ret, toShard[0:shardSize])
toShard = toShard[shardSize:]
}
if len(toShard) > 0 {
ret = append(ret, toShard)
}
return ret
}
func ShardByCount[T ~[]E, E any](toShard T, shardCount int) []T {
return ShardBySize(toShard, int(math.Ceil(float64(len(toShard))/float64(shardCount))))
}