Intersects checks whether two bitmap intersects, bitmaps are not modified
(x2 *Bitmap)
| 585 | |
| 586 | // Intersects checks whether two bitmap intersects, bitmaps are not modified |
| 587 | func (rb *Bitmap) Intersects(x2 *Bitmap) bool { |
| 588 | pos1 := 0 |
| 589 | pos2 := 0 |
| 590 | length1 := rb.highlowcontainer.size() |
| 591 | length2 := x2.highlowcontainer.size() |
| 592 | |
| 593 | main: |
| 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 |
| 634 | func (rb *Bitmap) Xor(x2 *Bitmap) { |