Fix radix_sort_by_key for desc order #593
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This should fix #588.
Now in radix sort when
greater<T>()
is specified as comparison function (desc order) instead of performing asc-ordered radix sort and then reversing the result, descending radix sort is performed.It's done by negating input value if its type is a signed type and by subtracting the input value from the maximum value of value's type in other cases (in
radix()
function). That way values seem "reversed" and we get desc order. It should also be faster than sorting in asc order and then reversing the result.I also added some test for desc-ordered radix sort and radix sort by key.