AndNot computes the difference between two bitmaps and stores the result in the current bitmap
(x2 *Bitmap)
| 1672 | |
| 1673 | // AndNot computes the difference between two bitmaps and stores the result in the current bitmap |
| 1674 | func (rb *Bitmap) AndNot(x2 *Bitmap) { |
| 1675 | if rb == x2 { |
| 1676 | rb.Clear() |
| 1677 | return |
| 1678 | } |
| 1679 | pos1 := 0 |
| 1680 | pos2 := 0 |
| 1681 | intersectionsize := 0 |
| 1682 | length1 := rb.highlowcontainer.size() |
| 1683 | length2 := x2.highlowcontainer.size() |
| 1684 | |
| 1685 | main: |
| 1686 | for { |
| 1687 | if pos1 < length1 && pos2 < length2 { |
| 1688 | s1 := rb.highlowcontainer.getKeyAtIndex(pos1) |
| 1689 | s2 := x2.highlowcontainer.getKeyAtIndex(pos2) |
| 1690 | for { |
| 1691 | if s1 == s2 { |
| 1692 | c1 := rb.highlowcontainer.getWritableContainerAtIndex(pos1) |
| 1693 | c2 := x2.highlowcontainer.getContainerAtIndex(pos2) |
| 1694 | diff := c1.iandNot(c2) |
| 1695 | if !diff.isEmpty() { |
| 1696 | rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, diff, false) |
| 1697 | intersectionsize++ |
| 1698 | } |
| 1699 | pos1++ |
| 1700 | pos2++ |
| 1701 | if (pos1 == length1) || (pos2 == length2) { |
| 1702 | break main |
| 1703 | } |
| 1704 | s1 = rb.highlowcontainer.getKeyAtIndex(pos1) |
| 1705 | s2 = x2.highlowcontainer.getKeyAtIndex(pos2) |
| 1706 | } else if s1 < s2 { |
| 1707 | c1 := rb.highlowcontainer.getContainerAtIndex(pos1) |
| 1708 | mustCopyOnWrite := rb.highlowcontainer.needsCopyOnWrite(pos1) |
| 1709 | rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, c1, mustCopyOnWrite) |
| 1710 | intersectionsize++ |
| 1711 | pos1++ |
| 1712 | if pos1 == length1 { |
| 1713 | break main |
| 1714 | } |
| 1715 | s1 = rb.highlowcontainer.getKeyAtIndex(pos1) |
| 1716 | } else { // s1 > s2 |
| 1717 | pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) |
| 1718 | if pos2 == length2 { |
| 1719 | break main |
| 1720 | } |
| 1721 | s2 = x2.highlowcontainer.getKeyAtIndex(pos2) |
| 1722 | } |
| 1723 | } |
| 1724 | } else { |
| 1725 | break |
| 1726 | } |
| 1727 | } |
| 1728 | // TODO:implement as a copy |
| 1729 | for pos1 < length1 { |
| 1730 | c1 := rb.highlowcontainer.getContainerAtIndex(pos1) |
| 1731 | s1 := rb.highlowcontainer.getKeyAtIndex(pos1) |