Skip to content

Commit 0e1e703

Browse files
author
blake2-ppc
committed
---
yaml --- r: 142743 b: refs/heads/try2 c: 24d2d7b h: refs/heads/master i: 142741: 42ce9a5 142739: 94c024f 142735: 03b144d v: v3
1 parent e2ddd53 commit 0e1e703

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 7052371e39268c08067048654a4e115ac86cc51b
8+
refs/heads/try2: 24d2d7b5bb4b046429f293ff5c2cde4d14dfac8b
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libextra/dlist.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
// Backlinks over List::prev are raw pointers that form a full chain in
1111
// the reverse direction.
1212

13-
1413
use std::cast;
1514
use std::cmp;
1615
use std::ptr;
1716
use std::util;
1817
use std::iterator::FromIterator;
1918

19+
use container::Deque;
20+
2021
/// A doubly-linked list
2122
pub struct List<T> {
2223
priv length: uint,
@@ -124,36 +125,30 @@ impl<T> Mutable for List<T> {
124125
}
125126
}
126127

127-
impl<T> List<T> {
128-
/// Create an empty List
129-
#[inline]
130-
pub fn new() -> List<T> {
131-
List{list_head: None, list_tail: Rawlink::none(), length: 0}
132-
}
133-
128+
impl<T> Deque<T> for List<T> {
134129
/// Provide a reference to the front element, or None if the list is empty
135-
pub fn peek_front<'a>(&'a self) -> Option<&'a T> {
130+
fn front<'a>(&'a self) -> Option<&'a T> {
136131
self.list_head.chain_ref(|x| Some(&x.value))
137132
}
138133

139134
/// Provide a mutable reference to the front element, or None if the list is empty
140-
pub fn peek_front_mut<'a>(&'a mut self) -> Option<&'a mut T> {
135+
fn front_mut<'a>(&'a mut self) -> Option<&'a mut T> {
141136
match self.list_head {
142137
None => None,
143138
Some(ref mut head) => Some(&mut head.value),
144139
}
145140
}
146141

147142
/// Provide a reference to the back element, or None if the list is empty
148-
pub fn peek_back<'a>(&'a self) -> Option<&'a T> {
143+
fn back<'a>(&'a self) -> Option<&'a T> {
149144
match self.list_tail.resolve_immut() {
150145
None => None,
151146
Some(tail) => Some(&tail.value),
152147
}
153148
}
154149

155150
/// Provide a mutable reference to the back element, or None if the list is empty
156-
pub fn peek_back_mut<'a>(&'a mut self) -> Option<&'a mut T> {
151+
fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> {
157152
match self.list_tail.resolve() {
158153
None => None,
159154
Some(tail) => Some(&mut tail.value),
@@ -163,7 +158,7 @@ impl<T> List<T> {
163158
/// Add an element last in the list
164159
///
165160
/// O(1)
166-
pub fn push_back(&mut self, elt: T) {
161+
fn push_back(&mut self, elt: T) {
167162
match self.list_tail.resolve() {
168163
None => return self.push_front(elt),
169164
Some(tail) => {
@@ -179,7 +174,7 @@ impl<T> List<T> {
179174
///
180175
/// O(1)
181176
#[inline]
182-
pub fn pop_back(&mut self) -> Option<T> {
177+
fn pop_back(&mut self) -> Option<T> {
183178
match self.list_tail.resolve() {
184179
None => None,
185180
Some(tail) => {
@@ -202,7 +197,7 @@ impl<T> List<T> {
202197
/// Add an element first in the list
203198
///
204199
/// O(1)
205-
pub fn push_front(&mut self, elt: T) {
200+
fn push_front(&mut self, elt: T) {
206201
let mut new_head = ~Node{value: elt, next: None, prev: Rawlink::none()};
207202
match self.list_head {
208203
None => {
@@ -221,7 +216,7 @@ impl<T> List<T> {
221216
/// Remove the first element and return it, or None if the list is empty
222217
///
223218
/// O(1)
224-
pub fn pop_front(&mut self) -> Option<T> {
219+
fn pop_front(&mut self) -> Option<T> {
225220
match util::replace(&mut self.list_head, None) {
226221
None => None,
227222
Some(old_head) => {
@@ -239,6 +234,14 @@ impl<T> List<T> {
239234
}
240235
}
241236
}
237+
}
238+
239+
impl<T> List<T> {
240+
/// Create an empty List
241+
#[inline]
242+
pub fn new() -> List<T> {
243+
List{list_head: None, list_tail: Rawlink::none(), length: 0}
244+
}
242245

243246
/// Add all elements from `other` to the end of the list
244247
///
@@ -292,7 +295,7 @@ impl<T> List<T> {
292295
{
293296
let mut it = self.mut_iter();
294297
loop {
295-
match (it.next(), other.peek_front()) {
298+
match (it.next(), other.front()) {
296299
(None , _ ) => break,
297300
(_ , None ) => return,
298301
(Some(x), Some(y)) => if f(x, y) { loop }
@@ -462,7 +465,7 @@ impl<'self, A> ListInsertion<A> for MutForwardIterator<'self, A> {
462465

463466
fn peek_next<'a>(&'a mut self) -> Option<&'a mut A> {
464467
match self.curs.resolve() {
465-
None => self.list.peek_front_mut(),
468+
None => self.list.front_mut(),
466469
Some(curs) => match curs.next {
467470
None => None,
468471
Some(ref mut node) => Some(&mut node.value),
@@ -574,14 +577,14 @@ mod tests {
574577
n.push_front(2);
575578
n.push_front(3);
576579
{
577-
assert_eq!(n.peek_front().unwrap(), &3);
578-
let x = n.peek_front_mut().unwrap();
580+
assert_eq!(n.front().unwrap(), &3);
581+
let x = n.front_mut().unwrap();
579582
assert_eq!(*x, 3);
580583
*x = 0;
581584
}
582585
{
583-
assert_eq!(n.peek_back().unwrap(), &2);
584-
let y = n.peek_back_mut().unwrap();
586+
assert_eq!(n.back().unwrap(), &2);
587+
let y = n.back_mut().unwrap();
585588
assert_eq!(*y, 2);
586589
*y = 1;
587590
}

0 commit comments

Comments
 (0)