diff options
| author | Michael Goulet <michael@errs.io> | 2023-05-25 13:57:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-25 13:57:59 -0700 |
| commit | fb45513126298a32a43be5e19910a60e983a7d5c (patch) | |
| tree | b6477c966041c2f898f966187ebc94c997622344 /compiler/rustc_interface/src/errors.rs | |
| parent | a2b1646c597329d0a25efa3889b66650f65de1de (diff) | |
| parent | fd5fa012e9bf38b3655d2a076d0f67b058367096 (diff) | |
| download | rust-fb45513126298a32a43be5e19910a60e983a7d5c.tar.gz rust-fb45513126298a32a43be5e19910a60e983a7d5c.zip | |
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
Diffstat (limited to 'compiler/rustc_interface/src/errors.rs')
0 files changed, 0 insertions, 0 deletions
