From 7a9f282528fe95e160b177b880e06cc5ca2a426a Mon Sep 17 00:00:00 2001 From: yanchith Date: Fri, 9 Jun 2023 11:48:11 +0200 Subject: [PATCH] Reallocatorize after merge --- .../alloc/src/collections/binary_heap/mod.rs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index f5e6bd20ea5..abc29b32bbc 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -280,7 +280,6 @@ pub struct BinaryHeap< data: Vec, } -// XXX: PeekMut /// Structure wrapping a mutable reference to the greatest item on a /// `BinaryHeap`. /// @@ -289,8 +288,12 @@ pub struct BinaryHeap< /// /// [`peek_mut`]: BinaryHeap::peek_mut #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")] -pub struct PeekMut<'a, T: 'a + Ord> { - heap: &'a mut BinaryHeap, +pub struct PeekMut< + 'a, + T: 'a + Ord, + #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, +> { + heap: &'a mut BinaryHeap, // If a set_len + sift_down are required, this is Some. If a &mut T has not // yet been exposed to peek_mut()'s caller, it's None. original_len: Option, @@ -359,11 +362,10 @@ impl<'a, T: Ord, A: Allocator + 'a> DerefMut for PeekMut<'a, T, A> { } } -// XXX: PeekMut impl<'a, T: Ord, A: Allocator + 'a> PeekMut<'a, T, A> { /// Removes the peeked value from the heap and returns it. #[stable(feature = "binary_heap_peek_mut_pop", since = "1.18.0")] - pub fn pop(mut this: PeekMut<'a, T>) -> T { + pub fn pop(mut this: PeekMut<'a, T, A>) -> T { if let Some(original_len) = this.original_len.take() { // SAFETY: This is how many elements were in the Vec at the time of // the BinaryHeap::peek_mut call. @@ -404,18 +406,21 @@ impl fmt::Debug for BinaryHeap { } } -struct RebuildOnDrop<'a, T: Ord> { - heap: &'a mut BinaryHeap, +struct RebuildOnDrop< + 'a, + T: Ord, + #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, +> { + heap: &'a mut BinaryHeap, rebuild_from: usize, } -impl<'a, T: Ord> Drop for RebuildOnDrop<'a, T> { +impl<'a, T: Ord, A: Allocator> Drop for RebuildOnDrop<'a, T, A> { fn drop(&mut self) { self.heap.rebuild_tail(self.rebuild_from); } } -// XXX: BinaryHeap impl BinaryHeap { /// Creates an empty `BinaryHeap` as a max-heap. /// @@ -501,7 +506,6 @@ impl BinaryHeap { BinaryHeap { data: Vec::with_capacity_in(capacity, alloc) } } - // XXX: peek_mut /// Returns a mutable reference to the greatest item in the binary heap, or /// `None` if it is empty. /// @@ -533,7 +537,7 @@ impl BinaryHeap { /// If the item is modified then the worst case time complexity is *O*(log(*n*)), /// otherwise it's *O*(1). #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")] - pub fn peek_mut(&mut self) -> Option> { + pub fn peek_mut(&mut self) -> Option> { if self.is_empty() { None } else { @@ -1813,7 +1817,7 @@ impl Extend for BinaryHeap { } #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BinaryHeap { +impl<'a, T: 'a + Ord + Copy, A: Allocator> Extend<&'a T> for BinaryHeap { fn extend>(&mut self, iter: I) { self.extend(iter.into_iter().cloned()); }