Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for unstable sorting in const context #102307

Open
3 tasks
onestacked opened this issue Sep 26, 2022 · 1 comment
Open
3 tasks

Tracking Issue for unstable sorting in const context #102307

onestacked opened this issue Sep 26, 2022 · 1 comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@onestacked
Copy link
Contributor

onestacked commented Sep 26, 2022

Feature gate: #![feature(const_sort)]

This is a tracking issue for const slice::sort_unstable and sort_internals.

Public API

// core::slice

pub const fn heapsort<T, F>(v: &mut [T], mut is_less: F)
where
    F: ~const FnMut(&T, &T) -> bool + ~const Destruct;

pub const fn sort_unstable(&mut self)
    where
        T: ~const Ord;

 pub const fn sort_unstable_by<F>(&mut self, mut compare: F)
    where
        F: ~const FnMut(&T, &T) -> Ordering + ~const Destruct;

pub const fn sort_unstable_by_key<K, F>(&mut self, mut f: F)
    where
        F: ~const FnMut(&T) -> K + ~const Destruct,
        K: ~const Ord + ~const Destruct;

pub const fn select_nth_unstable(&mut self, index: usize) -> (&mut [T], &mut T, &mut [T])
    where
        T: ~const Ord;

 pub const fn select_nth_unstable_by<F>(
        &mut self,
        index: usize,
        mut compare: F,
    ) -> (&mut [T], &mut T, &mut [T])
    where
        F: ~const FnMut(&T, &T) -> Ordering + ~const Destruct;

pub const fn select_nth_unstable_by_key<K, F>(
        &mut self,
        index: usize,
        mut f: F,
    ) -> (&mut [T], &mut T, &mut [T])
    where
        F: ~const FnMut(&T) -> K + ~const Destruct,
        K: ~const Ord + ~const Destruct;

pub const fn is_sorted(&self) -> bool
    where
        T: ~const PartialOrd;

pub const fn is_sorted_by<F>(&self, mut compare: F) -> bool
    where
        F: ~const FnMut(&T, &T) -> Option<Ordering> + ~const Destruct;

pub const fn is_sorted_by_key<F, K>(&self, mut f: F) -> bool
    where
        F: ~const FnMut(&T) -> K + ~const Destruct,
        K: ~const PartialOrd + ~const Destruct;

slice::sort[_by[_key]] would need allocations in const context to be implemented. #79597

Steps / History

Unresolved Questions

Footnotes

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

@onestacked onestacked added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 26, 2022
@est31
Copy link
Member

est31 commented Sep 26, 2022

Can you maybe add ... in core to this? And mention why slice::sort is not included? I guess it's not included because it's in alloc due to using merge_sort which allocates internally. Edit: Resolved, thanks!

@onestacked onestacked changed the title Tracking Issue for sorting in const context Tracking Issue for unstable sorting in const context Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants