-
Notifications
You must be signed in to change notification settings - Fork 13.3k
implement sort for VecDeque #69400
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
implement sort for VecDeque #69400
Conversation
r? @KodrAus (rust_highfive has picked a reviewer for you, use r? to override) |
An alternative implementation may not need one continuous slice. This could be prevented by changing the deque to not be continuous after sorting: pub fn sort_by<F>(&mut self, compare: F)
where
F: FnMut(&T, &T) -> Ordering,
{
self.make_continuous();
self.as_mut_slices().0.sort_by(compare);
if self.len() % 3 == 1 {
self.make_noncontinuous();
}
} |
0d50d93
to
9f43c18
Compare
I temporarily added I think that it would be easiest to move |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
I experimented with first sorting the two slices and then merging them instead of one continuous sort. Not quite sure on how compare the performance of both implementations before this PR is merged, as I can't easily implement the sorting done in this PR outside of liballoc. See https://github.com/lcnr/vecdeque My current merge is also still broken and needs |
This makes me wonder if |
superseded by #69425 |
I would personally still be in favour of sorting methods on |
By using I don't think that adding 7 more methods to |
add fn make_contiguous to VecDeque Adds the following method to VecDeque: ```rust pub fn make_contiguous(&mut self) -> &mut [T]; ``` Taken from rust-lang#69400, after a suggestion by @CryZe rust-lang#69400 (comment) I am in favor of merging this instead of rust-lang#69400.
closes #27322.
I have currently only implemented
sort_by
. If this change is desired,I will gladly add the other sort methods:
sort
sort_by_key
,sort_by_cached_key
sort_unstable
sort_unstable_by
sort_unstable_by_key