Skip to content

Commit de1ff0a

Browse files
committedJun 13, 2023
Auto merge of #99339 - yanchith:binary-heap-ta, r=Amanieu
Make BinaryHeap parametric over Allocator Tracking issue: #32838 Related: rust-lang/wg-allocators#7 This parametrizes `BinaryHeap` with `A`, similarly to how other collections are parametrized. A couple things I left out: ``` BinaryHeap::append Currently requires both structures to have the same allocator type. Could change, but depends on Vec::append, which has the same constraints. impl<T: Ord> Default for BinaryHeap<T> Not parametrized, because there's nowhere to conjure the allocator from. impl<T: Ord> FromIterator<T> for BinaryHeap<T> Not parametrized, because there's nowhere to conjure the allocator from. impl<T: Ord, const N: usize> From<[T; N]> for BinaryHeap<T> Not parametrized, because there's nowhere to conjure the allocator from. unsafe impl<I> AsVecIntoIter for IntoIter<I> AsVecIntoIter is not allocator aware, and I didn't dare change it without guidance. Is this something important? ``` I've seen very few tests for allocator_api in general, but I'd like to at least test this on some usage code in my projects before moving forward. EDIT: Updated the list of impls and functions that are not affected by this. `BinaryHeap` no longer has a `SpecExtend` impl, and prior work made implementing `Extend` possible.
2 parents 5e8c53f + e0e355d commit de1ff0a

File tree

1 file changed

+175
-63
lines changed
  • library/alloc/src/collections/binary_heap

1 file changed

+175
-63
lines changed
 

‎library/alloc/src/collections/binary_heap/mod.rs

Lines changed: 175 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,15 @@
143143
#![allow(missing_docs)]
144144
#![stable(feature = "rust1", since = "1.0.0")]
145145

146+
use core::alloc::Allocator;
146147
use core::fmt;
147148
use core::iter::{FusedIterator, InPlaceIterable, SourceIter, TrustedLen};
148149
use core::mem::{self, swap, ManuallyDrop};
149150
use core::num::NonZeroUsize;
150151
use core::ops::{Deref, DerefMut};
151152
use core::ptr;
152153

154+
use crate::alloc::Global;
153155
use crate::collections::TryReserveError;
154156
use crate::slice;
155157
use crate::vec::{self, AsVecIntoIter, Vec};
@@ -271,8 +273,11 @@ mod tests;
271273
/// [peek\_mut]: BinaryHeap::peek_mut
272274
#[stable(feature = "rust1", since = "1.0.0")]
273275
#[cfg_attr(not(test), rustc_diagnostic_item = "BinaryHeap")]
274-
pub struct BinaryHeap<T> {
275-
data: Vec<T>,
276+
pub struct BinaryHeap<
277+
T,
278+
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
279+
> {
280+
data: Vec<T, A>,
276281
}
277282

278283
/// Structure wrapping a mutable reference to the greatest item on a
@@ -283,22 +288,26 @@ pub struct BinaryHeap<T> {
283288
///
284289
/// [`peek_mut`]: BinaryHeap::peek_mut
285290
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
286-
pub struct PeekMut<'a, T: 'a + Ord> {
287-
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>,
288297
// If a set_len + sift_down are required, this is Some. If a &mut T has not
289298
// yet been exposed to peek_mut()'s caller, it's None.
290299
original_len: Option<NonZeroUsize>,
291300
}
292301

293302
#[stable(feature = "collection_debug", since = "1.17.0")]
294-
impl<T: Ord + fmt::Debug> fmt::Debug for PeekMut<'_, T> {
303+
impl<T: Ord + fmt::Debug, A: Allocator> fmt::Debug for PeekMut<'_, T, A> {
295304
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
296305
f.debug_tuple("PeekMut").field(&self.heap.data[0]).finish()
297306
}
298307
}
299308

