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

Function AndNot

roaring.go:1873–1926  ·  view source on GitHub ↗

AndNot computes the difference between two bitmaps and returns the result

(x1, x2 *Bitmap)

Source from the content-addressed store, hash-verified

1871
1872// AndNot computes the difference between two bitmaps and returns the result
1873func AndNot(x1, x2 *Bitmap) *Bitmap {
1874 if x1 == x2 {
1875 return NewBitmap()
1876 }
1877 answer := NewBitmap()
1878 pos1 := 0
1879 pos2 := 0
1880 length1 := x1.highlowcontainer.size()
1881 length2 := x2.highlowcontainer.size()
1882
1883main:
1884 for {
1885 if pos1 < length1 && pos2 < length2 {
1886 s1 := x1.highlowcontainer.getKeyAtIndex(pos1)
1887 s2 := x2.highlowcontainer.getKeyAtIndex(pos2)
1888 for {
1889 if s1 < s2 {
1890 answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1)
1891 pos1++
1892 if pos1 == length1 {
1893 break main
1894 }
1895 s1 = x1.highlowcontainer.getKeyAtIndex(pos1)
1896 } else if s1 == s2 {
1897 c1 := x1.highlowcontainer.getContainerAtIndex(pos1)
1898 c2 := x2.highlowcontainer.getContainerAtIndex(pos2)
1899 diff := c1.andNot(c2)
1900 if !diff.isEmpty() {
1901 answer.highlowcontainer.appendContainer(s1, diff, false)
1902 }
1903 pos1++
1904 pos2++
1905 if (pos1 == length1) || (pos2 == length2) {
1906 break main
1907 }
1908 s1 = x1.highlowcontainer.getKeyAtIndex(pos1)
1909 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
1910 } else { // s1 > s2
1911 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2)
1912 if pos2 == length2 {
1913 break main
1914 }
1915 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
1916 }
1917 }
1918 } else {
1919 break
1920 }
1921 }
1922 if pos2 == length2 {
1923 answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1)
1924 }
1925 return answer
1926}
1927
1928// AddMany add all of the values in dat
1929func (rb *Bitmap) AddMany(dat []uint32) {

Callers 10

TestBitmapExtraCOWFunction · 0.70
TestBitmapCOWFunction · 0.70
rTestCOWFunction · 0.70
TestAndNotCOWFunction · 0.70
TestBitmapExtraFunction · 0.70
TestBitmapFunction · 0.70
rTestFunction · 0.70
TestAndNotFunction · 0.70
TestBitmap_FromBufferFunction · 0.70
BenchmarkAndNotFunction · 0.70

Calls 10

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

Tested by 10

TestBitmapExtraCOWFunction · 0.56
TestBitmapCOWFunction · 0.56
rTestCOWFunction · 0.56
TestAndNotCOWFunction · 0.56
TestBitmapExtraFunction · 0.56
TestBitmapFunction · 0.56
rTestFunction · 0.56
TestAndNotFunction · 0.56
TestBitmap_FromBufferFunction · 0.56
BenchmarkAndNotFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…