Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement in-place xOrProduceAnd() #261

Open
jacksonrnewhouse opened this issue Jul 22, 2020 · 2 comments
Open

Implement in-place xOrProduceAnd() #261

jacksonrnewhouse opened this issue Jul 22, 2020 · 2 comments

Comments

@jacksonrnewhouse
Copy link

jacksonrnewhouse commented Jul 22, 2020

The pseudocode for addDigit in #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 {}
@lemire
Copy link
Member

lemire commented Jul 22, 2020

This is an example of a ternary logical operation.

I agree.

@jacksonrnewhouse
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants