rust/library
Michael Goulet fb45513126
Rollup merge of #107522 - Sp00ph:introselect, r=Amanieu
Add Median of Medians fallback to introselect

Fixes #102451.

This PR is a follow up to #106997. It adds a Fast Deterministic Selection implementation as a fallback to the introselect algorithm used by `select_nth_unstable`. This allows it to guarantee O(n) worst case running time, while maintaining good performance in all cases.

This would fix #102451, which was opened because the `select_nth_unstable` docs falsely claimed that it had O(n) worst case performance, even though it was actually quadratic in the worst case. #106997 improved the worst case complexity to O(n log n) by using heapsort as a fallback, and this PR further improves it to O(n) (this would also make #106933 unnecessary).
It also improves the actual runtime if the fallback gets called: Using a pathological input of size `1 << 19` (see the playground link in #102451), calculating the median is roughly 3x faster using fast deterministic selection as a fallback than it is using heapsort.

The downside to this is less code reuse between the sorting and selection algorithms, but I don't think it's that bad. The additional algorithms are ~250 LOC with no `unsafe` blocks (I tried using unsafe to avoid bounds checks but it didn't noticeably improve the performance).
I also let it fuzz for a while against the current `select_nth_unstable` implementation to ensure correctness, and it seems to still fulfill all the necessary postconditions.

cc `@scottmcm` who reviewed #106997
2023-05-25 13:57:59 -07:00
..
alloc Auto merge of #86844 - bjorn3:global_alloc_improvements, r=pnkfelix 2023-05-25 16:59:57 +00:00
backtrace@4245978ca8 PS Vita std support 2023-05-07 18:57:43 +03:00
core Rollup merge of #107522 - Sp00ph:introselect, r=Amanieu 2023-05-25 13:57:59 -07:00
panic_abort
panic_unwind
portable-simd Hide repr attribute from doc of types without guaranteed repr 2023-05-16 10:00:52 -07:00
proc_macro
profiler_builtins
rtstartup
rustc-std-workspace-alloc
rustc-std-workspace-core
rustc-std-workspace-std
std Roll compiler_builtins to 0.1.92 2023-05-23 11:14:50 -04:00
stdarch@7e2cdc675b stdarch: update submodule, take 5 2023-05-08 19:03:55 +09:00
sysroot
test libtest: Improve error when missing -Zunstable-options 2023-05-24 11:18:20 -05:00
unwind