MCPcopy Index your code
hub / github.com/RoaringBitmap/roaring / Or

Function Or

roaring.go:1741–1785  ·  view source on GitHub ↗

Or computes the union between two bitmaps and returns the result

(x1, x2 *Bitmap)

Source from the content-addressed store, hash-verified

1739
1740// Or computes the union between two bitmaps and returns the result
1741func Or(x1, x2 *Bitmap) *Bitmap {
1742 answer := NewBitmap()
1743 pos1 := 0
1744 pos2 := 0
1745 length1 := x1.highlowcontainer.size()
1746 length2 := x2.highlowcontainer.size()
1747main:
1748 for (pos1 < length1) && (pos2 < length2) {
1749 s1 := x1.highlowcontainer.getKeyAtIndex(pos1)
1750 s2 := x2.highlowcontainer.getKeyAtIndex(pos2)
1751
1752 for {
1753 if s1 < s2 {
1754 answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1)
1755 pos1++
1756 if pos1 == length1 {
1757 break main
1758 }
1759 s1 = x1.highlowcontainer.getKeyAtIndex(pos1)
1760 } else if s1 > s2 {
1761 answer.highlowcontainer.appendCopy(x2.highlowcontainer, pos2)
1762 pos2++
1763 if pos2 == length2 {
1764 break main
1765 }
1766 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
1767 } else {
1768 answer.highlowcontainer.appendContainer(s1, x1.highlowcontainer.getContainerAtIndex(pos1).or(x2.highlowcontainer.getContainerAtIndex(pos2)), false)
1769 pos1++
1770 pos2++
1771 if (pos1 == length1) || (pos2 == length2) {
1772 break main
1773 }
1774 s1 = x1.highlowcontainer.getKeyAtIndex(pos1)
1775 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
1776 }
1777 }
1778 }
1779 if pos1 == length1 {
1780 answer.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2)
1781 } else if pos2 == length2 {
1782 answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1)
1783 }
1784 return answer
1785}
1786
1787// And computes the intersection between two bitmaps and returns the result
1788func And(x1, x2 *Bitmap) *Bitmap {

Callers 15

TestBitmapExtraCOWFunction · 0.70
TestBitmapCOWFunction · 0.70
TestXORtest4COWFunction · 0.70
rTestCOWFunction · 0.70
TestInPlaceCOWContainersFunction · 0.70
HeapOrFunction · 0.70
TestRoaring_OrThenAndFunction · 0.70
TestBitmapExtraFunction · 0.70
TestBitmapFunction · 0.70
TestXORtest4Function · 0.70
rTestFunction · 0.70

Calls 8

NewBitmapFunction · 0.70
orMethod · 0.65
sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
appendCopyMethod · 0.45
appendContainerMethod · 0.45
getContainerAtIndexMethod · 0.45
appendCopyManyMethod · 0.45

Tested by 15

TestBitmapExtraCOWFunction · 0.56
TestBitmapCOWFunction · 0.56
TestXORtest4COWFunction · 0.56
rTestCOWFunction · 0.56
TestInPlaceCOWContainersFunction · 0.56
TestRoaring_OrThenAndFunction · 0.56
TestBitmapExtraFunction · 0.56
TestBitmapFunction · 0.56
TestXORtest4Function · 0.56
rTestFunction · 0.56
TestBitmap_FromBufferFunction · 0.56