Xor computes the symmetric difference between two bitmaps and returns the result
(x1, x2 *Bitmap)
| 871 | |
| 872 | // Xor computes the symmetric difference between two bitmaps and returns the result |
| 873 | func 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 |
| 910 | func AndNot(x1, x2 *Bitmap) *Bitmap { |