golang如何实现一个像php的array_trunk()的方法来chunk一个map?
2 回答
慕标琳琳
TA贡献1830条经验 获得超9个赞
func (d *scanner)ChunksAsCPUNumber() {
var divided [][]string
counts := d.Count()
CPUNum := runtime.NumCPU()
size := (counts + CPUNum - 1) / CPUNum
for i := 0; i < counts; i += size {
end := i + size
if end > counts {
end = counts
}
divided = append(divided, d.Files[i:end])
}
fmt.Printf("%#v\n", divided)
}
- 2 回答
- 0 关注
- 456 浏览
添加回答
举报
0/150
提交
取消