Skip to content

[ER] slice::partial_sort ? #94256

@leonardo-m

Description

@leonardo-m

In Rust code that uses Itertools I see code like

data.sorted().rev().take(3)...

Or more generally I see sorting + take. In such cases when the number of items to take is small it's better to use a faster algorithm that sorts only those few items. This is the partialSort() of the D language stdlib:

https://dlang.org/phobos/std_algorithm_sorting.html#partialSort

Currently in Rust this could be done efficiently using select_nth_unstable() followed by sort() of just the first items.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions