-
Notifications
You must be signed in to change notification settings - Fork 232
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
Clarify In-Place operation semantics #308
Comments
The |
This may not be explicit but I think it is well defined. Both ... which is not to say that we can't do better... maybe we should....
Can you elaborate? It is typically faster and simpler to unconditionally set a value. Additional branches make the code harder to read, to maintain and typically slower. I am not saying you are wrong. However, it seems like if we are going to refactor (a time intensive proposal), one would like to get simpler code as a result... not more complicated code. if we really want to make it explicit, then I submit to you that we can think of other means, like...
That would be quite explicit then... Please understand that I am not arguing... I just want to push back a little so I can better understand what you are proposing. |
I realized AndAny's issues when I refactored array.ior(run) to potentially return a new run container. At first I thought I had found a bug but because of when those unchecked ior calls are made it will always work. BUT, that is only because of a bunch of implementation dependent choices, and the general contract allows for implementations that break it. Then, I looked at the various implementations, and they seemed to generally attempt to modify the receiver. I'd also be happy to just make explicit that receiver may not be modified |
That is the contract for |
Been fooling around with optimizing in-place operations, in particular if we can do better with run containers. My interest is in solutions that are performant both in terms of calculations and allocations. Right now, the semantics for container calls like
ior()
andiand()
are not well specified. They always return a container, that container will always be the union/intersection and it will usually, but not always, be the receiving struct. This ambiguity is mainly handled by always using the returned value, such as at https://github.com/RoaringBitmap/roaring/blob/master/roaring.go#L731 or https://github.com/RoaringBitmap/roaring/blob/master/roaring.go#L554. However, in at least one place we perform a naked ior(), which breaks if the underlying container is not updated with the union result.My suggestion is to change the semantics so that iand() etc. return
nil
when the container was actually updated in-place, and a non-nil result value when it wasn't. The downside is that the code would be slightly more verbose. For example, instead ofit'd be
The main advantages are that it would be more explicit and not have to always reset the value in the bitmap.
It'd be a good piece of work to refactor everywhere, so figured I'd get feedback first.
The text was updated successfully, but these errors were encountered: