diff options
Diffstat (limited to 'src/libcollections/binary_heap.rs')
| -rw-r--r-- | src/libcollections/binary_heap.rs | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 2427422f743..64e10e69a2e 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -161,6 +161,7 @@ use vec::{mod, Vec}; /// /// This will be a max-heap. #[deriving(Clone)] +#[stable] pub struct BinaryHeap<T> { data: Vec<T>, } @@ -168,7 +169,6 @@ pub struct BinaryHeap<T> { #[stable] impl<T: Ord> Default for BinaryHeap<T> { #[inline] - #[stable] fn default() -> BinaryHeap<T> { BinaryHeap::new() } } @@ -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. @@ -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) } } @@ -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() } } @@ -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() } } @@ -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 @@ -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); } @@ -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(); } @@ -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() { @@ -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); @@ -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. @@ -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(); } } @@ -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() } @@ -578,11 +579,13 @@ 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`. @@ -590,6 +593,7 @@ 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() } @@ -598,11 +602,13 @@ 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`. @@ -610,6 +616,7 @@ 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() } @@ -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(); |
