Implement in-place xOrProduceAnd()
The pseudocode for addDigit in https://github.com/RoaringBitmap/roaring/issues/260 includes the two lines
carry := roaring.And(bsi.bA[i], bitmap)
bsi.bA[i].Xor(bitmap)
And() and Xor() do basically the same operations. In both they iterate forward through the container keys, comparing them, then making a decision about should happen at each step. This could be optimized by doing both operations in a single pass. I'm not sure the best name for the method, but the signature would look like
func (bitmap *Bitmap) XorWithAndReturned(other *Bitmap) *Bitmap {}
This is an example of a ternary logical operation.
I agree.
I've given this some more thought, and I'm not sure a single method like that is the right approach. If you're trying to do addition with minimal allocation I think you want something that can do an add over the whole sequence of digits, performing container-level carries as necessary. Having gotten into the weeds of the various in-place And/Or/Xor I think there might be a clean way to do this, and I might give it a shot sometime next week.