MCPcopy Create free account
hub / github.com/RoaringBitmap/roaring / Xor

Function Xor

roaring64/roaring64.go:873–907  ·  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

871
872// Xor computes the symmetric difference between two bitmaps and returns the result
873func Xor(x1, x2 *Bitmap) *Bitmap {
874 answer := NewBitmap()
875 pos1 := 0
876 pos2 := 0
877 length1 := x1.highlowcontainer.size()
878 length2 := x2.highlowcontainer.size()
879 for {
880 if (pos1 < length1) && (pos2 < length2) {
881 s1 := x1.highlowcontainer.getKeyAtIndex(pos1)
882 s2 := x2.highlowcontainer.getKeyAtIndex(pos2)
883 if s1 < s2 {
884 answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1)
885 pos1++
886 } else if s1 > s2 {
887 answer.highlowcontainer.appendCopy(x2.highlowcontainer, pos2)
888 pos2++
889 } else {
890 c := roaring.Xor(x1.highlowcontainer.getContainerAtIndex(pos1), x2.highlowcontainer.getContainerAtIndex(pos2))
891 if !c.IsEmpty() {
892 answer.highlowcontainer.appendContainer(s1, c, false)
893 }
894 pos1++
895 pos2++
896 }
897 } else {
898 break
899 }
900 }
901 if pos1 == length1 {
902 answer.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2)
903 } else if pos2 == length2 {
904 answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1)
905 }
906 return answer
907}
908
909// AndNot computes the difference between two bitmaps and returns the result
910func AndNot(x1, x2 *Bitmap) *Bitmap {

Callers 9

TestBitmapExtraCOWFunction · 0.70
TestBitmapCOWFunction · 0.70
TestXORtest4COWFunction · 0.70
rTestCOWFunction · 0.70
testAggregationsFunction · 0.70
TestBitmapExtraFunction · 0.70
TestBitmapFunction · 0.70
TestXORtest4Function · 0.70
rTestFunction · 0.70

Calls 9

NewBitmapFunction · 0.70
sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
appendCopyMethod · 0.45
XorMethod · 0.45
getContainerAtIndexMethod · 0.45
IsEmptyMethod · 0.45
appendContainerMethod · 0.45
appendCopyManyMethod · 0.45

Tested by 9

TestBitmapExtraCOWFunction · 0.56
TestBitmapCOWFunction · 0.56
TestXORtest4COWFunction · 0.56
rTestCOWFunction · 0.56
testAggregationsFunction · 0.56
TestBitmapExtraFunction · 0.56
TestBitmapFunction · 0.56
TestXORtest4Function · 0.56
rTestFunction · 0.56