Reallocatorize after merge

This commit is contained in:
yanchith 2023-06-09 11:48:11 +02:00
parent cb5c011670
commit 7a9f282528

View File

@ -280,7 +280,6 @@ pub struct BinaryHeap<
data: Vec<T, A>, data: Vec<T, A>,
} }
// XXX: PeekMut<A>
/// Structure wrapping a mutable reference to the greatest item on a /// Structure wrapping a mutable reference to the greatest item on a
/// `BinaryHeap`. /// `BinaryHeap`.
/// ///
@ -289,8 +288,12 @@ pub struct BinaryHeap<
/// ///
/// [`peek_mut`]: BinaryHeap::peek_mut /// [`peek_mut`]: BinaryHeap::peek_mut
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")] #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
pub struct PeekMut<'a, T: 'a + Ord> { pub struct PeekMut<
heap: &'a mut BinaryHeap<T>, 'a,
T: 'a + Ord,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
> {
heap: &'a mut BinaryHeap<T, A>,
// If a set_len + sift_down are required, this is Some. If a &mut T has not // 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. // yet been exposed to peek_mut()'s caller, it's None.
original_len: Option<NonZeroUsize>, original_len: Option<NonZeroUsize>,
@ -359,11 +362,10 @@ impl<'a, T: Ord, A: Allocator + 'a> DerefMut for PeekMut<'a, T, A> {
} }
} }
// XXX: PeekMut<A>
impl<'a, T: Ord, A: Allocator + 'a> PeekMut<'a, T, A> { impl<'a, T: Ord, A: Allocator + 'a> PeekMut<'a, T, A> {
/// Removes the peeked value from the heap and returns it. /// Removes the peeked value from the heap and returns it.
#[stable(feature = "binary_heap_peek_mut_pop", since = "1.18.0")] #[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() { if let Some(original_len) = this.original_len.take() {
// SAFETY: This is how many elements were in the Vec at the time of // SAFETY: This is how many elements were in the Vec at the time of
// the BinaryHeap::peek_mut call. // the BinaryHeap::peek_mut call.
@ -404,18 +406,21 @@ impl<T: fmt::Debug, A: Allocator> fmt::Debug for BinaryHeap<T, A> {
} }
} }
struct RebuildOnDrop<'a, T: Ord> { struct RebuildOnDrop<
heap: &'a mut BinaryHeap<T>, 'a,
T: Ord,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
> {
heap: &'a mut BinaryHeap<T, A>,
rebuild_from: usize, 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) { fn drop(&mut self) {
self.heap.rebuild_tail(self.rebuild_from); self.heap.rebuild_tail(self.rebuild_from);
} }
} }
// XXX: BinaryHeap<T, A>
impl<T: Ord> BinaryHeap<T> { impl<T: Ord> BinaryHeap<T> {
/// Creates an empty `BinaryHeap` as a max-heap. /// Creates an empty `BinaryHeap` as a max-heap.
/// ///
@ -501,7 +506,6 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
BinaryHeap { data: Vec::with_capacity_in(capacity, alloc) } BinaryHeap { data: Vec::with_capacity_in(capacity, alloc) }
} }
// XXX: peek_mut
/// Returns a mutable reference to the greatest item in the binary heap, or /// Returns a mutable reference to the greatest item in the binary heap, or
/// `None` if it is empty. /// `None` if it is empty.
/// ///
@ -533,7 +537,7 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
/// If the item is modified then the worst case time complexity is *O*(log(*n*)), /// If the item is modified then the worst case time complexity is *O*(log(*n*)),
/// otherwise it's *O*(1). /// otherwise it's *O*(1).
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")] #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T>> { pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T, A>> {
if self.is_empty() { if self.is_empty() {
None None
} else { } else {
@ -1813,7 +1817,7 @@ impl<T: Ord, A: Allocator> Extend<T> for BinaryHeap<T, A> {
} }
#[stable(feature = "extend_ref", since = "1.2.0")] #[stable(feature = "extend_ref", since = "1.2.0")]
impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BinaryHeap<T> { impl<'a, T: 'a + Ord + Copy, A: Allocator> Extend<&'a T> for BinaryHeap<T, A> {
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) { fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
self.extend(iter.into_iter().cloned()); self.extend(iter.into_iter().cloned());
} }