-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add selection algorithms nthElement
heapSelect
and median
#24414
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
base: master
Are you sure you want to change the base?
Conversation
Any thoughts on additional inclusion of sorting networks, particularly for finding things like median? Ref:
Disclaimer: I implemented some of the above in comptime for my video processing plugin: https://github.com/adworacz/zsmooth/blob/master/src/common/sorting_networks.zig |
|
EDIT: |
Since I didn't find anything from the math library that calculates a mean in an overflow safe manner, in the median function for integers it's now done with the common bit manipulation |
Selection algorithms come up from time to time, for example here: #9890
This pull request adds the following public functions to
std.select
. Is this the correct place or should we put them tostd.sort
even though they aren't exactly sorting algorithms?I tried to check how the current sorting algorithm work and more or less copy their behavior, but there are still couple of open questions.
nthElement
andheapSelect
, especiallyn
?median
good enough or what should be done to them?std.sort
orstd.sort.pdq
:partitionEqual
andsiftDown
should we share the implementations somehow?sort3
,chosePivot
,partition
Same as above, do we implement them here with the minor modifications (and possible minor speedups), but duplicate code?