@@ -280,7 +280,6 @@ pub struct BinaryHeap<
280
280
data: Vec<T, A>,
281
281
}
282
282
283
- // XXX: PeekMut<A>
284
283
/// Structure wrapping a mutable reference to the greatest item on a
285
284
/// `BinaryHeap`.
286
285
///
@@ -289,8 +288,12 @@ pub struct BinaryHeap<
289
288
///
290
289
/// [`peek_mut`]: BinaryHeap::peek_mut
291
290
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
292
- pub struct PeekMut<'a, T: 'a + Ord> {
293
- heap: &'a mut BinaryHeap<T>,
291
+ pub struct PeekMut<
292
+ 'a,
293
+ T: 'a + Ord,
294
+ #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
295
+ > {
296
+ heap: &'a mut BinaryHeap<T, A>,
294
297
// If a set_len + sift_down are required, this is Some. If a &mut T has not
295
298
// yet been exposed to peek_mut()'s caller, it's None.
296
299
original_len: Option<NonZeroUsize>,
@@ -359,11 +362,10 @@ impl<'a, T: Ord, A: Allocator + 'a> DerefMut for PeekMut<'a, T, A> {
359
362
}
360
363
}
361
364
362
- // XXX: PeekMut<A>
363
365
impl<'a, T: Ord, A: Allocator + 'a> PeekMut<'a, T, A> {
364
366
/// Removes the peeked value from the heap and returns it.
365
367
#[stable(feature = "binary_heap_peek_mut_pop", since = "1.18.0")]
366
- pub fn pop(mut this: PeekMut<'a, T>) -> T {
368
+ pub fn pop(mut this: PeekMut<'a, T, A >) -> T {
367
369
if let Some(original_len) = this.original_len.take() {
368
370
// SAFETY: This is how many elements were in the Vec at the time of
369
371
// the BinaryHeap::peek_mut call.
@@ -404,18 +406,21 @@ impl<T: fmt::Debug, A: Allocator> fmt::Debug for BinaryHeap<T, A> {
404
406
}
405
407
}
406
408
407
- struct RebuildOnDrop<'a, T: Ord> {
408
- heap: &'a mut BinaryHeap<T>,
409
+ struct RebuildOnDrop<
410
+ 'a,
411
+ T: Ord,
412
+ #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
413
+ > {
414
+ heap: &'a mut BinaryHeap<T, A>,
409
415
rebuild_from: usize,
410
416
}
411
417
412
- impl<'a, T: Ord> Drop for RebuildOnDrop<'a, T> {
418
+ impl<'a, T: Ord, A: Allocator > Drop for RebuildOnDrop<'a, T, A > {
413
419
fn drop(&mut self) {
414
420
self.heap.rebuild_tail(self.rebuild_from);
415
421
}
416
422
}
417
423
418
- // XXX: BinaryHeap<T, A>
419
424
impl<T: Ord> BinaryHeap<T> {
420
425
/// Creates an empty `BinaryHeap` as a max-heap.
421
426
///
@@ -501,7 +506,6 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
501
506
BinaryHeap { data: Vec::with_capacity_in(capacity, alloc) }
502
507
}
503
508
504
- // XXX: peek_mut
505
509
/// Returns a mutable reference to the greatest item in the binary heap, or
506
510
/// `None` if it is empty.
507
511
///
@@ -533,7 +537,7 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
533
537
/// If the item is modified then the worst case time complexity is *O*(log(*n*)),
534
538
/// otherwise it's *O*(1).
535
539
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
536
- pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T>> {
540
+ pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T, A >> {
537
541
if self.is_empty() {
538
542
None
539
543
} else {
@@ -1813,7 +1817,7 @@ impl<T: Ord, A: Allocator> Extend<T> for BinaryHeap<T, A> {
1813
1817
}
1814
1818
1815
1819
#[stable(feature = "extend_ref", since = "1.2.0")]
1816
- impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BinaryHeap<T> {
1820
+ impl<'a, T: 'a + Ord + Copy, A: Allocator > Extend<&'a T> for BinaryHeap<T, A > {
1817
1821
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
1818
1822
self.extend(iter.into_iter().cloned());
1819
1823
}
0 commit comments