Uh oh!
There was an error while loading. Please reload this page.
Add 'partition_at_index/_by/_by_key' for slices. - #55448
Conversation
rust-highfive
commented
Oct 28, 2018
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @bluss (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
TimNN
commented
Nov 6, 2018
Ping from triage @bluss / @rust-lang/libs: This PR requires your review. |
SimonSapin
commented
Nov 6, 2018
@Mokosha, can you say more about why this is useful? What’s an example of a situation where you’d use this? @rust-lang/libs, thoughts on having this feature in the standard library? It’s apparently already available on crates.io rust-lang/rfcs#1470 (comment) |
@SimonSapin I have two separate use-cases in my own projects, both involving selecting the median of a dataset.
In the former I implemented quickselect myself because I couldn't find any crate implementing quickselect or any other kth-element algorithm when I wrote the code back in 2016. I didn't discover That's a major issue with saying "just use something from crates.io", sometimes people don't know what they're actually looking for or what keywords to search to find it. This is a fundamental enough operation that it should reside in the stdlib, where people are most likely to look first for solutions. In the latter because the dataset is a small, constant size and I needed to copy it to preserve the original ordering (potentially not necessary, I already see a possible optimization), I decided to just use the stdlib's sort and index the set directly. In both cases I would prefer a stdlib-provided implementation if it was available. In both cases it would probably be more optimal than the solutions I ended up going with, and importing an external crate just for one function at one use site in each case seemed like overkill (though in |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
alexcrichton
commented
Nov 7, 2018
This seems reasonable to me to add, pending bikeshedding the name/returns/etc |
Uh oh!
There was an error while loading. Please reload this page.
@Mokosha It looks like there's been a few review comments, can you take a look at those? |
Mokosha
commented
Nov 16, 2018
Yes. My apologies. I will take a look at these over the weekend. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Mokosha
commented
Nov 27, 2018
I haven't tested the changes, as I'm running into an issue building |
Mokosha
commented
Dec 2, 2018
All tests pass. :) Waiting for additional feedback. |
abonander
commented
Dec 4, 2018
@Mokosha they'll want the commits to be squashed before they merge. I don't have review permissions. |
Mokosha
commented
Dec 6, 2018
Is this something I'm in charge of? (Do I create a new PR that squashes the commits?) I thought that was an option when doing the merge... |
Merges aren't done directly through Github, I don't think bors will squash. You can do an interactive rebase against the parent commit of your first one, mark all subsequent commits as "fixup" and then force-push to your branch when the rebase is complete. The change in commits will be immediately reflected on the PR. |
bluss
commented
Dec 9, 2018
This seems good! The name doesn't feel intuitive to me (but not the operation either, so maybe I haven't used it anywhere). Name was discussed in rust-lang/rfcs/issues/1470. I think I understand this operation better as |
Mokosha
commented
Dec 9, 2018
I don't know which name is the most intuitive, honestly. The reason I didn't choose anything with |
Mark-Simulacrum
commented
Dec 9, 2018
Perhaps |
@Mark-Simulacrum It doesn't quite sort the first N elements. Rather, it chooses an index
|
Mark-Simulacrum
commented
Dec 9, 2018
Ah, okay. Then I think the partition naming is probably the best that I can think of -- and seems to jive okay with the other partition method on slices (https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.partition_dedup). If we do rename to the |
Mokosha
commented
Dec 11, 2018
OK -- good point about consistency. How about |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Would there be anything lost by using a fixed seed instead? IMO non-deterministic tests are an antipattern anyway. If you use something like |
Mokosha
commented
Mar 15, 2019
@RalfJung Probably not, but I'm matching the code already written in the test for |
RalfJung
commented
Mar 15, 2019
IMO they should, but that's up to @rust-lang/libs |
Centril
commented
Mar 30, 2019
Ping from triage, @scottmcm |
scottmcm
commented
Apr 2, 2019
@bors r=bluss |
bors
commented
Apr 2, 2019
📌 Commit 3f306db has been approved by |
bors
commented
Apr 2, 2019
⌛ Testing commit 3f306db with merge 8be24b37d498dbf7b85aef82b1007522a4b73cbc... |
bors
commented
Apr 2, 2019
💥 Test timed out |
kennytm
commented
Apr 2, 2019
@bors retry Double scheduling in two Travis builds. |
Add 'partition_at_index/_by/_by_key' for slices. This is an analog to C++'s std::nth_element (a.k.a. quickselect). Corresponds to tracking bug rust-lang#55300.
Add 'partition_at_index/_by/_by_key' for slices. This is an analog to C++'s std::nth_element (a.k.a. quickselect). Corresponds to tracking bug rust-lang#55300.
Mokosha
commented
Apr 3, 2019
Thank you to everyone who helped review this change and get it merged! |
This is an analog to C++'s std::nth_element (a.k.a. quickselect).
Corresponds to tracking bug #55300.