MCPcopy
hub / github.com/RoaringBitmap/roaring / HeapOr

Function HeapOr

fastaggregation.go:167–184  ·  view source on GitHub ↗

HeapOr computes the union between many bitmaps quickly using a heap. It might be faster than calling Or repeatedly.

(bitmaps ...*Bitmap)

Source from the content-addressed store, hash-verified

165// HeapOr computes the union between many bitmaps quickly using a heap.
166// It might be faster than calling Or repeatedly.
167func HeapOr(bitmaps ...*Bitmap) *Bitmap {
168 if len(bitmaps) == 0 {
169 return NewBitmap()
170 }
171 // TODO: for better speed, we could do the operation lazily, see Java implementation
172 pq := make(priorityQueue, len(bitmaps))
173 for i, bm := range bitmaps {
174 pq[i] = &item{bm, i}
175 }
176 heap.Init(&pq)
177
178 for pq.Len() > 1 {
179 x1 := heap.Pop(&pq).(*item)
180 x2 := heap.Pop(&pq).(*item)
181 heap.Push(&pq, &item{Or(x1.value, x2.value), 0})
182 }
183 return heap.Pop(&pq).(*item).value
184}
185
186// HeapXor computes the symmetric difference between many bitmaps quickly (as opposed to calling Xor repeated).
187// Internally, this function uses a heap.

Callers 1

Calls 5

NewBitmapFunction · 0.70
OrFunction · 0.70
LenMethod · 0.45
PopMethod · 0.45
PushMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…