-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add a Quicksort implementation. #15380
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
Conversation
Quicksort makes different tradeoffs than the existing merge sort: It does not allocate, but is not stable. Original implementation by @pcwalton: servo/servo@3764c3c49f
We have previously made the decision not to include multiple sorting routines in favor of one stable sort that works well. |
Agreed, exposing two methods for sorting on vectors by default can get confusing, especially when one sounds like it's faster than the other (quicksort vs sort). That being said, it is useful to be able to sort in libcore without the standard library. Can you elaborate more about why you'd like to add this, given our initial decision to not have multiple sorting routines? |
According to @pcwalton, memory allocation used to be a significant part of the time spent doing selector matching in Servo (which involves sorting CSS declarations by specificity). We switched to quicksort (which does not allocate) for speed. I understand the concern of having "competing" methods. What if I removed all the methods in this PR, so that it only adds a function? |
If the stdlib |
Do you mean an a library other than libcore in this repository, or outside of this repository? |
Outside of this repository |
Especially as Cargo comes along... Quicksort is the kind of thing that I wouldn't mind being in the standard library, as it isn't likely to change a whole lot, but just a thought. |
Should it be introsort (a quicksort variant) instead, to keep the same complexity even against maliciously constructed input? The C++ STL introsort is apparently very fast, so I guess the algorithm shouldn't cost any performance. |
We discussed this on IRC and the conclusion for now is that not having two sorts is the paramount concern here. Servo can definitely have its own sort, and we can possibly consider adding a variant to the standard library that works alongside the existing |
Fix unsized struct problems in mir eval
Quicksort makes different tradeoffs than the existing merge sort: It does not allocate, but is not stable.
r? @pcwalton