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

Method AndNot

roaring.go:1674–1738  ·  view source on GitHub ↗

AndNot computes the difference between two bitmaps and stores the result in the current bitmap

(x2 *Bitmap)

Source from the content-addressed store, hash-verified

1672
1673// AndNot computes the difference between two bitmaps and stores the result in the current bitmap
1674func (rb *Bitmap) AndNot(x2 *Bitmap) {
1675 if rb == x2 {
1676 rb.Clear()
1677 return
1678 }
1679 pos1 := 0
1680 pos2 := 0
1681 intersectionsize := 0
1682 length1 := rb.highlowcontainer.size()
1683 length2 := x2.highlowcontainer.size()
1684
1685main:
1686 for {
1687 if pos1 < length1 && pos2 < length2 {
1688 s1 := rb.highlowcontainer.getKeyAtIndex(pos1)
1689 s2 := x2.highlowcontainer.getKeyAtIndex(pos2)
1690 for {
1691 if s1 == s2 {
1692 c1 := rb.highlowcontainer.getWritableContainerAtIndex(pos1)
1693 c2 := x2.highlowcontainer.getContainerAtIndex(pos2)
1694 diff := c1.iandNot(c2)
1695 if !diff.isEmpty() {
1696 rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, diff, false)
1697 intersectionsize++
1698 }
1699 pos1++
1700 pos2++
1701 if (pos1 == length1) || (pos2 == length2) {
1702 break main
1703 }
1704 s1 = rb.highlowcontainer.getKeyAtIndex(pos1)
1705 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
1706 } else if s1 < s2 {
1707 c1 := rb.highlowcontainer.getContainerAtIndex(pos1)
1708 mustCopyOnWrite := rb.highlowcontainer.needsCopyOnWrite(pos1)
1709 rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, c1, mustCopyOnWrite)
1710 intersectionsize++
1711 pos1++
1712 if pos1 == length1 {
1713 break main
1714 }
1715 s1 = rb.highlowcontainer.getKeyAtIndex(pos1)
1716 } else { // s1 > s2
1717 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2)
1718 if pos2 == length2 {
1719 break main
1720 }
1721 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
1722 }
1723 }
1724 } else {
1725 break
1726 }
1727 }
1728 // TODO:implement as a copy
1729 for pos1 < length1 {
1730 c1 := rb.highlowcontainer.getContainerAtIndex(pos1)
1731 s1 := rb.highlowcontainer.getKeyAtIndex(pos1)

Callers 15

TestBitmapCOWFunction · 0.95
TestDoubleAddCOWFunction · 0.95
TestAndNotCOWFunction · 0.95
TestBitmapFunction · 0.95
TestDoubleAddFunction · 0.95
TestAndNotFunction · 0.95
TestExample2_roaring061Function · 0.45

Calls 11

ClearMethod · 0.95
iandNotMethod · 0.65
isEmptyMethod · 0.65
sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
getContainerAtIndexMethod · 0.45
needsCopyOnWriteMethod · 0.45
advanceUntilMethod · 0.45
resizeMethod · 0.45

Tested by 13

TestBitmapCOWFunction · 0.76
TestDoubleAddCOWFunction · 0.76
TestAndNotCOWFunction · 0.76
TestBitmapFunction · 0.76
TestDoubleAddFunction · 0.76
TestAndNotFunction · 0.76
TestExample2_roaring061Function · 0.36