AndNot computes the difference between two bitmaps and stores the result in the current bitmap
(x2 *Bitmap)
| 718 | |
| 719 | // AndNot computes the difference between two bitmaps and stores the result in the current bitmap |
| 720 | func (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 | |
| 727 | main: |
| 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++ |