@@ -304,20 +304,6 @@ impl extensions<T> for dlist<T> {
304
304
tl.map(|nobe| self.unlink(nobe));
305
305
tl
306
306
}
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
- }
321
307
/// Get the node at the list's head. O(1).
322
308
pure fn peek_n() -> option<dlist_node<T>> { self.hd }
323
309
/// Get the node at the list's tail. O(1).
@@ -399,7 +385,7 @@ impl extensions<T> for dlist<T> {
399
385
// Cute as it would be to simply detach the list and proclaim "O(1)!",
400
386
// the GC would still be a hidden O(n). Better to be honest about it.
401
387
while !self . is_empty ( ) {
402
- let _ = self . pop ( ) ;
388
+ let _ = self . pop_n ( ) ;
403
389
}
404
390
}
405
391
@@ -457,6 +443,10 @@ impl extensions<T> for dlist<T> {
457
443
}
458
444
459
445
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 ) }
460
450
/// Get data at the list's head. O(1).
461
451
pure fn peek ( ) -> option < T > { self . peek_n ( ) . map ( |nobe| nobe. data ) }
462
452
/// Get data at the list's tail. O(1).
@@ -622,6 +612,13 @@ mod tests {
622
612
a. assert_consistent ( ) ; assert a. is_empty ( ) ;
623
613
}
624
614
#[ 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]
625
622
fn test_dlist_is_empty ( ) {
626
623
let empty = new_dlist :: < int > ( ) ;
627
624
let full1 = from_vec ( ~[ 1 , 2 , 3 ] ) ;
0 commit comments