torwig commented on code in PR #1444:
URL:
https://github.com/apache/incubator-kvrocks/pull/1444#discussion_r1197814030
##########
tests/cppunit/types/set_test.cc:
##########
@@ -191,6 +191,23 @@ TEST_F(RedisSetTest, Inter) {
set_->Del(k3);
}
+TEST_F(RedisSetTest, InterCard) {
Review Comment:
Additionally, you can add a test for a corner/edge case when one of the sets
is empty. And one for the case when there are no common elements in both sets.
##########
src/types/redis_set.cc:
##########
@@ -338,19 +338,42 @@ rocksdb::Status Set::Inter(const std::vector<Slice>
&keys, std::vector<std::stri
for (const auto &member : target_members) {
member_counters[member] = 1;
}
+
+ bool has_limit = limit > 0;
for (size_t i = 1; i < keys.size(); i++) {
s = Members(keys[i], &target_members);
if (!s.ok() || target_members.empty()) return s;
for (const auto &member : target_members) {
- if (member_counters.find(member) == member_counters.end()) continue;
+ if (member_counters.count(member) == 0) continue;
member_counters[member]++;
+ if (has_limit && member_counters[member] == keys.size()) {
+ members->emplace_back(member);
+ if (--limit == 0) {
+ limit = -1;
Review Comment:
Maybe the following code should be considered as a loop break:
```
if (has_limit && member_counters[member] == keys.size()) {
members->emplace_back(member);
if (members->size() >= limit) {
break;
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]