300309
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
301-
impl<T: Ord> Drop for PeekMut<'_, T> {
310+
impl<T: Ord, A: Allocator> Drop for PeekMut<'_, T, A> {
302311
fn drop(&mut self) {
303312
if let Some(original_len) = self.original_len {
304313
// SAFETY: That's how many elements were in the Vec at the time of
@@ -315,7 +324,7 @@ impl<T: Ord> Drop for PeekMut<'_, T> {
315324
}
316325

317326
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
318-
impl<T: Ord> Deref for PeekMut<'_, T> {
327+
impl<T: Ord, A: Allocator> Deref for PeekMut<'_, T, A> {
319328
type Target = T;
320329
fn deref(&self) -> &T {
321330
debug_assert!(!self.heap.is_empty());
@@ -325,7 +334,7 @@ impl<T: Ord> Deref for PeekMut<'_, T> {
325334
}
326335

327336
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
328-
impl<T: Ord> DerefMut for PeekMut<'_, T> {
337+
impl<T: Ord, A: Allocator> DerefMut for PeekMut<'_, T, A> {
329338
fn deref_mut(&mut self) -> &mut T {
330339
debug_assert!(!self.heap.is_empty());
331340

@@ -353,10 +362,10 @@ impl<T: Ord> DerefMut for PeekMut<'_, T> {
353362
}
354363
}
355364

356-
impl<'a, T: Ord> PeekMut<'a, T> {
365+
impl<'a, T: Ord, A: Allocator> PeekMut<'a, T, A> {
357366
/// Removes the peeked value from the heap and returns it.
358367
#[stable(feature = "binary_heap_peek_mut_pop", since = "1.18.0")]
359-
pub fn pop(mut this: PeekMut<'a, T>) -> T {
368+
pub fn pop(mut this: PeekMut<'a, T, A>) -> T {
360369
if let Some(original_len) = this.original_len.take() {
361370
// SAFETY: This is how many elements were in the Vec at the time of
362371
// the BinaryHeap::peek_mut call.
@@ -371,7 +380,7 @@ impl<'a, T: Ord> PeekMut<'a, T> {
371380
}
372381

373382
#[stable(feature = "rust1", since = "1.0.0")]
374-
impl<T: Clone> Clone for BinaryHeap<T> {
383+
impl<T: Clone, A: Allocator + Clone> Clone for BinaryHeap<T, A> {
375384
fn clone(&self) -> Self {
376385
BinaryHeap { data: self.data.clone() }
377386
}
@@ -391,18 +400,22 @@ impl<T: Ord> Default for BinaryHeap<T> {
391400
}
392401

393402
#[stable(feature = "binaryheap_debug", since = "1.4.0")]
394-
impl<T: fmt::Debug> fmt::Debug for BinaryHeap<T> {
403+
impl<T: fmt::Debug, A: Allocator> fmt::Debug for BinaryHeap<T, A> {
395404
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
396405
f.debug_list().entries(self.iter()).finish()
397406
}
398407
}
399408

400-
struct RebuildOnDrop<'a, T: Ord> {
401-
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>,
402415
rebuild_from: usize,
403416
}
404417

405-
impl<'a, T: Ord> Drop for RebuildOnDrop<'a, T> {
418+
impl<T: Ord, A: Allocator> Drop for RebuildOnDrop<'_, T, A> {
406419
fn drop(&mut self) {
407420
self.heap.rebuild_tail(self.rebuild_from);
408421
}
@@ -446,6 +459,52 @@ impl<T: Ord> BinaryHeap<T> {
446459
pub fn with_capacity(capacity: usize) -> BinaryHeap<T> {
447460
BinaryHeap { data: Vec::with_capacity(capacity) }
448461
}
462+
}
463+
464+
impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
465+
/// Creates an empty `BinaryHeap` as a max-heap, using `A` as allocator.
466+
///
467+
/// # Examples
468+
///
469+
/// Basic usage:
470+
///
471+
/// ```
472+
/// #![feature(allocator_api)]
473+
///
474+
/// use std::alloc::System;
475+
/// use std::collections::BinaryHeap;
476+
/// let mut heap = BinaryHeap::new_in(System);
477+
/// heap.push(4);
478+
/// ```
479+
#[unstable(feature = "allocator_api", issue = "32838")]
480+
#[must_use]
481+
pub fn new_in(alloc: A) -> BinaryHeap<T, A> {
482+
BinaryHeap { data: Vec::new_in(alloc) }
483+
}
484+
485+
/// Creates an empty `BinaryHeap` with at least the specified capacity, using `A` as allocator.
486+
///
487+
/// The binary heap will be able to hold at least `capacity` elements without
488+
/// reallocating. This method is allowed to allocate for more elements than
489+
/// `capacity`. If `capacity` is 0, the binary heap will not allocate.
490+
///
491+
/// # Examples
492+
///
493+
/// Basic usage:
494+
///
495+
/// ```
496+
/// #![feature(allocator_api)]
497+
///
498+
/// use std::alloc::System;
499+
/// use std::collections::BinaryHeap;
500+
/// let mut heap = BinaryHeap::with_capacity_in(10, System);
501+
/// heap.push(4);
502+
/// ```
503+
#[unstable(feature = "allocator_api", issue = "32838")]
504+
#[must_use]
505+
pub fn with_capacity_in(capacity: usize, alloc: A) -> BinaryHeap<T, A> {
506+
BinaryHeap { data: Vec::with_capacity_in(capacity, alloc) }
507+
}
449508

450509
/// Returns a mutable reference to the greatest item in the binary heap, or
451510
/// `None` if it is empty.
@@ -478,7 +537,7 @@ impl<T: Ord> BinaryHeap<T> {
478537
/// If the item is modified then the worst case time complexity is *O*(log(*n*)),
479538
/// otherwise it's *O*(1).
480539
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
481-
pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T>> {
540+
pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T, A>> {
482541
if self.is_empty() { None } else { Some(PeekMut { heap: self, original_len: None }) }
483542
}
484543

@@ -573,7 +632,7 @@ impl<T: Ord> BinaryHeap<T> {
573632
/// ```
574633
#[must_use = "`self` will be dropped if the result is not used"]
575634
#[stable(feature = "binary_heap_extras_15", since = "1.5.0")]
576-
pub fn into_sorted_vec(mut self) -> Vec<T> {
635+
pub fn into_sorted_vec(mut self) -> Vec<T, A> {
577636
let mut end = self.len();
578637
while end > 1 {
579638
end -= 1;
@@ -831,7 +890,7 @@ impl<T: Ord> BinaryHeap<T> {
831890
/// ```
832891
#[inline]
833892
#[unstable(feature = "binary_heap_drain_sorted", issue = "59278")]
834-
pub fn drain_sorted(&mut self) -> DrainSorted<'_, T> {
893+
pub fn drain_sorted(&mut self) -> DrainSorted<'_, T, A> {
835894
DrainSorted { inner: self }
836895
}
837896

@@ -874,7 +933,7 @@ impl<T: Ord> BinaryHeap<T> {
874933
}
875934
}
876935

877-
impl<T> BinaryHeap<T> {
936+
impl<T, A: Allocator> BinaryHeap<T, A> {
878937
/// Returns an iterator visiting all values in the underlying vector, in
879938
/// arbitrary order.
880939
///
@@ -911,7 +970,7 @@ impl<T> BinaryHeap<T> {
911970
/// assert_eq!(heap.into_iter_sorted().take(2).collect::<Vec<_>>(), [5, 4]);
912971
/// ```
913972
#[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")]
914-
pub fn into_iter_sorted(self) -> IntoIterSorted<T> {
973+
pub fn into_iter_sorted(self) -> IntoIterSorted<T, A> {
915974
IntoIterSorted { inner: self }
916975
}
917976

@@ -1178,10 +1237,17 @@ impl<T> BinaryHeap<T> {
11781237
/// ```
11791238
#[must_use = "`self` will be dropped if the result is not used"]
11801239
#[stable(feature = "binary_heap_extras_15", since = "1.5.0")]
1181-
pub fn into_vec(self) -> Vec<T> {
1240+
pub fn into_vec(self) -> Vec<T, A> {
11821241
self.into()
11831242
}
11841243

1244+
/// Returns a reference to the underlying allocator.
1245+
#[unstable(feature = "allocator_api", issue = "32838")]
1246+
#[inline]
1247+
pub fn allocator(&self) -> &A {
1248+
self.data.allocator()
1249+
}
1250+
11851251
/// Returns the length of the binary heap.
11861252
///
11871253
/// # Examples
@@ -1249,7 +1315,7 @@ impl<T> BinaryHeap<T> {
12491315
/// ```
12501316
#[inline]
12511317
#[stable(feature = "drain", since = "1.6.0")]
1252-
pub fn drain(&mut self) -> Drain<'_, T> {
1318+
pub fn drain(&mut self) -> Drain<'_, T, A> {
12531319
Drain { iter: self.data.drain(..) }
12541320
}
12551321

@@ -1419,19 +1485,30 @@ impl<T> FusedIterator for Iter<'_, T> {}
14191485
/// [`into_iter`]: BinaryHeap::into_iter
14201486
#[stable(feature = "rust1", since = "1.0.0")]
14211487
#[derive(Clone)]
1422-
pub struct IntoIter<T> {
1423-
iter: vec::IntoIter<T>,
1488+
pub struct IntoIter<
1489+
T,
1490+
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
1491+
> {
1492+
iter: vec::IntoIter<T, A>,
1493+
}
1494+
1495+
impl<T, A: Allocator> IntoIter<T, A> {
1496+
/// Returns a reference to the underlying allocator.
1497+
#[unstable(feature = "allocator_api", issue = "32838")]
1498+
pub fn allocator(&self) -> &A {
1499+
self.iter.allocator()
1500+
}
14241501
}
14251502

14261503
#[stable(feature = "collection_debug", since = "1.17.0")]
1427-
impl<T: fmt::Debug> fmt::Debug for IntoIter<T> {
1504+
impl<T: fmt::Debug, A: Allocator> fmt::Debug for IntoIter<T, A> {
14281505
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14291506
f.debug_tuple("IntoIter").field(&self.iter.as_slice()).finish()
14301507
}
14311508
}
14321509

14331510
#[stable(feature = "rust1", since = "1.0.0")]
1434-
impl<T> Iterator for IntoIter<T> {
1511+
impl<T, A: Allocator> Iterator for IntoIter<T, A> {
14351512
type Item = T;
14361513

14371514
#[inline]
@@ -1446,22 +1523,22 @@ impl<T> Iterator for IntoIter<T> {
14461523
}
14471524

14481525
#[stable(feature = "rust1", since = "1.0.0")]
1449-
impl<T> DoubleEndedIterator for IntoIter<T> {
1526+
impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
14501527
#[inline]
14511528
fn next_back(&mut self) -> Option<T> {
14521529
self.iter.next_back()
14531530
}
14541531
}
14551532

14561533
#[stable(feature = "rust1", since = "1.0.0")]
1457-
impl<T> ExactSizeIterator for IntoIter<T> {
1534+
impl<T, A: Allocator> ExactSizeIterator for IntoIter<T, A> {
14581535
fn is_empty(&self) -> bool {
14591536
self.iter.is_empty()
14601537
}
14611538
}
14621539

14631540
#[stable(feature = "fused", since = "1.26.0")]
1464-
impl<T> FusedIterator for IntoIter<T> {}
1541+
impl<T, A: Allocator> FusedIterator for IntoIter<T, A> {}
14651542

14661543
#[stable(feature = "default_iters", since = "1.70.0")]
14671544
impl<T> Default for IntoIter<T> {
@@ -1481,8 +1558,8 @@ impl<T> Default for IntoIter<T> {
14811558
// also refer to the vec::in_place_collect module documentation to get an overview
14821559
#[unstable(issue = "none", feature = "inplace_iteration")]
14831560
#[doc(hidden)]
1484-
unsafe impl<T> SourceIter for IntoIter<T> {
1485-
type Source = IntoIter<T>;
1561+
unsafe impl<T, A: Allocator> SourceIter for IntoIter<T, A> {
1562+
type Source = IntoIter<T, A>;
14861563

14871564
#[inline]
14881565
unsafe fn as_inner(&mut self) -> &mut Self::Source {
@@ -1492,7 +1569,7 @@ unsafe impl<T> SourceIter for IntoIter<T> {
14921569

14931570
#[unstable(issue = "none", feature = "inplace_iteration")]
14941571
#[doc(hidden)]
1495-
unsafe impl<I> InPlaceIterable for IntoIter<I> {}
1572+
unsafe impl<I, A: Allocator> InPlaceIterable for IntoIter<I, A> {}
14961573

14971574
unsafe impl<I> AsVecIntoIter for IntoIter<I> {
14981575
type Item = I;
@@ -1505,12 +1582,23 @@ unsafe impl<I> AsVecIntoIter for IntoIter<I> {
15051582
#[must_use = "iterators are lazy and do nothing unless consumed"]
15061583
#[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")]
15071584
#[derive(Clone, Debug)]
1508-
pub struct IntoIterSorted<T> {
1509-
inner: BinaryHeap<T>,
1585+
pub struct IntoIterSorted<
1586+
T,
1587+
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
1588+
> {
1589+
inner: BinaryHeap<T, A>,
1590+
}
1591+
1592+
impl<T, A: Allocator> IntoIterSorted<T, A> {
1593+
/// Returns a reference to the underlying allocator.
1594+
#[unstable(feature = "allocator_api", issue = "32838")]
1595+
pub fn allocator(&self) -> &A {
1596+
self.inner.allocator()
1597+
}
15101598
}
15111599

15121600
#[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")]
1513-
impl<T: Ord> Iterator for IntoIterSorted<T> {
1601+
impl<T: Ord, A: Allocator> Iterator for IntoIterSorted<T, A> {
15141602
type Item = T;
15151603

15161604
#[inline]
@@ -1526,13 +1614,13 @@ impl<T: Ord> Iterator for IntoIterSorted<T> {
15261614
}
15271615

15281616
#[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")]
1529-
impl<T: Ord> ExactSizeIterator for IntoIterSorted<T> {}
1617+
impl<T: Ord, A: Allocator> ExactSizeIterator for IntoIterSorted<T, A> {}
15301618

15311619
#[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")]
1532-
impl<T: Ord> FusedIterator for IntoIterSorted<T> {}
1620+
impl<T: Ord, A: Allocator> FusedIterator for IntoIterSorted<T, A> {}
15331621

15341622
#[unstable(feature = "trusted_len", issue = "37572")]
1535-
unsafe impl<T: Ord> TrustedLen for IntoIterSorted<T> {}
1623+
unsafe impl<T: Ord, A: Allocator> TrustedLen for IntoIterSorted<T, A> {}
15361624

15371625
/// A draining iterator over the elements of a `BinaryHeap`.
15381626
///
@@ -1542,12 +1630,24 @@ unsafe impl<T: Ord> TrustedLen for IntoIterSorted<T> {}
15421630
/// [`drain`]: BinaryHeap::drain
15431631
#[stable(feature = "drain", since = "1.6.0")]
15441632
#[derive(Debug)]
1545-
pub struct Drain<'a, T: 'a> {
1546-
iter: vec::Drain<'a, T>,
1633+
pub struct Drain<
1634+
'a,
1635+
T: 'a,
1636+
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
1637+
> {
1638+
iter: vec::Drain<'a, T, A>,
1639+
}
1640+
1641+
impl<T, A: Allocator> Drain<'_, T, A> {
1642+
/// Returns a reference to the underlying allocator.
1643+
#[unstable(feature = "allocator_api", issue = "32838")]
1644+
pub fn allocator(&self) -> &A {
1645+
self.iter.allocator()
1646+
}
15471647
}
15481648

15491649
#[stable(feature = "drain", since = "1.6.0")]
1550-
impl<T> Iterator for Drain<'_, T> {
1650+
impl<T, A: Allocator> Iterator for Drain<'_, T, A> {
15511651
type Item = T;
15521652

15531653
#[inline]
@@ -1562,22 +1662,22 @@ impl<T> Iterator for Drain<'_, T> {
15621662
}
15631663

15641664
#[stable(feature = "drain", since = "1.6.0")]
1565-
impl<T> DoubleEndedIterator for Drain<'_, T> {
1665+
impl<T, A: Allocator> DoubleEndedIterator for Drain<'_, T, A> {
15661666
#[inline]
15671667
fn next_back(&mut self) -> Option<T> {
15681668
self.iter.next_back()
15691669
}
15701670
}
15711671

15721672
#[stable(feature = "drain", since = "1.6.0")]
1573-
impl<T> ExactSizeIterator for Drain<'_, T> {
1673+
impl<T, A: Allocator> ExactSizeIterator for Drain<'_, T, A> {
15741674
fn is_empty(&self) -> bool {
15751675
self.iter.is_empty()
15761676
}
15771677
}
15781678

15791679
#[stable(feature = "fused", since = "1.26.0")]
1580-
impl<T> FusedIterator for Drain<'_, T> {}
1680+
impl<T, A: Allocator> FusedIterator for Drain<'_, T, A> {}
15811681

15821682
/// A draining iterator over the elements of a `BinaryHeap`.
15831683
///
@@ -1587,17 +1687,29 @@ impl<T> FusedIterator for Drain<'_, T> {}
15871687
/// [`drain_sorted`]: BinaryHeap::drain_sorted
15881688
#[unstable(feature = "binary_heap_drain_sorted", issue = "59278")]
15891689
#[derive(Debug)]
1590-
pub struct DrainSorted<'a, T: Ord> {
1591-
inner: &'a mut BinaryHeap<T>,
1690+
pub struct DrainSorted<
1691+
'a,
1692+
T: Ord,
1693+
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
1694+
> {
1695+
inner: &'a mut BinaryHeap<T, A>,
1696+
}
1697+
1698+
impl<'a, T: Ord, A: Allocator> DrainSorted<'a, T, A> {
1699+
/// Returns a reference to the underlying allocator.
1700+
#[unstable(feature = "allocator_api", issue = "32838")]
1701+
pub fn allocator(&self) -> &A {
1702+
self.inner.allocator()
1703+
}
15921704
}
15931705

15941706
#[unstable(feature = "binary_heap_drain_sorted", issue = "59278")]
1595-
impl<'a, T: Ord> Drop for DrainSorted<'a, T> {
1707+
impl<'a, T: Ord, A: Allocator> Drop for DrainSorted<'a, T, A> {
15961708
/// Removes heap elements in heap order.
15971709
fn drop(&mut self) {
1598-
struct DropGuard<'r, 'a, T: Ord>(&'r mut DrainSorted<'a, T>);
1710+
struct DropGuard<'r, 'a, T: Ord, A: Allocator>(&'r mut DrainSorted<'a, T, A>);
15991711

1600-
impl<'r, 'a, T: Ord> Drop for DropGuard<'r, 'a, T> {
1712+
impl<'r, 'a, T: Ord, A: Allocator> Drop for DropGuard<'r, 'a, T, A> {
16011713
fn drop(&mut self) {
16021714
while self.0.inner.pop().is_some() {}
16031715
}
@@ -1612,7 +1724,7 @@ impl<'a, T: Ord> Drop for DrainSorted<'a, T> {
16121724
}
16131725

16141726
#[unstable(feature = "binary_heap_drain_sorted", issue = "59278")]
1615-
impl<T: Ord> Iterator for DrainSorted<'_, T> {
1727+
impl<T: Ord, A: Allocator> Iterator for DrainSorted<'_, T, A> {
16161728
type Item = T;
16171729

16181730
#[inline]
@@ -1628,20 +1740,20 @@ impl<T: Ord> Iterator for DrainSorted<'_, T> {
16281740
}
16291741

16301742
#[unstable(feature = "binary_heap_drain_sorted", issue = "59278")]
1631-
impl<T: Ord> ExactSizeIterator for DrainSorted<'_, T> {}
1743+
impl<T: Ord, A: Allocator> ExactSizeIterator for DrainSorted<'_, T, A> {}
16321744

16331745
#[unstable(feature = "binary_heap_drain_sorted", issue = "59278")]
1634-
impl<T: Ord> FusedIterator for DrainSorted<'_, T> {}
1746+
impl<T: Ord, A: Allocator> FusedIterator for DrainSorted<'_, T, A> {}
16351747

16361748
#[unstable(feature = "trusted_len", issue = "37572")]
1637-
unsafe impl<T: Ord> TrustedLen for DrainSorted<'_, T> {}
1749+
unsafe impl<T: Ord, A: Allocator> TrustedLen for DrainSorted<'_, T, A> {}
16381750

16391751
#[stable(feature = "binary_heap_extras_15", since = "1.5.0")]
1640-
impl<T: Ord> From<Vec<T>> for BinaryHeap<T> {
1752+
impl<T: Ord, A: Allocator> From<Vec<T, A>> for BinaryHeap<T, A> {
16411753
/// Converts a `Vec<T>` into a `BinaryHeap<T>`.
16421754
///
16431755
/// This conversion happens in-place, and has *O*(*n*) time complexity.
1644-
fn from(vec: Vec<T>) -> BinaryHeap<T> {
1756+
fn from(vec: Vec<T, A>) -> BinaryHeap<T, A> {
16451757
let mut heap = BinaryHeap { data: vec };
16461758
heap.rebuild();
16471759
heap
@@ -1665,12 +1777,12 @@ impl<T: Ord, const N: usize> From<[T; N]> for BinaryHeap<T> {
16651777
}
16661778

16671779
#[stable(feature = "binary_heap_extras_15", since = "1.5.0")]
1668-
impl<T> From<BinaryHeap<T>> for Vec<T> {
1780+
impl<T, A: Allocator> From<BinaryHeap<T, A>> for Vec<T, A> {
16691781
/// Converts a `BinaryHeap<T>` into a `Vec<T>`.
16701782
///
16711783
/// This conversion requires no data movement or allocation, and has
16721784
/// constant time complexity.
1673-
fn from(heap: BinaryHeap<T>) -> Vec<T> {
1785+
fn from(heap: BinaryHeap<T, A>) -> Vec<T, A> {
16741786
heap.data
16751787
}
16761788
}
@@ -1683,9 +1795,9 @@ impl<T: Ord> FromIterator<T> for BinaryHeap<T> {
16831795
}
16841796

16851797
#[stable(feature = "rust1", since = "1.0.0")]
1686-
impl<T> IntoIterator for BinaryHeap<T> {
1798+
impl<T, A: Allocator> IntoIterator for BinaryHeap<T, A> {
16871799
type Item = T;
1688-
type IntoIter = IntoIter<T>;
1800+
type IntoIter = IntoIter<T, A>;
16891801

16901802
/// Creates a consuming iterator, that is, one that moves each value out of
16911803
/// the binary heap in arbitrary order. The binary heap cannot be used
@@ -1705,13 +1817,13 @@ impl<T> IntoIterator for BinaryHeap<T> {
17051817
/// println!("{x}");
17061818
/// }
17071819
/// ```
1708-
fn into_iter(self) -> IntoIter<T> {
1820+
fn into_iter(self) -> IntoIter<T, A> {
17091821
IntoIter { iter: self.data.into_iter() }
17101822
}
17111823
}
17121824

17131825
#[stable(feature = "rust1", since = "1.0.0")]
1714-
impl<'a, T> IntoIterator for &'a BinaryHeap<T> {
1826+
impl<'a, T, A: Allocator> IntoIterator for &'a BinaryHeap<T, A> {
17151827
type Item = &'a T;
17161828
type IntoIter = Iter<'a, T>;
17171829

@@ -1721,7 +1833,7 @@ impl<'a, T> IntoIterator for &'a BinaryHeap<T> {
17211833
}
17221834

17231835
#[stable(feature = "rust1", since = "1.0.0")]
1724-
impl<T: Ord> Extend<T> for BinaryHeap<T> {
1836+
impl<T: Ord, A: Allocator> Extend<T> for BinaryHeap<T, A> {
17251837
#[inline]
17261838
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
17271839
let guard = RebuildOnDrop { rebuild_from: self.len(), heap: self };
@@ -1740,7 +1852,7 @@ impl<T: Ord> Extend<T> for BinaryHeap<T> {
17401852
}
17411853

17421854
#[stable(feature = "extend_ref", since = "1.2.0")]
1743-
impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BinaryHeap<T> {
1855+
impl<'a, T: 'a + Ord + Copy, A: Allocator> Extend<&'a T> for BinaryHeap<T, A> {
17441856
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
17451857
self.extend(iter.into_iter().cloned());
17461858
}

0 commit comments

Comments
 (0)
Please sign in to comment.