You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "git-hulk (via GitHub)" <gi...@apache.org> on 2023/06/21 01:23:09 UTC

[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #1502: Add support of the new command ZUNION

git-hulk commented on code in PR #1502:
URL: https://github.com/apache/incubator-kvrocks/pull/1502#discussion_r1236169700


##########
src/types/redis_zset.cc:
##########
@@ -744,16 +754,20 @@ rocksdb::Status ZSet::UnionStore(const Slice &dst, const std::vector<KeyWeight>
       }
     }
   }
-  if (!dst_zset.empty()) {
-    std::vector<MemberScore> mscores;
-    mscores.reserve(dst_zset.size());
+  auto compare_score = [](const MemberScore &score1, const MemberScore &score2) {
+    if (score1.score == score2.score) {
+      return score1.member < score2.member;
+    }
+    return score1.score < score2.score;
+  };
+  if (members && !dst_zset.empty()) {
+    members->reserve(dst_zset.size());
     for (const auto &iter : dst_zset) {
-      mscores.emplace_back(MemberScore{iter.first, iter.second});
+      members->emplace_back(MemberScore{iter.first, iter.second});
     }
-    if (saved_cnt) *saved_cnt = mscores.size();
-    Overwrite(dst, mscores);
+    if (saved_cnt) *saved_cnt = members->size();
+    std::sort(members->begin(), members->end(), compare_score);

Review Comment:
   Sorry, maybe I misunderstand your previous comment. We don't need to sort members here, because the underlying storage will sort them.



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org