Skip to content
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

Feature Request: Different Sort Options for Scores #17

Open
H-Shafiei opened this issue Sep 26, 2022 · 6 comments
Open

Feature Request: Different Sort Options for Scores #17

H-Shafiei opened this issue Sep 26, 2022 · 6 comments
Labels
good first issue Good for newcomers

Comments

@H-Shafiei
Copy link

Hi, Thanks for your nice work!

I think there might be a use case for having different scores being compared in independent orders. Let's say I want to create a leaderboard for my game and I have a highscore with an ascending score (meaning the higher the score, the higher the rank) and for the same scores I would compare the time of the score (which the lower the time the higher the rank). From what I see with your module, we have to accomplish this with saving either the time or the highscore with some math function to reverse it's meaning and then use the module. But because I think this feature would be used alot, It would be worth implementation. Can this be implemented?

Thanks

@RinChanNOWWW
Copy link
Contributor

we have to accomplish this with saving either the time or the highscore with some math function to reverse it's meaning and then use the module.

I think this is just the right way.

@H-Shafiei
Copy link
Author

That is one solution for sure; But why not add something to handle it inside the module? One way I can think of is we can add an option to express the sorting direction when creating a sortedset. For example I say the sort direction is 1#-1#1 which means for a score like score1#score2#score3, score1 and score3 are ordered in the same way and score2 is sorted in the opposite way (and change the way the are compared together based on that option). This is just a thought though

@RinChanNOWWW
Copy link
Contributor

cc @chenyang8094 @yangbodong22011

@yangbodong22011
Copy link
Member

we have to accomplish this with saving either the time or the highscore with some math function to reverse it's meaning and then use the module.

I think this is just the right way.

I think so too, and I don't think the syntax modification or increased memory footprint (need to store a collation) due to this requirement is worth doing at the moment.
Let's keep the issue open and wait for more feedback.

@chenyang8094
Copy link
Collaborator

chenyang8094 commented Sep 28, 2022

@H-Shafiei Thanks for your issue. Simple look, the command you need might be (with a sort option, only valid when tairzset is first created):

EXZADD key [NX|XX] [CH] [INCR] [SORT pattern] score member [score member ...]

where the pattern maybe 1#-1#1 or i#d#i etc.

This is indeed more flexible (to adapt to the sorting needs of different scenarios).

In addition to the syntax modification, we may also need to record this pattern in each TairZsetObj, so that we can keep this collation in subsequent writes. This will introduce a little memory overhead, but I don't think it will be huge (since it's key level, not every score).

But I still think this is a larger feature (functionally speaking). I also think we need more feedback, or you can try to submit a PR with your ideas, maybe that way we can discuss this better.

@chenyang8094 chenyang8094 added the good first issue Good for newcomers label Sep 28, 2022
@H-Shafiei
Copy link
Author

@chenyang8094 Yes that's exactly what I was thinking of and I think it won't have a considerable overhead.

I was reading the code in order to see if I can work on it but I haven't coded in C for a few years; although I can read the code but I am almost sure that I can't change it without hundreds of bugs rising up :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants