golang如何trunk一个map

golang如何实现一个像php的array_trunk()的方法来chunk一个map?

达令说
浏览 457回答 2
2回答

慕标琳琳

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) }
打开App,查看更多内容
随时随地看视频慕课网APP