PragmaTwice commented on code in PR #2262:
URL: https://github.com/apache/kvrocks/pull/2262#discussion_r1574466135
##########
src/storage/redis_db.h:
##########
@@ -23,13 +23,44 @@
#include <map>
#include <string>
#include <utility>
+#include <variant>
#include <vector>
#include "redis_metadata.h"
+#include "server/redis_reply.h"
#include "storage.h"
namespace redis {
+struct SortArgument {
+ std::string sortby; // BY
+ bool dontsort = false; // DONT SORT
+ int offset = 0; // LIMIT OFFSET
+ int count = -1; // LIMIT COUNT
+ std::vector<std::string> getpatterns; // GET
+ bool desc = false; // ASC/DESC
+ bool alpha = false; // ALPHA
+ std::string storekey; // STORE
+};
+
+struct RedisSortObject {
+ std::string obj;
+ std::variant<double, std::string> v;
+};
+
+/// SortCompare is a helper function that enables `RedisSortObject` to be
sorted based on `SortArgument`.
+///
+/// It can assist in implementing the third parameter `Compare comp` required
by `std::sort`
+///
+/// \param args The basis used to compare two RedisSortObjects.
+/// If `args.alpha` is false, `RedisSortObject.v` will be taken as double for
comparison
+/// If `args.alpha` is true and `args.sortby` is not empty,
`RedisSortObject.v` will be taken as string for comparison
+/// If `args.alpha` is true and `args.sortby` is empty, the comparison is by
`RedisSortObject.obj`.
+///
+/// \return If `desc` is false, returns true when `a < b`, otherwise returns
true when `a > b`
+
+bool SortCompare(const RedisSortObject &a, const RedisSortObject &b, const
SortArgument &args);
Review Comment:
I think this function can be a static (or friend) member function of
`RedisSortObject`.
--
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]