@@ -162,8 +162,6 @@ use core::ptr;
162
162
use slice;
163
163
use vec:: Vec ;
164
164
165
- // FIXME(conventions): implement into_iter
166
-
167
165
/// A priority queue implemented with a binary heap.
168
166
///
169
167
/// This will be a max-heap.
@@ -186,7 +184,6 @@ impl<T: Ord> BinaryHeap<T> {
186
184
/// use std::collections::BinaryHeap;
187
185
/// let pq: BinaryHeap<uint> = BinaryHeap::new();
188
186
/// ```
189
- #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
190
187
pub fn new ( ) -> BinaryHeap < T > { BinaryHeap { data : vec ! ( ) , } }
191
188
192
189
/// Creates an empty `BinaryHeap` with a specific capacity.
@@ -200,7 +197,6 @@ impl<T: Ord> BinaryHeap<T> {
200
197
/// use std::collections::BinaryHeap;
201
198
/// let pq: BinaryHeap<uint> = BinaryHeap::with_capacity(10u);
202
199
/// ```
203
- #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
204
200
pub fn with_capacity ( capacity : uint ) -> BinaryHeap < T > {
205
201
BinaryHeap { data : Vec :: with_capacity ( capacity) }
206
202
}
@@ -238,7 +234,6 @@ impl<T: Ord> BinaryHeap<T> {
238
234
/// println!("{}", x);
239
235
/// }
240
236
/// ```
241
- #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
242
237
pub fn iter < ' a > ( & ' a self ) -> Items < ' a , T > {
243
238
Items { iter : self . data . iter ( ) }
244
239
}
@@ -273,19 +268,10 @@ impl<T: Ord> BinaryHeap<T> {
273
268
/// let pq: BinaryHeap<uint> = BinaryHeap::with_capacity(100u);
274
269
/// assert!(pq.capacity() >= 100u);
275
270
/// ```
276
- #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
277
271
pub fn capacity ( & self ) -> uint { self . data . capacity ( ) }
278
272
279
- /// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
280
- /// given `BinaryHeap`. Does nothing if the capacity is already sufficient.
281
- ///
282
- /// Note that the allocator may give the collection more space than it requests. Therefore
283
- /// capacity can not be relied upon to be precisely minimal. Prefer `reserve` if future
284
- /// insertions are expected.
285
- ///
286
- /// # Panics
287
- ///
288
- /// Panics if the new capacity overflows `uint`.
273
+ /// Reserves capacity for exactly `n` elements in the `BinaryHeap`.
274
+ /// Do nothing if the capacity is already sufficient.
289
275
///
290
276
/// # Example
291
277
///
@@ -294,17 +280,12 @@ impl<T: Ord> BinaryHeap<T> {
294
280
///
295
281
/// let mut pq: BinaryHeap<uint> = BinaryHeap::new();
296
282
/// pq.reserve_exact(100u);
297
- /// assert!(pq.capacity() > = 100u);
283
+ /// assert!(pq.capacity() = = 100u);
298
284
/// ```
299
- #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
300
- pub fn reserve_exact ( & mut self , additional : uint ) { self . data . reserve_exact ( additional) }
285
+ pub fn reserve_exact ( & mut self , n : uint ) { self . data . reserve_exact ( n) }
301
286
302
- /// Reserves capacity for at least `additional` more elements to be inserted in the
303
- /// `BinaryHeap`. The collection may reserve more space to avoid frequent reallocations.
304
- ///
305
- /// # Panics
306
- ///
307
- /// Panics if the new capacity overflows `uint`.
287
+ /// Reserves capacity for at least `n` elements in the `BinaryHeap`.
288
+ /// Do nothing if the capacity is already sufficient.
308
289
///
309
290
/// # Example
310
291
///
@@ -315,15 +296,8 @@ impl<T: Ord> BinaryHeap<T> {
315
296
/// pq.reserve(100u);
316
297
/// assert!(pq.capacity() >= 100u);
317
298
/// ```
318
- #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
319
- pub fn reserve ( & mut self , additional : uint ) {
320
- self . data . reserve ( additional)
321
- }
322
-
323
- /// Discards as much additional capacity as possible.
324
- #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
325
- pub fn shrink_to_fit ( & mut self ) {
326
- self . data . shrink_to_fit ( )
299
+ pub fn reserve ( & mut self , n : uint ) {
300
+ self . data . reserve ( n)
327
301
}
328
302
329
303
/// Removes the greatest item from a queue and returns it, or `None` if it
@@ -340,7 +314,6 @@ impl<T: Ord> BinaryHeap<T> {
340
314
/// assert_eq!(pq.pop(), Some(1i));
341
315
/// assert_eq!(pq.pop(), None);
342
316
/// ```
343
- #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
344
317
pub fn pop ( & mut self ) -> Option < T > {
345
318
match self . data . pop ( ) {
346
319
None => { None }
@@ -369,7 +342,6 @@ impl<T: Ord> BinaryHeap<T> {
369
342
/// assert_eq!(pq.len(), 3);
370
343
/// assert_eq!(pq.top(), Some(&5i));
371
344
/// ```
372
- #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
373
345
pub fn push ( & mut self , item : T ) {
374
346
self . data . push ( item) ;
375
347
let new_len = self . len ( ) - 1 ;
@@ -523,15 +495,12 @@ impl<T: Ord> BinaryHeap<T> {
523
495
}
524
496
525
497
/// Returns the length of the queue.
526
- #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
527
498
pub fn len ( & self ) -> uint { self . data . len ( ) }
528
499
529
500
/// Returns true if the queue contains no elements
530
- #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
531
501
pub fn is_empty ( & self ) -> bool { self . len ( ) == 0 }
532
502
533
503
/// Drops all items from the queue.
534
- #[ unstable = "matches collection reform specification, waiting for dust to settle" ]
535
504
pub fn clear ( & mut self ) { self . data . truncate ( 0 ) }
536
505
}
537
506
@@ -559,7 +528,8 @@ impl<T: Ord> Extendable<T> for BinaryHeap<T> {
559
528
fn extend < Iter : Iterator < T > > ( & mut self , mut iter : Iter ) {
560
529
let ( lower, _) = iter. size_hint ( ) ;
561
530
562
- self . reserve ( lower) ;
531
+ let len = self . capacity ( ) ;
532
+ self . reserve ( len + lower) ;
563
533
564
534
for elem in iter {
565
535
self . push ( elem) ;
0 commit comments