diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index d2215ea528ad..cd36d14816cb 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -304,20 +304,6 @@ impl extensions for dlist { tl.map(|nobe| self.unlink(nobe)); tl } - /// Remove data from the head of the list. O(1). - fn pop() -> option { - do option::map_consume(self.pop_n()) |nobe| { - let dlist_node(@{ data: x, _ }) <- nobe; - x - } - } - /// Remove data from the tail of the list. O(1). - fn pop_tail() -> option { - do option::map_consume(self.pop_tail_n()) |nobe| { - let dlist_node(@{ data: x, _ }) <- nobe; - x - } - } /// Get the node at the list's head. O(1). pure fn peek_n() -> option> { self.hd } /// Get the node at the list's tail. O(1). @@ -399,7 +385,7 @@ impl extensions for dlist { // Cute as it would be to simply detach the list and proclaim "O(1)!", // the GC would still be a hidden O(n). Better to be honest about it. while !self.is_empty() { - let _ = self.pop(); + let _ = self.pop_n(); } } @@ -457,6 +443,10 @@ impl extensions for dlist { } impl extensions for dlist { + /// Remove data from the head of the list. O(1). + fn pop() -> option { self.pop_n().map (|nobe| nobe.data) } + /// Remove data from the tail of the list. O(1). + fn pop_tail() -> option { self.pop_tail_n().map (|nobe| nobe.data) } /// Get data at the list's head. O(1). pure fn peek() -> option { self.peek_n().map (|nobe| nobe.data) } /// Get data at the list's tail. O(1). @@ -622,6 +612,13 @@ mod tests { a.assert_consistent(); assert a.is_empty(); } #[test] + fn test_dlist_clear() { + let a = from_vec(~[5,4,3,2,1]); + a.clear(); + assert a.len() == 0; + a.assert_consistent(); + } + #[test] fn test_dlist_is_empty() { let empty = new_dlist::(); let full1 = from_vec(~[1,2,3]);