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

Method AndNot

roaring64/roaring64.go:720–780  ·  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

718
719// AndNot computes the difference between two bitmaps and stores the result in the current bitmap
720func (rb *Bitmap) AndNot(x2 *Bitmap) {
721 pos1 := 0
722 pos2 := 0
723 intersectionsize := 0
724 length1 := rb.highlowcontainer.size()
725 length2 := x2.highlowcontainer.size()
726
727main:
728 for {
729 if pos1 < length1 && pos2 < length2 {
730 s1 := rb.highlowcontainer.getKeyAtIndex(pos1)
731 s2 := x2.highlowcontainer.getKeyAtIndex(pos2)
732 for {
733 if s1 == s2 {
734 c1 := rb.highlowcontainer.getWritableContainerAtIndex(pos1)
735 c2 := x2.highlowcontainer.getContainerAtIndex(pos2)
736 c1.AndNot(c2)
737 if !c1.IsEmpty() {
738 rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, c1, false)
739 intersectionsize++
740 }
741 pos1++
742 pos2++
743 if (pos1 == length1) || (pos2 == length2) {
744 break main
745 }
746 s1 = rb.highlowcontainer.getKeyAtIndex(pos1)
747 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
748 } else if s1 < s2 {
749 c1 := rb.highlowcontainer.getContainerAtIndex(pos1)
750 mustCopyOnWrite := rb.highlowcontainer.needsCopyOnWrite(pos1)
751 rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, c1, mustCopyOnWrite)
752 intersectionsize++
753 pos1++
754 if pos1 == length1 {
755 break main
756 }
757 s1 = rb.highlowcontainer.getKeyAtIndex(pos1)
758 } else { // s1 > s2
759 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2)
760 if pos2 == length2 {
761 break main
762 }
763 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
764 }
765 }
766 } else {
767 break
768 }
769 }
770 // TODO:implement as a copy
771 for pos1 < length1 {
772 c1 := rb.highlowcontainer.getContainerAtIndex(pos1)
773 s1 := rb.highlowcontainer.getKeyAtIndex(pos1)
774 mustCopyOnWrite := rb.highlowcontainer.needsCopyOnWrite(pos1)
775 rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, c1, mustCopyOnWrite)
776 intersectionsize++
777 pos1++

Callers 10

TestBitmapCOWFunction · 0.95
TestDoubleAddCOWFunction · 0.95
TestAndNotCOWFunction · 0.95
TestBitmapFunction · 0.95
TestDoubleAddFunction · 0.95
TestAndNotFunction · 0.95
AndNotFunction · 0.45
SetBigManyMethod · 0.45
ClearBitsFunction · 0.45
ClearValuesMethod · 0.45

Calls 9

sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
getContainerAtIndexMethod · 0.45
IsEmptyMethod · 0.45
needsCopyOnWriteMethod · 0.45
advanceUntilMethod · 0.45
resizeMethod · 0.45

Tested by 6

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