Skip to content

Commit 878f881

Browse files
committed
---
yaml --- r: 22779 b: refs/heads/master c: 5cf99c5 h: refs/heads/master i: 22777: 03c07e4 22775: 79258d0 v: v3
1 parent e6379ed commit 878f881

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: de48b7d4c4bba0212080c9aeb63ac8a13bb04b06
2+
refs/heads/master: 5cf99c585ac16ad8c990c134333e61ea3bf591fb
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/dlist.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -304,20 +304,6 @@ impl extensions<T> for dlist<T> {
304304
tl.map(|nobe| self.unlink(nobe));
305305
tl
306306
}
307-
/// Remove data from the head of the list. O(1).
308-
fn pop() -> option<T> {
309-
do option::map_consume(self.pop_n()) |nobe| {
310-
let dlist_node(@{ data: x, _ }) <- nobe;
311-
x
312-
}
313-
}
314-
/// Remove data from the tail of the list. O(1).
315-
fn pop_tail() -> option<T> {
316-
do option::map_consume(self.pop_tail_n()) |nobe| {
317-
let dlist_node(@{ data: x, _ }) <- nobe;
318-
x
319-
}
320-
}
321307
/// Get the node at the list's head. O(1).
322308
pure fn peek_n() -> option<dlist_node<T>> { self.hd }
323309
/// Get the node at the list's tail. O(1).
@@ -399,7 +385,7 @@ impl extensions<T> for dlist<T> {
399385
// Cute as it would be to simply detach the list and proclaim "O(1)!",
400386
// the GC would still be a hidden O(n). Better to be honest about it.
401387
while !self.is_empty() {
402-
let _ = self.pop();
388+
let _ = self.pop_n();
403389
}
404390
}
405391

@@ -457,6 +443,10 @@ impl extensions<T> for dlist<T> {
457443
}
458444

459445
impl extensions<T: copy> for dlist<T> {
446+
/// Remove data from the head of the list. O(1).
447+
fn pop() -> option<T> { self.pop_n().map (|nobe| nobe.data) }
448+
/// Remove data from the tail of the list. O(1).
449+
fn pop_tail() -> option<T> { self.pop_tail_n().map (|nobe| nobe.data) }
460450
/// Get data at the list's head. O(1).
461451
pure fn peek() -> option<T> { self.peek_n().map (|nobe| nobe.data) }
462452
/// Get data at the list's tail. O(1).
@@ -622,6 +612,13 @@ mod tests {
622612
a.assert_consistent(); assert a.is_empty();
623613
}
624614
#[test]
615+
fn test_dlist_clear() {
616+
let a = from_vec(~[5,4,3,2,1]);
617+
a.clear();
618+
assert a.len() == 0;
619+
a.assert_consistent();
620+
}
621+
#[test]
625622
fn test_dlist_is_empty() {
626623
let empty = new_dlist::<int>();
627624
let full1 = from_vec(~[1,2,3]);

0 commit comments

Comments
 (0)