Or computes the union between two bitmaps and returns the result
(x1, x2 *Bitmap)
| 1739 | |
| 1740 | // Or computes the union between two bitmaps and returns the result |
| 1741 | func Or(x1, x2 *Bitmap) *Bitmap { |
| 1742 | answer := NewBitmap() |
| 1743 | pos1 := 0 |
| 1744 | pos2 := 0 |
| 1745 | length1 := x1.highlowcontainer.size() |
| 1746 | length2 := x2.highlowcontainer.size() |
| 1747 | main: |
| 1748 | for (pos1 < length1) && (pos2 < length2) { |
| 1749 | s1 := x1.highlowcontainer.getKeyAtIndex(pos1) |
| 1750 | s2 := x2.highlowcontainer.getKeyAtIndex(pos2) |
| 1751 | |
| 1752 | for { |
| 1753 | if s1 < s2 { |
| 1754 | answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1) |
| 1755 | pos1++ |
| 1756 | if pos1 == length1 { |
| 1757 | break main |
| 1758 | } |
| 1759 | s1 = x1.highlowcontainer.getKeyAtIndex(pos1) |
| 1760 | } else if s1 > s2 { |
| 1761 | answer.highlowcontainer.appendCopy(x2.highlowcontainer, pos2) |
| 1762 | pos2++ |
| 1763 | if pos2 == length2 { |
| 1764 | break main |
| 1765 | } |
| 1766 | s2 = x2.highlowcontainer.getKeyAtIndex(pos2) |
| 1767 | } else { |
| 1768 | answer.highlowcontainer.appendContainer(s1, x1.highlowcontainer.getContainerAtIndex(pos1).or(x2.highlowcontainer.getContainerAtIndex(pos2)), false) |
| 1769 | pos1++ |
| 1770 | pos2++ |
| 1771 | if (pos1 == length1) || (pos2 == length2) { |
| 1772 | break main |
| 1773 | } |
| 1774 | s1 = x1.highlowcontainer.getKeyAtIndex(pos1) |
| 1775 | s2 = x2.highlowcontainer.getKeyAtIndex(pos2) |
| 1776 | } |
| 1777 | } |
| 1778 | } |
| 1779 | if pos1 == length1 { |
| 1780 | answer.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2) |
| 1781 | } else if pos2 == length2 { |
| 1782 | answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1) |
| 1783 | } |
| 1784 | return answer |
| 1785 | } |
| 1786 | |
| 1787 | // And computes the intersection between two bitmaps and returns the result |
| 1788 | func And(x1, x2 *Bitmap) *Bitmap { |