Change BITCOUNT 'end' as optional like BITPOS#118
Change BITCOUNT 'end' as optional like BITPOS#118hwware merged 12 commits intovalkey-io:unstablefrom
Conversation
338c5d1 to
ecbcc8b
Compare
3fbebc4 to
fd83b40
Compare
Signed-off-by: LiiNen <[email protected]>
Signed-off-by: LiiNen <[email protected]>
Signed-off-by: LiiNen <[email protected]>
in case of end is not declared, BYTE|BIT cannot be used, so variable 'isbit' is always 0 Signed-off-by: LiiNen <[email protected]>
Signed-off-by: LiiNen <[email protected]>
Signed-off-by: LiiNen <[email protected]>
Signed-off-by: LiiNen <[email protected]>
Signed-off-by: LiiNen <[email protected]>
Co-authored-by: Madelyn Olson <[email protected]> Signed-off-by: LiiNen <[email protected]>
fd83b40 to
729ec8b
Compare
|
rebase to avoid spellcheck issue: #139 |
|
seems like issues in testfile. I'll check it edited) p.s. I have changed it when I made PR to redis, but just missed it in here by human(my) fault 😅 |
Signed-off-by: LiiNen <[email protected]>
| assert_equal [r bitcount s 0] [count_bits "foobar"] | ||
| assert_equal [r bitcount s 1] [count_bits "oobar"] | ||
| assert_equal [r bitcount s -1] [count_bits "r"] | ||
| assert_equal [r bitcount s -2] [count_bits "ar"] |
There was a problem hiding this comment.
Could you please add several special cases which include larger value of start, such as start = 10 or 50, Thanks
There was a problem hiding this comment.
I'll add some new test cases in near days. thxs
There was a problem hiding this comment.
Added more testcases; 843c84a
- Larger value of start as you said
- Larger negative value of start.
- Also added large negative value in
BITCOUNT with start, end - fix [count_bits ""] -> 0, when start > end if it is in the range of string (line 147)
There was a problem hiding this comment.
note: you said larger value as 10 or 50 for example, but the value 1000 is already used from others, so I also use 1000 :)
There was a problem hiding this comment.
@hwware gently ping, just wondered if you didn't receive above comments alarm.
i hope it didn't bother you.
| "type": "pure-token", | ||
| "token": "BYTE" | ||
| "name": "end", | ||
| "type": "integer" |
There was a problem hiding this comment.
end is in optional block, so this is useless I think.
I saw syntax again and below is what I have changed.
BITPOS key bit [start [end [BYTE | BIT]]]
BITCOUNT key [start end [BYTE | BIT]] -> BITCOUNT key [start [end [BYTE | BIT]]]
If end is also optional, then the syntax should be like below:
BITCOUNT key [start [[end] [BYTE | BIT]]]
I didn't think it before, and it seems this is also maybe reasonable - allowing using just 'start' and '[BYTE | BIT]'.
But in this case, it is harmful for backwards compatibility, and maybe critical to client libraries.
ex. BITCOUNT key start BYTE will be think as BITCOUNT key start end in client libraries, and will be return error because end is just string 'BYTE'.
It will be a quiet issue. Is this what you meant?
|
You are right. Just ignore my suggestion code changes and keep current json file. |
|
But I doubt, maybe for BITPOS and BITCOUNT, the command format: Let us discuss this later |
|
I agree. If there is no need to consider backward compatibility, then me also want to change: using BYTE|BIT without In case of testcase, I'll work on it asap when i have time :) |
Signed-off-by: LiiNen <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## unstable #118 +/- ##
============================================
- Coverage 70.22% 70.19% -0.04%
============================================
Files 109 109
Lines 59880 59879 -1
============================================
- Hits 42051 42030 -21
- Misses 17829 17849 +20
|
We can solve this problem in the future. Discussed in separate meeting, directionally LGTM, just need someone to review the code and merge. |
|
seems like conflicts came out due to modifying language format (#323) |
Signed-off-by: LiiNen <[email protected]>
|
update done. while fixing conflict, found small typo against lint, so it also have been fixed. /* line 798 in src/bitops.c */
// before fix
if (c-> argc == 3
// after fix ( remove space between '>' and 'a' )
if (c->argc == 3 |
|
There is a clang-format issue from this commit found while trying to submit another commit - https://github.com/valkey-io/valkey/actions/runs/9279101016/job/25531813775. Can you fix it? diff --git a/src/bitops.c b/src/bitops.c
index 7a385812d..2094bb0ea 100644
--- a/src/bitops.c
+++ b/src/bitops.c
@@ -808,10 +808,9 @@ void bitcountCommand(client *c) {
}
}
if (c->argc >= 4) {
- if (getLongLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK)
- return;
+ if (getLongLongFromObjectOrReply(c, c->argv[3], &end, NULL) != C_OK) return;
}
-
+
/* Lookup, check for type. */
o = lookupKeyRead(c->db, c->argv[1]);
if (checkType(c, o, OBJ_STRING)) return;
@@ -821,7 +820,7 @@ void bitcountCommand(client *c) {
/* Make sure we will not overflow */
serverAssert(totlen <= LLONG_MAX >> 3);
- if (c->argc < 4) end = totlen-1;
+ if (c->argc < 4) end = totlen - 1;
/* Convert negative indexes */
if (start < 0 && end < 0 && start > end) { |
ref: - #118 (my pervious change) - #461 (issuing that clang format checker fails due to my change) There was an issue that clang-format cheker failed. I don't know why I missed it and why it didn't catch. just running `clang-format -i bitops.c` was all. Signed-off-by: LiiNen <[email protected]>

This change is the thing I suggested to redis when it was BSD, and is not just migration - this is of course more advanced
Issue
There is weird difference in syntax between BITPOS and BITCOUNT:
I think this might cause confusion in terms of usability.
It was not just a syntax typo error, and really works differently.
The results below are with unstable build:
What did I fix
simply changes logic, to accept BITCOUNT also without 'end' - 'end' become optional, like BITPOS
Of course, I also fixed syntax hint:
Moreover ...
I hadn't noticed that there was very small dead code in these command logic, when I wrote PR to redis.
I found it now, when write code again, so I wrote it in valkey.
Bit variable (actually int) "isbit" is only being set as 1, when 'BIT' is declared.
But we were checking whether 'isbit' is true or false in this 'if' phrase, even if isbit could never be 1, because argc is always less than 4 (or 5 in bitpos).
I think this minor fixes will make valkey command operation more consistent.
Of course, this PR contains just changing args from "required" to "optional", so it will never hurt previous users.
Thanks,