-
Notifications
You must be signed in to change notification settings - Fork 226
/
fastaggregation64.go
36 lines (34 loc) · 1.02 KB
/
fastaggregation64.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package roaring64
// FastAnd computes the intersection between many bitmaps quickly
// Compared to the And function, it can take many bitmaps as input, thus saving the trouble
// of manually calling "And" many times.
func FastAnd(bitmaps ...*Bitmap) *Bitmap {
if len(bitmaps) == 0 {
return NewBitmap()
} else if len(bitmaps) == 1 {
return bitmaps[0].Clone()
}
answer := And(bitmaps[0], bitmaps[1])
for _, bm := range bitmaps[2:] {
answer.And(bm)
}
return answer
}
// FastOr computes the union between many bitmaps quickly, as opposed to having to call Or repeatedly.
// It might also be faster than calling Or repeatedly.
func FastOr(bitmaps ...*Bitmap) *Bitmap {
if len(bitmaps) == 0 {
return NewBitmap()
} else if len(bitmaps) == 1 {
return bitmaps[0].Clone()
}
//answer := lazyOR(bitmaps[0], bitmaps[1])
answer := Or(bitmaps[0], bitmaps[1])
for _, bm := range bitmaps[2:] {
//answer = answer.lazyOR(bm)
answer.Or(bm)
}
// here is where repairAfterLazy is called.
//answer.repairAfterLazy()
return answer
}