mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
batch slice cap should be actions divided by batchSize and plus one for remainder (added braces for clarity)
parent
0f386c514f
commit
46fe561bef
@ -177,7 +177,7 @@ Useful if you want to do batch processing on large slices.
|
|||||||
```go
|
```go
|
||||||
actions := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
actions := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||||
batchSize := 3
|
batchSize := 3
|
||||||
batches := make([][]int, 0, (len(actions) + batchSize - 1) / batchSize)
|
batches := make([][]int, 0, (len(actions) / batchSize + 1))
|
||||||
|
|
||||||
for batchSize < len(actions) {
|
for batchSize < len(actions) {
|
||||||
actions, batches = actions[batchSize:], append(batches, actions[0:batchSize:batchSize])
|
actions, batches = actions[batchSize:], append(batches, actions[0:batchSize:batchSize])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user