HeapOr computes the union between many bitmaps quickly using a heap. It might be faster than calling Or repeatedly.
(bitmaps ...*Bitmap)
| 165 | // HeapOr computes the union between many bitmaps quickly using a heap. |
| 166 | // It might be faster than calling Or repeatedly. |
| 167 | func 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. |
searching dependent graphs…