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

Method Intersects

roaring64/roaring64.go:587–631  ·  view source on GitHub ↗

Intersects checks whether two bitmap intersects, bitmaps are not modified

(x2 *Bitmap)

Source from the content-addressed store, hash-verified

585
586// Intersects checks whether two bitmap intersects, bitmaps are not modified
587func (rb *Bitmap) Intersects(x2 *Bitmap) bool {
588 pos1 := 0
589 pos2 := 0
590 length1 := rb.highlowcontainer.size()
591 length2 := x2.highlowcontainer.size()
592
593main:
594 for {
595 if pos1 < length1 && pos2 < length2 {
596 s1 := rb.highlowcontainer.getKeyAtIndex(pos1)
597 s2 := x2.highlowcontainer.getKeyAtIndex(pos2)
598 for {
599 if s1 == s2 {
600 c1 := rb.highlowcontainer.getContainerAtIndex(pos1)
601 c2 := x2.highlowcontainer.getContainerAtIndex(pos2)
602 if c1.Intersects(c2) {
603 return true
604 }
605 pos1++
606 pos2++
607 if (pos1 == length1) || (pos2 == length2) {
608 break main
609 }
610 s1 = rb.highlowcontainer.getKeyAtIndex(pos1)
611 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
612 } else if s1 < s2 {
613 pos1 = rb.highlowcontainer.advanceUntil(s2, pos1)
614 if pos1 == length1 {
615 break main
616 }
617 s1 = rb.highlowcontainer.getKeyAtIndex(pos1)
618 } else { // s1 > s2
619 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2)
620 if pos2 == length2 {
621 break main
622 }
623 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
624 }
625 }
626 } else {
627 break
628 }
629 }
630 return false
631}
632
633// Xor computes the symmetric difference between two bitmaps and stores the result in the current bitmap
634func (rb *Bitmap) Xor(x2 *Bitmap) {

Callers 3

TestIntersects1COWFunction · 0.95
TestIntersects1Function · 0.95
TestRoaringIntervalCheckFunction · 0.45

Calls 4

sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
getContainerAtIndexMethod · 0.45
advanceUntilMethod · 0.45

Tested by 3

TestIntersects1COWFunction · 0.76
TestIntersects1Function · 0.76
TestRoaringIntervalCheckFunction · 0.36