Skip to content

Tracking Issue for adding partial_sort_unstable to [T] #149046

@tisonkun

Description

@tisonkun

Feature gate: #![feature(slice_partial_sort_unstable)]

This is a tracking issue for rust-lang/libs-team#685.

Public API

impl<T> [T] {
  // `n` is the length of the sorted slice
  pub fn partial_sort_unstable<R>(&mut self, range: R) where T: Ord, R: RangeBounds<usize> { ... }
  pub fn partial_sort_unstable_by<F, R>(&mut self, range: R, mut compare: F) where F: FnMut(&T, &T) -> Ordering, R: RangeBounds<usize> { ... }
  pub fn partial_sort_unstable_by_key<K, F, R>(&mut self, range: R, mut f: F) where F: FnMut(&T) -> K, K: Ord, R: RangeBounds<usize>  { ... }
}

#[test]
fn demostration() {
    let mut before: Vec<u32> = vec![4, 4, 3, 3, 1, 1, 2, 2];
    let last = 6;
    let mut d = before.clone();
    d.sort();

    before.partial_sort_unstable_by(..last, |a, b| a.cmp(b));
    assert_eq!(&d[0..last], &before[0..last]);
}

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions