Skip to content

Commit 7311b63

Browse files
committed
rollup merge of rust-lang#20053: csouth3/misc-stab
This pull request: *Renames `BinaryHeap::top` to `BinaryHeap::peek` *Stabilizes `front/back/front_mut/back_mut` in `DList` and `RingBuf` *Stabilizes `swap` in `RingBuf` in accordance with rust-lang/rfcs#509. Note that this PR does not address `Bitv::{get,set}` or HashMap's iterators, nor does it move `std::vec` to `std::collections::vec`, all of which still need to be done. Because of the method renaming, this is a [breaking-change].
2 parents b04bc5c + abf492d commit 7311b63

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

src/libcollections/binary_heap.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,16 @@ impl<T: Ord> BinaryHeap<T> {
272272
/// use std::collections::BinaryHeap;
273273
///
274274
/// let mut heap = BinaryHeap::new();
275-
/// assert_eq!(heap.top(), None);
275+
/// assert_eq!(heap.peek(), None);
276276
///
277277
/// heap.push(1i);
278278
/// heap.push(5i);
279279
/// heap.push(2i);
280-
/// assert_eq!(heap.top(), Some(&5i));
280+
/// assert_eq!(heap.peek(), Some(&5i));
281281
///
282282
/// ```
283-
pub fn top(&self) -> Option<&T> {
283+
#[stable]
284+
pub fn peek(&self) -> Option<&T> {
284285
self.data.get(0)
285286
}
286287

@@ -388,7 +389,7 @@ impl<T: Ord> BinaryHeap<T> {
388389
/// heap.push(1i);
389390
///
390391
/// assert_eq!(heap.len(), 3);
391-
/// assert_eq!(heap.top(), Some(&5i));
392+
/// assert_eq!(heap.peek(), Some(&5i));
392393
/// ```
393394
#[unstable = "matches collection reform specification, waiting for dust to settle"]
394395
pub fn push(&mut self, item: T) {
@@ -412,7 +413,7 @@ impl<T: Ord> BinaryHeap<T> {
412413
/// assert_eq!(heap.push_pop(3i), 5);
413414
/// assert_eq!(heap.push_pop(9i), 9);
414415
/// assert_eq!(heap.len(), 2);
415-
/// assert_eq!(heap.top(), Some(&3i));
416+
/// assert_eq!(heap.peek(), Some(&3i));
416417
/// ```
417418
pub fn push_pop(&mut self, mut item: T) -> T {
418419
match self.data.get_mut(0) {
@@ -442,7 +443,7 @@ impl<T: Ord> BinaryHeap<T> {
442443
/// assert_eq!(heap.replace(1i), None);
443444
/// assert_eq!(heap.replace(3i), Some(1i));
444445
/// assert_eq!(heap.len(), 1);
445-
/// assert_eq!(heap.top(), Some(&3i));
446+
/// assert_eq!(heap.peek(), Some(&3i));
446447
/// ```
447448
pub fn replace(&mut self, mut item: T) -> Option<T> {
448449
if !self.is_empty() {
@@ -714,13 +715,13 @@ mod tests {
714715
}
715716

716717
#[test]
717-
fn test_top_and_pop() {
718+
fn test_peek_and_pop() {
718719
let data = vec!(2u, 4, 6, 2, 1, 8, 10, 3, 5, 7, 0, 9, 1);
719720
let mut sorted = data.clone();
720721
sorted.sort();
721722
let mut heap = BinaryHeap::from_vec(data);
722723
while !heap.is_empty() {
723-
assert_eq!(heap.top().unwrap(), sorted.last().unwrap());
724+
assert_eq!(heap.peek().unwrap(), sorted.last().unwrap());
724725
assert_eq!(heap.pop().unwrap(), sorted.pop().unwrap());
725726
}
726727
}
@@ -729,44 +730,44 @@ mod tests {
729730
fn test_push() {
730731
let mut heap = BinaryHeap::from_vec(vec!(2i, 4, 9));
731732
assert_eq!(heap.len(), 3);
732-
assert!(*heap.top().unwrap() == 9);
733+
assert!(*heap.peek().unwrap() == 9);
733734
heap.push(11);
734735
assert_eq!(heap.len(), 4);
735-
assert!(*heap.top().unwrap() == 11);
736+
assert!(*heap.peek().unwrap() == 11);
736737
heap.push(5);
737738
assert_eq!(heap.len(), 5);
738-
assert!(*heap.top().unwrap() == 11);
739+
assert!(*heap.peek().unwrap() == 11);
739740
heap.push(27);
740741
assert_eq!(heap.len(), 6);
741-
assert!(*heap.top().unwrap() == 27);
742+
assert!(*heap.peek().unwrap() == 27);
742743
heap.push(3);
743744
assert_eq!(heap.len(), 7);
744-
assert!(*heap.top().unwrap() == 27);
745+
assert!(*heap.peek().unwrap() == 27);
745746
heap.push(103);
746747
assert_eq!(heap.len(), 8);
747-
assert!(*heap.top().unwrap() == 103);
748+
assert!(*heap.peek().unwrap() == 103);
748749
}
749750

750751
#[test]
751752
fn test_push_unique() {
752753
let mut heap = BinaryHeap::from_vec(vec!(box 2i, box 4, box 9));
753754
assert_eq!(heap.len(), 3);
754-
assert!(*heap.top().unwrap() == box 9);
755+
assert!(*heap.peek().unwrap() == box 9);
755756
heap.push(box 11);
756757
assert_eq!(heap.len(), 4);
757-
assert!(*heap.top().unwrap() == box 11);
758+
assert!(*heap.peek().unwrap() == box 11);
758759
heap.push(box 5);
759760
assert_eq!(heap.len(), 5);
760-
assert!(*heap.top().unwrap() == box 11);
761+
assert!(*heap.peek().unwrap() == box 11);
761762
heap.push(box 27);
762763
assert_eq!(heap.len(), 6);
763-
assert!(*heap.top().unwrap() == box 27);
764+
assert!(*heap.peek().unwrap() == box 27);
764765
heap.push(box 3);
765766
assert_eq!(heap.len(), 7);
766-
assert!(*heap.top().unwrap() == box 27);
767+
assert!(*heap.peek().unwrap() == box 27);
767768
heap.push(box 103);
768769
assert_eq!(heap.len(), 8);
769-
assert!(*heap.top().unwrap() == box 103);
770+
assert!(*heap.peek().unwrap() == box 103);
770771
}
771772

772773
#[test]
@@ -831,9 +832,9 @@ mod tests {
831832
}
832833

833834
#[test]
834-
fn test_empty_top() {
835+
fn test_empty_peek() {
835836
let empty = BinaryHeap::<int>::new();
836-
assert!(empty.top().is_none());
837+
assert!(empty.peek().is_none());
837838
}
838839

839840
#[test]

src/libcollections/dlist.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,31 +451,31 @@ impl<T> DList<T> {
451451
/// Provides a reference to the front element, or `None` if the list is
452452
/// empty.
453453
#[inline]
454-
#[unstable = "matches collection reform specification, waiting for dust to settle"]
454+
#[stable]
455455
pub fn front(&self) -> Option<&T> {
456456
self.list_head.as_ref().map(|head| &head.value)
457457
}
458458

459459
/// Provides a mutable reference to the front element, or `None` if the list
460460
/// is empty.
461461
#[inline]
462-
#[unstable = "matches collection reform specification, waiting for dust to settle"]
462+
#[stable]
463463
pub fn front_mut(&mut self) -> Option<&mut T> {
464464
self.list_head.as_mut().map(|head| &mut head.value)
465465
}
466466

467467
/// Provides a reference to the back element, or `None` if the list is
468468
/// empty.
469469
#[inline]
470-
#[unstable = "matches collection reform specification, waiting for dust to settle"]
470+
#[stable]
471471
pub fn back(&self) -> Option<&T> {
472472
self.list_tail.resolve_immut().as_ref().map(|tail| &tail.value)
473473
}
474474

475475
/// Provides a mutable reference to the back element, or `None` if the list
476476
/// is empty.
477477
#[inline]
478-
#[unstable = "matches collection reform specification, waiting for dust to settle"]
478+
#[stable]
479479
pub fn back_mut(&mut self) -> Option<&mut T> {
480480
self.list_tail.resolve().map(|tail| &mut tail.value)
481481
}

src/libcollections/ring_buf.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ impl<T> RingBuf<T> {
228228
/// assert_eq!(buf[0], 5);
229229
/// assert_eq!(buf[2], 3);
230230
/// ```
231+
#[stable]
231232
pub fn swap(&mut self, i: uint, j: uint) {
232233
assert!(i < self.len());
233234
assert!(j < self.len());
@@ -546,7 +547,7 @@ impl<T> RingBuf<T> {
546547
/// d.push_back(2i);
547548
/// assert_eq!(d.front(), Some(&1i));
548549
/// ```
549-
#[unstable = "matches collection reform specification, waiting for dust to settle"]
550+
#[stable]
550551
pub fn front(&self) -> Option<&T> {
551552
if !self.is_empty() { Some(&self[0]) } else { None }
552553
}
@@ -570,7 +571,7 @@ impl<T> RingBuf<T> {
570571
/// }
571572
/// assert_eq!(d.front(), Some(&9i));
572573
/// ```
573-
#[unstable = "matches collection reform specification, waiting for dust to settle"]
574+
#[stable]
574575
pub fn front_mut(&mut self) -> Option<&mut T> {
575576
if !self.is_empty() { Some(&mut self[0]) } else { None }
576577
}
@@ -590,7 +591,7 @@ impl<T> RingBuf<T> {
590591
/// d.push_back(2i);
591592
/// assert_eq!(d.back(), Some(&2i));
592593
/// ```
593-
#[unstable = "matches collection reform specification, waiting for dust to settle"]
594+
#[stable]
594595
pub fn back(&self) -> Option<&T> {
595596
if !self.is_empty() { Some(&self[self.len() - 1]) } else { None }
596597
}
@@ -614,7 +615,7 @@ impl<T> RingBuf<T> {
614615
/// }
615616
/// assert_eq!(d.back(), Some(&9i));
616617
/// ```
617-
#[unstable = "matches collection reform specification, waiting for dust to settle"]
618+
#[stable]
618619
pub fn back_mut(&mut self) -> Option<&mut T> {
619620
let len = self.len();
620621
if !self.is_empty() { Some(&mut self[len - 1]) } else { None }

0 commit comments

Comments
 (0)