MCPcopy Create free account
hub / github.com/RoaringBitmap/roaring / parallelExecutor

Function parallelExecutor

BitSliceIndexing/bsi.go:156–195  ·  view source on GitHub ↗
(parallelism int, t *task, e action,
	foundSet *roaring.Bitmap)

Source from the content-addressed store, hash-verified

154type action func(t *task, batch []uint32, resultsChan chan *roaring.Bitmap, wg *sync.WaitGroup)
155
156func parallelExecutor(parallelism int, t *task, e action,
157 foundSet *roaring.Bitmap) *roaring.Bitmap {
158
159 var n int = parallelism
160 if n == 0 {
161 n = runtime.NumCPU()
162 }
163
164 resultsChan := make(chan *roaring.Bitmap, n)
165
166 card := foundSet.GetCardinality()
167 x := card / uint64(n)
168
169 remainder := card - (x * uint64(n))
170 var batch []uint32
171 var wg sync.WaitGroup
172 iter := foundSet.ManyIterator()
173 for i := 0; i < n; i++ {
174 if i == n-1 {
175 batch = make([]uint32, x+remainder)
176 } else {
177 batch = make([]uint32, x)
178 }
179 iter.NextMany(batch)
180 wg.Add(1)
181 go e(t, batch, resultsChan, &wg)
182 }
183
184 wg.Wait()
185
186 close(resultsChan)
187
188 ba := make([]*roaring.Bitmap, 0)
189 for bm := range resultsChan {
190 ba = append(ba, bm)
191 }
192
193 return roaring.ParOr(0, ba...)
194
195}
196
197type bsiAction func(input *BSI, batch []uint32, resultsChan chan *BSI, wg *sync.WaitGroup)
198

Callers 3

CompareValueMethod · 0.70
IntersectAndTransposeMethod · 0.70
BatchEqualMethod · 0.70

Calls 5

NextManyMethod · 0.65
GetCardinalityMethod · 0.45
ManyIteratorMethod · 0.45
AddMethod · 0.45
ParOrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…