-
Notifications
You must be signed in to change notification settings - Fork 557
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
Refactor BITPOS Implementation #1016
Conversation
2fbe7cd
to
5dde961
Compare
This is great; I couldn't find time for this. But one thing, there was a test which I couldn't pass last try, and this one doesn't seem to pass it either (maybe I got the test wrong). Try applying this diff manually (or via git apply). It adds a few lines to BitmapBitPosOffsetsTest test.
You'd expect referring to the same positions (in different syntax) lead to the same result? Yet the test fails:
(I also tried with a randomized seed a couple of times just to be sure it always passes and couldn't clear all seeds). |
Yeah, there were a couple of boundary conditions missing. Thanks for sharing this test. I added the fix and your unit test and it seems to pass now. |
It turns out the distribution of the default seed is somehow very specific. I tried a few, and they pass consistently except for one case: when startOffset equals endOffset. Didn't find problems when that was excluded.
Result is:
(bit output actually can differ in redis, but only when end argument isn't applied and the result is extended past end of string. This isn't the case in this test, so likely a bug.) |
The seed needs to be specific because the unit tests need to be deterministic. |
I'm aware of the seed requirement (it would be a bad idea to change it), I'm just using this to verify. Now, the bitops implementation is naive, yet the exception is on the bit test. So the byte test 'passed' with the same result as the naive implementation - which suggests a BYTE range and an equivalent BIT range returned a different result. I don't think this should be happening when the end offset is specified? Edit: Ah, but the redis BYTE range includes the entire byte when the naive bit range is limited to a bit? So it's not the same range exactly. I was wrong here, sorry. |
Yes, I was about to explain that. Cool, if you find something else let me know. It has been tricky to test it extensively and you did a great job providing feedback. |
a7574ea
to
62ece05
Compare
I compared with a Redis implementation and couldn't find differences when start end arguments are given and identical regardless of bit/byte. |
This PR fixes the BITPOS to support BIT search correctly.