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

Function Xor

roaring.go:1833–1870  ·  view source on GitHub ↗

Xor computes the symmetric difference between two bitmaps and returns the result

(x1, x2 *Bitmap)

Source from the content-addressed store, hash-verified

1831
1832// Xor computes the symmetric difference between two bitmaps and returns the result
1833func Xor(x1, x2 *Bitmap) *Bitmap {
1834 if x1 == x2 {
1835 return NewBitmap()
1836 }
1837 answer := NewBitmap()
1838 pos1 := 0
1839 pos2 := 0
1840 length1 := x1.highlowcontainer.size()
1841 length2 := x2.highlowcontainer.size()
1842 for {
1843 if (pos1 < length1) && (pos2 < length2) {
1844 s1 := x1.highlowcontainer.getKeyAtIndex(pos1)
1845 s2 := x2.highlowcontainer.getKeyAtIndex(pos2)
1846 if s1 < s2 {
1847 answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1)
1848 pos1++
1849 } else if s1 > s2 {
1850 answer.highlowcontainer.appendCopy(x2.highlowcontainer, pos2)
1851 pos2++
1852 } else {
1853 c := x1.highlowcontainer.getContainerAtIndex(pos1).xor(x2.highlowcontainer.getContainerAtIndex(pos2))
1854 if !c.isEmpty() {
1855 answer.highlowcontainer.appendContainer(s1, c, false)
1856 }
1857 pos1++
1858 pos2++
1859 }
1860 } else {
1861 break
1862 }
1863 }
1864 if pos1 == length1 {
1865 answer.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2)
1866 } else if pos2 == length2 {
1867 answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1)
1868 }
1869 return answer
1870}
1871
1872// AndNot computes the difference between two bitmaps and returns the result
1873func AndNot(x1, x2 *Bitmap) *Bitmap {

Callers 14

TestBitmapExtraCOWFunction · 0.70
TestBitmapCOWFunction · 0.70
TestXORtest4COWFunction · 0.70
rTestCOWFunction · 0.70
HeapXorFunction · 0.70
TestBitmapExtraFunction · 0.70
TestBitmapFunction · 0.70
TestXORtest4Function · 0.70
rTestFunction · 0.70
TestFastAggregationsXORFunction · 0.70

Calls 9

NewBitmapFunction · 0.70
xorMethod · 0.65
isEmptyMethod · 0.65
sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
appendCopyMethod · 0.45
getContainerAtIndexMethod · 0.45
appendContainerMethod · 0.45
appendCopyManyMethod · 0.45

Tested by 13

TestBitmapExtraCOWFunction · 0.56
TestBitmapCOWFunction · 0.56
TestXORtest4COWFunction · 0.56
rTestCOWFunction · 0.56
TestBitmapExtraFunction · 0.56
TestBitmapFunction · 0.56
TestXORtest4Function · 0.56
rTestFunction · 0.56
TestFastAggregationsXORFunction · 0.56
TestBitmap_FromBufferFunction · 0.56