Xor computes the symmetric difference between two bitmaps and returns the result
(x1, x2 *Bitmap)
| 1831 | |
| 1832 | // Xor computes the symmetric difference between two bitmaps and returns the result |
| 1833 | func 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 |
| 1873 | func AndNot(x1, x2 *Bitmap) *Bitmap { |