diff options
| author | Brian Anderson <banderson@mozilla.com> | 2014-07-11 18:08:46 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2014-07-23 13:20:16 -0700 |
| commit | 94e42c2d896cd26c1a48fa4a1748f2c62089fc2a (patch) | |
| tree | 08b0c436e2e57cf4a278883de067d52223d461d6 /src/libcollections | |
| parent | 2d79bfa4150c356240d934b14623d6e90f7e48c4 (diff) | |
| download | rust-94e42c2d896cd26c1a48fa4a1748f2c62089fc2a.tar.gz rust-94e42c2d896cd26c1a48fa4a1748f2c62089fc2a.zip | |
collections: Make push_back/pop_back default methods
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/dlist.rs | 20 | ||||
| -rw-r--r-- | src/libcollections/lib.rs | 4 | ||||
| -rw-r--r-- | src/libcollections/ringbuf.rs | 32 |
3 files changed, 18 insertions, 38 deletions
diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index f4d0763421c..19488ee9f85 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -249,29 +249,17 @@ impl<T> Deque<T> for DList<T> { fn pop_front(&mut self) -> Option<T> { self.pop_front_node().map(|box Node{value, ..}| value) } +} - /// Add an element last in the list - /// - /// O(1) - #[deprecated = "use the `push` method"] - fn push_back(&mut self, elt: T) { +impl<T> MutableSeq<T> for DList<T> { + fn push(&mut self, elt: T) { self.push_back_node(box Node::new(elt)) } - - /// Remove the last element and return it, or None if the list is empty - /// - /// O(1) - #[deprecated = "use the `pop` method"] - fn pop_back(&mut self) -> Option<T> { + fn pop(&mut self) -> Option<T> { self.pop_back_node().map(|box Node{value, ..}| value) } } -impl<T> MutableSeq<T> for DList<T> { - fn push(&mut self, elt: T) { self.push_back(elt) } - fn pop(&mut self) -> Option<T> { self.pop_back() } -} - impl<T> Default for DList<T> { #[inline] fn default() -> DList<T> { DList::new() } diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 1d1907f4541..8d008f921da 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -516,7 +516,7 @@ pub trait Deque<T> : MutableSeq<T> { /// assert_eq!(d.front(), Some(&1i)); /// ``` #[deprecated = "use the `push` method"] - fn push_back(&mut self, elt: T); + fn push_back(&mut self, elt: T) { self.push(elt) } /// Remove the last element and return it, or `None` if the sequence is empty. /// @@ -534,7 +534,7 @@ pub trait Deque<T> : MutableSeq<T> { /// assert_eq!(d.pop_back(), None); /// ``` #[deprecated = "use the `pop` method"] - fn pop_back(&mut self) -> Option<T>; + fn pop_back(&mut self) -> Option<T> { self.pop() } /// Remove the first element and return it, or `None` if the sequence is empty. /// diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index 9d24b349c97..c56781ec30b 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -80,18 +80,6 @@ impl<T> Deque<T> for RingBuf<T> { result } - /// Remove and return the last element in the RingBuf, or None if it is empty - #[deprecated = "use the `pop` method"] - fn pop_back(&mut self) -> Option<T> { - if self.nelts > 0 { - self.nelts -= 1; - let hi = self.raw_index(self.nelts); - self.elts.get_mut(hi).take() - } else { - None - } - } - /// Prepend an element to the RingBuf fn push_front(&mut self, t: T) { if self.nelts == self.elts.len() { @@ -103,10 +91,10 @@ impl<T> Deque<T> for RingBuf<T> { *self.elts.get_mut(self.lo) = Some(t); self.nelts += 1u; } +} - /// Append an element to the RingBuf - #[deprecated = "use the `push` method"] - fn push_back(&mut self, t: T) { +impl<T> MutableSeq<T> for RingBuf<T> { + fn push(&mut self, t: T) { if self.nelts == self.elts.len() { grow(self.nelts, &mut self.lo, &mut self.elts); } @@ -114,11 +102,15 @@ impl<T> Deque<T> for RingBuf<T> { *self.elts.get_mut(hi) = Some(t); self.nelts += 1u; } -} - -impl<T> MutableSeq<T> for RingBuf<T> { - fn push(&mut self, t: T) { self.push_back(t) } - fn pop(&mut self) -> Option<T> { self.pop_back() } + fn pop(&mut self) -> Option<T> { + if self.nelts > 0 { + self.nelts -= 1; + let hi = self.raw_index(self.nelts); + self.elts.get_mut(hi).take() + } else { + None + } + } } impl<T> Default for RingBuf<T> { |
