Skip to content

Commit 53448ac

Browse files
committed
concurent and 3
1 parent 60db6e0 commit 53448ac

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

bitmap_conc.go

+19-7
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,29 @@ func concurrentlyOnContainersRange(numKeys int, bufs [][]uint16, callback func(f
2929
return
3030
}
3131

32-
delta := (numKeys + concurrency - 1) / concurrency
33-
3432
wg := new(sync.WaitGroup)
3533
wg.Add(concurrency - 1)
36-
for i := 0; i < concurrency-1; i++ {
37-
go func(i int) {
38-
callback(delta*i, delta*(i+1), bufs[i])
34+
35+
delta := numKeys / concurrency
36+
rem := numKeys - delta*concurrency
37+
from := 0
38+
for i := 0; i < rem; i++ {
39+
to := from + delta + 1
40+
go func(i, from int) {
41+
callback(from, to, bufs[i])
42+
wg.Done()
43+
}(i, from)
44+
from = to
45+
}
46+
for i := rem; i < concurrency-1; i++ {
47+
to := from + delta
48+
go func(i, from int) {
49+
callback(from, to, bufs[i])
3950
wg.Done()
40-
}(i)
51+
}(i, from)
52+
from = to
4153
}
42-
callback(delta*(concurrency-1), numKeys, bufs[concurrency-1])
54+
callback(from, numKeys, bufs[concurrency-1])
4355
wg.Wait()
4456
}
4557

0 commit comments

Comments
 (0)