collections: Make push_back/pop_back default methods
This commit is contained in:
parent
2d79bfa415
commit
94e42c2d89
@ -249,27 +249,15 @@ fn push_front(&mut self, elt: 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) {
|
||||
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> {
|
||||
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() }
|
||||
fn push(&mut self, elt: T) {
|
||||
self.push_back_node(box Node::new(elt))
|
||||
}
|
||||
fn pop(&mut self) -> Option<T> {
|
||||
self.pop_back_node().map(|box Node{value, ..}| value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Default for DList<T> {
|
||||
|
@ -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.
|
||||
///
|
||||
|
@ -80,18 +80,6 @@ fn pop_front(&mut self) -> Option<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 @@ fn push_front(&mut self, t: 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 @@ fn push_back(&mut self, t: 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> {
|
||||
|
Loading…
Reference in New Issue
Block a user