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

Method lazyOR

fastaggregation.go:56–107  ·  view source on GitHub ↗

In-place Or function that requires repairAfterLazy

(x2 *Bitmap)

Source from the content-addressed store, hash-verified

54
55// In-place Or function that requires repairAfterLazy
56func (x1 *Bitmap) lazyOR(x2 *Bitmap) *Bitmap {
57 pos1 := 0
58 pos2 := 0
59 length1 := x1.highlowcontainer.size()
60 length2 := x2.highlowcontainer.size()
61main:
62 for (pos1 < length1) && (pos2 < length2) {
63 s1 := x1.highlowcontainer.getKeyAtIndex(pos1)
64 s2 := x2.highlowcontainer.getKeyAtIndex(pos2)
65
66 for {
67 if s1 < s2 {
68 pos1++
69 if pos1 == length1 {
70 break main
71 }
72 s1 = x1.highlowcontainer.getKeyAtIndex(pos1)
73 } else if s1 > s2 {
74 x1.highlowcontainer.insertNewKeyValueAt(pos1, s2, x2.highlowcontainer.getContainerAtIndex(pos2).clone())
75 pos2++
76 pos1++
77 length1++
78 if pos2 == length2 {
79 break main
80 }
81 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
82 } else {
83 c1 := x1.highlowcontainer.getWritableContainerAtIndex(pos1)
84 // runContainer16.lazyIOR falls back to a slow ior path
85 // (O(N log R) per merged element); promote to bitmapContainer
86 // first, whose lazy union is O(1024) regardless of cardinality.
87 // See https://github.com/RoaringBitmap/roaring/issues/81.
88 if rc, ok := c1.(*runContainer16); ok && !rc.isFull() {
89 c1 = rc.toBitmapContainer()
90 }
91 x1.highlowcontainer.containers[pos1] = c1.lazyIOR(x2.highlowcontainer.getContainerAtIndex(pos2))
92 x1.highlowcontainer.needCopyOnWrite[pos1] = false
93 pos1++
94 pos2++
95 if (pos1 == length1) || (pos2 == length2) {
96 break main
97 }
98 s1 = x1.highlowcontainer.getKeyAtIndex(pos1)
99 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
100 }
101 }
102 }
103 if pos1 == length1 {
104 x1.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2)
105 }
106 return x1
107}
108
109// to be called after lazy aggregates
110func (x1 *Bitmap) repairAfterLazy() {

Callers

nothing calls this directly

Calls 10

cloneMethod · 0.65
isFullMethod · 0.65
lazyIORMethod · 0.65
sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
insertNewKeyValueAtMethod · 0.45
getContainerAtIndexMethod · 0.45
toBitmapContainerMethod · 0.45
appendCopyManyMethod · 0.45

Tested by

no test coverage detected