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

Method Intersects

roaring.go:1538–1582  ·  view source on GitHub ↗

Intersects checks whether two bitmap intersects, bitmaps are not modified

(x2 *Bitmap)

Source from the content-addressed store, hash-verified

1536
1537// Intersects checks whether two bitmap intersects, bitmaps are not modified
1538func (rb *Bitmap) Intersects(x2 *Bitmap) bool {
1539 pos1 := 0
1540 pos2 := 0
1541 length1 := rb.highlowcontainer.size()
1542 length2 := x2.highlowcontainer.size()
1543
1544main:
1545 for {
1546 if pos1 < length1 && pos2 < length2 {
1547 s1 := rb.highlowcontainer.getKeyAtIndex(pos1)
1548 s2 := x2.highlowcontainer.getKeyAtIndex(pos2)
1549 for {
1550 if s1 == s2 {
1551 c1 := rb.highlowcontainer.getContainerAtIndex(pos1)
1552 c2 := x2.highlowcontainer.getContainerAtIndex(pos2)
1553 if c1.intersects(c2) {
1554 return true
1555 }
1556 pos1++
1557 pos2++
1558 if (pos1 == length1) || (pos2 == length2) {
1559 break main
1560 }
1561 s1 = rb.highlowcontainer.getKeyAtIndex(pos1)
1562 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
1563 } else if s1 < s2 {
1564 pos1 = rb.highlowcontainer.advanceUntil(s2, pos1)
1565 if pos1 == length1 {
1566 break main
1567 }
1568 s1 = rb.highlowcontainer.getKeyAtIndex(pos1)
1569 } else { // s1 > s2
1570 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2)
1571 if pos2 == length2 {
1572 break main
1573 }
1574 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
1575 }
1576 }
1577 } else {
1578 break
1579 }
1580 }
1581 return false
1582}
1583
1584// Xor computes the symmetric difference between two bitmaps and stores the result in the current bitmap
1585func (rb *Bitmap) Xor(x2 *Bitmap) {

Callers 4

TestIntersects1COWFunction · 0.95
TestIntersects1Function · 0.95
smatIntersectsFunction · 0.45
TestRoaringIntervalCheckFunction · 0.45

Calls 5

intersectsMethod · 0.65
sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
getContainerAtIndexMethod · 0.45
advanceUntilMethod · 0.45

Tested by 3

TestIntersects1COWFunction · 0.76
TestIntersects1Function · 0.76
TestRoaringIntervalCheckFunction · 0.36