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

Add unstable sorting functions #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sunsided
Copy link
Contributor

@sunsided sunsided commented May 26, 2023

This adds the slice sorting functions sort_unstable, sort_unstable_by and sort_unstable_by_key.
These functions currently all take &mut self in order to make sure we have full control over the vector.

I added debug assertions around the borrow fields to check with you what to do - I assume the functions could return an error instead of panicking if any borrow currently exists.

The safety argument is that since no elements are currently borrowed, the vector is mutably borrowed itself and the length of the vector is not changed during the operation, we can safely access the individual elements without requiring a clone out of the cell.

The two functions sort_unstable_by and sort_unstable_by_key cannot be expressed in terms of each other due to the requirement T: Ord on only one of them, so I had to implement them twice. I sadly couldn't link the documentation to [T]::sort_unstable etc. due to issue rust-lang/rust#62968 and related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant