Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stabilize more of collections #20356

Merged
merged 1 commit into from
Jan 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ use vec::{mod, Vec};
///
/// This will be a max-heap.
#[deriving(Clone)]
#[stable]
pub struct BinaryHeap<T> {
data: Vec<T>,
}

#[stable]
impl<T: Ord> Default for BinaryHeap<T> {
#[inline]
#[stable]
fn default() -> BinaryHeap<T> { BinaryHeap::new() }
}

Expand All @@ -182,7 +182,7 @@ impl<T: Ord> BinaryHeap<T> {
/// let mut heap = BinaryHeap::new();
/// heap.push(4u);
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn new() -> BinaryHeap<T> { BinaryHeap { data: vec![] } }

/// Creates an empty `BinaryHeap` with a specific capacity.
Expand All @@ -197,7 +197,7 @@ impl<T: Ord> BinaryHeap<T> {
/// let mut heap = BinaryHeap::with_capacity(10);
/// heap.push(4u);
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn with_capacity(capacity: uint) -> BinaryHeap<T> {
BinaryHeap { data: Vec::with_capacity(capacity) }
}
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<T: Ord> BinaryHeap<T> {
/// println!("{}", x);
/// }
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn iter(&self) -> Iter<T> {
Iter { iter: self.data.iter() }
}
Expand All @@ -256,7 +256,7 @@ impl<T: Ord> BinaryHeap<T> {
/// println!("{}", x);
/// }
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn into_iter(self) -> IntoIter<T> {
IntoIter { iter: self.data.into_iter() }
}
Expand Down Expand Up @@ -291,7 +291,7 @@ impl<T: Ord> BinaryHeap<T> {
/// assert!(heap.capacity() >= 100);
/// heap.push(4u);
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn capacity(&self) -> uint { self.data.capacity() }

/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
Expand All @@ -314,7 +314,7 @@ impl<T: Ord> BinaryHeap<T> {
/// assert!(heap.capacity() >= 100);
/// heap.push(4u);
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn reserve_exact(&mut self, additional: uint) {
self.data.reserve_exact(additional);
}
Expand All @@ -335,13 +335,13 @@ impl<T: Ord> BinaryHeap<T> {
/// assert!(heap.capacity() >= 100);
/// heap.push(4u);
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn reserve(&mut self, additional: uint) {
self.data.reserve(additional);
}

/// Discards as much additional capacity as possible.
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn shrink_to_fit(&mut self) {
self.data.shrink_to_fit();
}
Expand All @@ -359,7 +359,7 @@ impl<T: Ord> BinaryHeap<T> {
/// assert_eq!(heap.pop(), Some(1));
/// assert_eq!(heap.pop(), None);
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn pop(&mut self) -> Option<T> {
self.data.pop().map(|mut item| {
if !self.is_empty() {
Expand All @@ -384,7 +384,7 @@ impl<T: Ord> BinaryHeap<T> {
/// assert_eq!(heap.len(), 3);
/// assert_eq!(heap.peek(), Some(&5));
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn push(&mut self, item: T) {
let old_len = self.len();
self.data.push(item);
Expand Down Expand Up @@ -539,11 +539,11 @@ impl<T: Ord> BinaryHeap<T> {
}

/// Returns the length of the binary heap.
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn len(&self) -> uint { self.data.len() }

/// Checks if the binary heap is empty.
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn is_empty(&self) -> bool { self.len() == 0 }

/// Clears the binary heap, returning an iterator over the removed elements.
Expand All @@ -554,7 +554,7 @@ impl<T: Ord> BinaryHeap<T> {
}

/// Drops all items from the binary heap.
#[unstable = "matches collection reform specification, waiting for dust to settle"]
#[stable]
pub fn clear(&mut self) { self.drain(); }
}

Expand All @@ -570,6 +570,7 @@ impl<'a, T> Clone for Iter<'a, T> {
}
}

#[stable]
impl<'a, T> Iterator<&'a T> for Iter<'a, T> {
#[inline]
fn next(&mut self) -> Option<&'a T> { self.iter.next() }
Expand All @@ -578,18 +579,21 @@ impl<'a, T> Iterator<&'a T> for Iter<'a, T> {
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}

#[stable]
impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() }
}

#[stable]
impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {}

/// An iterator that moves out of a `BinaryHeap`.
pub struct IntoIter<T> {
iter: vec::IntoIter<T>,
}

#[stable]
impl<T> Iterator<T> for IntoIter<T> {
#[inline]
fn next(&mut self) -> Option<T> { self.iter.next() }
Expand All @@ -598,18 +602,21 @@ impl<T> Iterator<T> for IntoIter<T> {
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}

#[stable]
impl<T> DoubleEndedIterator<T> for IntoIter<T> {
#[inline]
fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
}

#[stable]
impl<T> ExactSizeIterator<T> for IntoIter<T> {}

/// An iterator that drains a `BinaryHeap`.
pub struct Drain<'a, T: 'a> {
iter: vec::Drain<'a, T>,
}

#[stable]
impl<'a, T: 'a> Iterator<T> for Drain<'a, T> {
#[inline]
fn next(&mut self) -> Option<T> { self.iter.next() }
Expand All @@ -618,19 +625,23 @@ impl<'a, T: 'a> Iterator<T> for Drain<'a, T> {
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}

#[stable]
impl<'a, T: 'a> DoubleEndedIterator<T> for Drain<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
}

#[stable]
impl<'a, T: 'a> ExactSizeIterator<T> for Drain<'a, T> {}

#[stable]
impl<T: Ord> FromIterator<T> for BinaryHeap<T> {
fn from_iter<Iter: Iterator<T>>(iter: Iter) -> BinaryHeap<T> {
BinaryHeap::from_vec(iter.collect())
}
}

#[stable]
impl<T: Ord> Extend<T> for BinaryHeap<T> {
fn extend<Iter: Iterator<T>>(&mut self, mut iter: Iter) {
let (lower, _) = iter.size_hint();
Expand Down
Loading