1 // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! A doubly-linked list with owned nodes.
13 //! The DList allows pushing and popping elements at either end.
15 //! DList implements the trait Deque. It should be imported with `use
16 //! extra::container::Deque`.
19 // DList is constructed like a singly-linked list over the field `next`.
20 // including the last link being None; each Node owns its `next` field.
22 // Backlinks over DList::prev are raw pointers that form a full chain in
23 // the reverse direction.
28 use std::iterator::{FromIterator, Extendable, Invert};
33 /// A doubly-linked list.
36 priv list_head: Link<T>,
37 priv list_tail: Rawlink<Node<T>>,
40 type Link<T> = Option<~Node<T>>;
41 struct Rawlink<T> { priv p: *mut T }
45 priv prev: Rawlink<Node<T>>,
49 /// Double-ended DList iterator
51 pub struct DListIterator<'self, T> {
52 priv head: &'self Link<T>,
53 priv tail: Rawlink<Node<T>>,
57 /// Double-ended mutable DList iterator
58 pub struct MutDListIterator<'self, T> {
59 priv list: &'self mut DList<T>,
60 priv head: Rawlink<Node<T>>,
61 priv tail: Rawlink<Node<T>>,
65 /// DList consuming iterator
67 pub struct MoveIterator<T> {
71 /// Rawlink is a type like Option<T> but for holding a raw pointer
73 /// Like Option::None for Rawlink
74 fn none() -> Rawlink<T> {
75 Rawlink{p: ptr::mut_null()}
78 /// Like Option::Some for Rawlink
79 fn some(n: &mut T) -> Rawlink<T> {
80 Rawlink{p: ptr::to_mut_unsafe_ptr(n)}
83 /// Convert the `Rawlink` into an Option value
84 fn resolve_immut(&self) -> Option<&T> {
85 unsafe { self.p.to_option() }
88 /// Convert the `Rawlink` into an Option value
89 fn resolve(&mut self) -> Option<&mut T> {
93 Some(unsafe { cast::transmute(self.p) })
97 /// Return the `Rawlink` and replace with `Rawlink::none()`
98 fn take(&mut self) -> Rawlink<T> {
99 util::replace(self, Rawlink::none())
103 impl<T> Clone for Rawlink<T> {
105 fn clone(&self) -> Rawlink<T> {
111 fn new(v: T) -> Node<T> {
112 Node{value: v, next: None, prev: Rawlink::none()}
116 /// Set the .prev field on `next`, then return `Some(next)`
117 fn link_with_prev<T>(mut next: ~Node<T>, prev: Rawlink<Node<T>>) -> Link<T> {
122 impl<T> Container for DList<T> {
125 fn is_empty(&self) -> bool {
126 self.list_head.is_none()
130 fn len(&self) -> uint {
135 impl<T> Mutable for DList<T> {
136 /// Remove all elements from the DList
140 fn clear(&mut self) {
147 /// Add a Node first in the list
149 fn push_front_node(&mut self, mut new_head: ~Node<T>) {
150 match self.list_head {
152 self.list_tail = Rawlink::some(new_head);
153 self.list_head = link_with_prev(new_head, Rawlink::none());
155 Some(ref mut head) => {
156 new_head.prev = Rawlink::none();
157 head.prev = Rawlink::some(new_head);
158 util::swap(head, &mut new_head);
159 head.next = Some(new_head);
165 /// Remove the first Node and return it, or None if the list is empty
167 fn pop_front_node(&mut self) -> Option<~Node<T>> {
168 do self.list_head.take().map_move |mut front_node| {
170 match front_node.next.take() {
171 Some(node) => self.list_head = link_with_prev(node, Rawlink::none()),
172 None => self.list_tail = Rawlink::none()
178 /// Add a Node last in the list
180 fn push_back_node(&mut self, mut new_tail: ~Node<T>) {
181 match self.list_tail.resolve() {
182 None => return self.push_front_node(new_tail),
184 self.list_tail = Rawlink::some(new_tail);
185 tail.next = link_with_prev(new_tail, Rawlink::some(tail));
191 /// Remove the last Node and return it, or None if the list is empty
193 fn pop_back_node(&mut self) -> Option<~Node<T>> {
194 do self.list_tail.resolve().map_move_default(None) |tail| {
196 self.list_tail = tail.prev;
197 match tail.prev.resolve() {
198 None => self.list_head.take(),
199 Some(tail_prev) => tail_prev.next.take()
205 impl<T> Deque<T> for DList<T> {
206 /// Provide a reference to the front element, or None if the list is empty
208 fn front<'a>(&'a self) -> Option<&'a T> {
209 self.list_head.map(|head| &head.value)
212 /// Provide a mutable reference to the front element, or None if the list is empty
214 fn front_mut<'a>(&'a mut self) -> Option<&'a mut T> {
215 self.list_head.map_mut(|head| &mut head.value)
218 /// Provide a reference to the back element, or None if the list is empty
220 fn back<'a>(&'a self) -> Option<&'a T> {
221 self.list_tail.resolve_immut().map(|tail| &tail.value)
224 /// Provide a mutable reference to the back element, or None if the list is empty
226 fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> {
227 self.list_tail.resolve().map_mut(|tail| &mut tail.value)
230 /// Add an element first in the list
233 fn push_front(&mut self, elt: T) {
234 self.push_front_node(~Node::new(elt))
237 /// Remove the first element and return it, or None if the list is empty
240 fn pop_front(&mut self) -> Option<T> {
241 self.pop_front_node().map_move(|~Node{value, _}| value)
244 /// Add an element last in the list
247 fn push_back(&mut self, elt: T) {
248 self.push_back_node(~Node::new(elt))
251 /// Remove the last element and return it, or None if the list is empty
254 fn pop_back(&mut self) -> Option<T> {
255 self.pop_back_node().map_move(|~Node{value, _}| value)
260 /// Create an empty DList
262 pub fn new() -> DList<T> {
263 DList{list_head: None, list_tail: Rawlink::none(), length: 0}
266 /// Move the last element to the front of the list.
268 /// If the list is empty, do nothing.
270 pub fn rotate_forward(&mut self) {
271 do self.pop_back_node().map_move |tail| {
272 self.push_front_node(tail)
276 /// Move the first element to the back of the list.
278 /// If the list is empty, do nothing.
280 pub fn rotate_backward(&mut self) {
281 do self.pop_front_node().map_move |head| {
282 self.push_back_node(head)
286 /// Add all elements from `other` to the end of the list
289 pub fn append(&mut self, mut other: DList<T>) {
290 match self.list_tail.resolve() {
291 None => *self = other,
293 // Carefully empty `other`.
294 let o_tail = other.list_tail.take();
295 let o_length = other.length;
296 match other.list_head.take() {
299 tail.next = link_with_prev(node, self.list_tail);
300 self.list_tail = o_tail;
301 self.length += o_length;
308 /// Add all elements from `other` to the beginning of the list
312 pub fn prepend(&mut self, mut other: DList<T>) {
313 util::swap(self, &mut other);
317 /// Insert `elt` before the first `x` in the list where `f(x, elt)` is true,
321 pub fn insert_when(&mut self, elt: T, f: &fn(&T, &T) -> bool) {
323 let mut it = self.mut_iter();
325 match it.peek_next() {
327 Some(x) => if f(x, &elt) { break }
335 /// Merge DList `other` into this DList, using the function `f`.
336 /// Iterate the both DList with `a` from self and `b` from `other`, and
337 /// put `a` in the result if `f(a, b)` is true, else `b`.
340 pub fn merge(&mut self, mut other: DList<T>, f: &fn(&T, &T) -> bool) {
342 let mut it = self.mut_iter();
344 let take_a = match (it.peek_next(), other.front()) {
345 (_ , None) => return,
347 (Some(ref mut x), Some(y)) => f(*x, y),
352 it.insert_next_node(other.pop_front_node().unwrap());
360 /// Provide a forward iterator
362 pub fn iter<'a>(&'a self) -> DListIterator<'a, T> {
363 DListIterator{nelem: self.len(), head: &self.list_head, tail: self.list_tail}
366 /// Provide a reverse iterator
368 pub fn rev_iter<'a>(&'a self) -> Invert<DListIterator<'a, T>> {
372 /// Provide a forward iterator with mutable references
374 pub fn mut_iter<'a>(&'a mut self) -> MutDListIterator<'a, T> {
375 let head_raw = match self.list_head {
376 Some(ref mut h) => Rawlink::some(*h),
377 None => Rawlink::none(),
382 tail: self.list_tail,
386 /// Provide a reverse iterator with mutable references
388 pub fn mut_rev_iter<'a>(&'a mut self) -> Invert<MutDListIterator<'a, T>> {
389 self.mut_iter().invert()
393 /// Consume the list into an iterator yielding elements by value
395 pub fn move_iter(self) -> MoveIterator<T> {
396 MoveIterator{list: self}
399 /// Consume the list into an iterator yielding elements by value, in reverse
401 pub fn move_rev_iter(self) -> Invert<MoveIterator<T>> {
402 self.move_iter().invert()
406 impl<T: Ord> DList<T> {
407 /// Insert `elt` sorted in ascending order
411 pub fn insert_ordered(&mut self, elt: T) {
412 self.insert_when(elt, |a, b| a >= b)
417 impl<T> Drop for DList<T> {
419 let mut_self = unsafe {
420 cast::transmute_mut(self)
422 // Dissolve the dlist in backwards direction
423 // Just dropping the list_head can lead to stack exhaustion
424 // when length is >> 1_000_000
425 let mut tail = mut_self.list_tail;
427 match tail.resolve() {
430 prev.next.take(); // release ~Node<T>
436 mut_self.list_head = None;
437 mut_self.list_tail = Rawlink::none();
442 impl<'self, A> Iterator<&'self A> for DListIterator<'self, A> {
444 fn next(&mut self) -> Option<&'self A> {
448 do self.head.map |head| {
450 self.head = &head.next;
456 fn size_hint(&self) -> (uint, Option<uint>) {
457 (self.nelem, Some(self.nelem))
461 impl<'self, A> DoubleEndedIterator<&'self A> for DListIterator<'self, A> {
463 fn next_back(&mut self) -> Option<&'self A> {
467 do self.tail.resolve().map_move |prev| {
469 self.tail = prev.prev;
475 impl<'self, A> Iterator<&'self mut A> for MutDListIterator<'self, A> {
477 fn next(&mut self) -> Option<&'self mut A> {
481 do self.head.resolve().map_move |next| {
483 self.head = match next.next {
484 Some(ref mut node) => Rawlink::some(&mut **node),
485 None => Rawlink::none(),
492 fn size_hint(&self) -> (uint, Option<uint>) {
493 (self.nelem, Some(self.nelem))
497 impl<'self, A> DoubleEndedIterator<&'self mut A> for MutDListIterator<'self, A> {
499 fn next_back(&mut self) -> Option<&'self mut A> {
503 do self.tail.resolve().map_move |prev| {
505 self.tail = prev.prev;
512 /// Allow mutating the DList while iterating
513 pub trait ListInsertion<A> {
514 /// Insert `elt` just after to the element most recently returned by `.next()`
516 /// The inserted element does not appear in the iteration.
517 fn insert_next(&mut self, elt: A);
519 /// Provide a reference to the next element, without changing the iterator
520 fn peek_next<'a>(&'a mut self) -> Option<&'a mut A>;
523 // private methods for MutDListIterator
524 impl<'self, A> MutDListIterator<'self, A> {
525 fn insert_next_node(&mut self, mut ins_node: ~Node<A>) {
526 // Insert before `self.head` so that it is between the
527 // previously yielded element and self.head.
529 // The inserted node will not appear in further iteration.
530 match self.head.resolve() {
531 None => { self.list.push_back_node(ins_node); }
533 let prev_node = match node.prev.resolve() {
534 None => return self.list.push_front_node(ins_node),
537 let node_own = prev_node.next.take_unwrap();
538 ins_node.next = link_with_prev(node_own, Rawlink::some(ins_node));
539 prev_node.next = link_with_prev(ins_node, Rawlink::some(prev_node));
540 self.list.length += 1;
546 impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
548 fn insert_next(&mut self, elt: A) {
549 self.insert_next_node(~Node::new(elt))
553 fn peek_next<'a>(&'a mut self) -> Option<&'a mut A> {
557 self.head.resolve().map_move(|head| &mut head.value)
561 impl<A> Iterator<A> for MoveIterator<A> {
563 fn next(&mut self) -> Option<A> { self.list.pop_front() }
566 fn size_hint(&self) -> (uint, Option<uint>) {
567 (self.list.length, Some(self.list.length))
571 impl<A> DoubleEndedIterator<A> for MoveIterator<A> {
573 fn next_back(&mut self) -> Option<A> { self.list.pop_back() }
576 impl<A, T: Iterator<A>> FromIterator<A, T> for DList<A> {
577 fn from_iterator(iterator: &mut T) -> DList<A> {
578 let mut ret = DList::new();
579 ret.extend(iterator);
584 impl<A, T: Iterator<A>> Extendable<A, T> for DList<A> {
585 fn extend(&mut self, iterator: &mut T) {
586 for elt in *iterator { self.push_back(elt); }
590 impl<A: Eq> Eq for DList<A> {
591 fn eq(&self, other: &DList<A>) -> bool {
592 self.len() == other.len() &&
593 iterator::order::eq(self.iter(), other.iter())
596 fn ne(&self, other: &DList<A>) -> bool {
597 self.len() != other.len() &&
598 iterator::order::ne(self.iter(), other.iter())
602 impl<A: Eq + Ord> Ord for DList<A> {
603 fn lt(&self, other: &DList<A>) -> bool {
604 iterator::order::lt(self.iter(), other.iter())
606 fn le(&self, other: &DList<A>) -> bool {
607 iterator::order::le(self.iter(), other.iter())
609 fn gt(&self, other: &DList<A>) -> bool {
610 iterator::order::gt(self.iter(), other.iter())
612 fn ge(&self, other: &DList<A>) -> bool {
613 iterator::order::ge(self.iter(), other.iter())
617 impl<A: Clone> Clone for DList<A> {
618 fn clone(&self) -> DList<A> {
619 self.iter().map(|x| x.clone()).collect()
624 pub fn check_links<T>(list: &DList<T>) {
626 let mut last_ptr: Option<&Node<T>> = None;
627 let mut node_ptr: &Node<T>;
628 match list.list_head {
629 None => { assert_eq!(0u, list.length); return }
630 Some(ref node) => node_ptr = &**node,
633 match (last_ptr, node_ptr.prev.resolve_immut()) {
635 (None , _ ) => fail!("prev link for list_head"),
636 (Some(p), Some(pptr)) => {
637 assert_eq!(p as *Node<T>, pptr as *Node<T>);
639 _ => fail!("prev link is none, not good"),
641 match node_ptr.next {
643 last_ptr = Some(node_ptr);
653 assert_eq!(len, list.length);
664 let mut m = DList::new::<~int>();
665 assert_eq!(m.pop_front(), None);
666 assert_eq!(m.pop_back(), None);
667 assert_eq!(m.pop_front(), None);
669 assert_eq!(m.pop_front(), Some(~1));
672 assert_eq!(m.len(), 2);
673 assert_eq!(m.pop_front(), Some(~2));
674 assert_eq!(m.pop_front(), Some(~3));
675 assert_eq!(m.len(), 0);
676 assert_eq!(m.pop_front(), None);
681 assert_eq!(m.pop_front(), Some(~1));
683 let mut n = DList::new();
687 assert_eq!(n.front().unwrap(), &3);
688 let x = n.front_mut().unwrap();
693 assert_eq!(n.back().unwrap(), &2);
694 let y = n.back_mut().unwrap();
698 assert_eq!(n.pop_front(), Some(0));
699 assert_eq!(n.pop_front(), Some(1));
703 fn generate_test() -> DList<int> {
704 list_from(&[0,1,2,3,4,5,6])
708 fn list_from<T: Clone>(v: &[T]) -> DList<T> {
709 v.iter().map(|x| (*x).clone()).collect()
715 let mut m = DList::new();
716 let mut n = DList::new();
719 assert_eq!(m.len(), 1);
720 assert_eq!(m.pop_back(), Some(2));
724 let mut m = DList::new();
725 let n = DList::new();
728 assert_eq!(m.len(), 1);
729 assert_eq!(m.pop_back(), Some(2));
733 let v = ~[1,2,3,4,5];
734 let u = ~[9,8,1,2,3,4,5];
735 let mut m = list_from(v);
736 m.append(list_from(u));
739 assert_eq!(sum.len(), m.len());
740 for elt in sum.move_iter() {
741 assert_eq!(m.pop_front(), Some(elt))
748 let mut m = DList::new();
749 let mut n = DList::new();
752 assert_eq!(m.len(), 1);
753 assert_eq!(m.pop_back(), Some(2));
757 let v = ~[1,2,3,4,5];
758 let u = ~[9,8,1,2,3,4,5];
759 let mut m = list_from(v);
760 m.prepend(list_from(u));
763 assert_eq!(sum.len(), m.len());
764 for elt in sum.move_iter() {
765 assert_eq!(m.pop_front(), Some(elt))
771 let mut n = DList::new::<int>();
772 n.rotate_backward(); check_links(&n);
773 assert_eq!(n.len(), 0);
774 n.rotate_forward(); check_links(&n);
775 assert_eq!(n.len(), 0);
777 let v = ~[1,2,3,4,5];
778 let mut m = list_from(v);
779 m.rotate_backward(); check_links(&m);
780 m.rotate_forward(); check_links(&m);
781 assert_eq!(v.iter().collect::<~[&int]>(), m.iter().collect());
782 m.rotate_forward(); check_links(&m);
783 m.rotate_forward(); check_links(&m);
784 m.pop_front(); check_links(&m);
785 m.rotate_forward(); check_links(&m);
786 m.rotate_backward(); check_links(&m);
787 m.push_front(9); check_links(&m);
788 m.rotate_forward(); check_links(&m);
789 assert_eq!(~[3,9,5,1,2], m.move_iter().collect());
794 let m = generate_test();
795 for (i, elt) in m.iter().enumerate() {
796 assert_eq!(i as int, *elt);
798 let mut n = DList::new();
799 assert_eq!(n.iter().next(), None);
801 let mut it = n.iter();
802 assert_eq!(it.size_hint(), (1, Some(1)));
803 assert_eq!(it.next().unwrap(), &4);
804 assert_eq!(it.size_hint(), (0, Some(0)));
805 assert_eq!(it.next(), None);
809 fn test_iterator_clone() {
810 let mut n = DList::new();
814 let mut it = n.iter();
816 let mut jt = it.clone();
817 assert_eq!(it.next(), jt.next());
818 assert_eq!(it.next_back(), jt.next_back());
819 assert_eq!(it.next(), jt.next());
823 fn test_iterator_double_end() {
824 let mut n = DList::new();
825 assert_eq!(n.iter().next(), None);
829 let mut it = n.iter();
830 assert_eq!(it.size_hint(), (3, Some(3)));
831 assert_eq!(it.next().unwrap(), &6);
832 assert_eq!(it.size_hint(), (2, Some(2)));
833 assert_eq!(it.next_back().unwrap(), &4);
834 assert_eq!(it.size_hint(), (1, Some(1)));
835 assert_eq!(it.next_back().unwrap(), &5);
836 assert_eq!(it.next_back(), None);
837 assert_eq!(it.next(), None);
842 let m = generate_test();
843 for (i, elt) in m.rev_iter().enumerate() {
844 assert_eq!((6 - i) as int, *elt);
846 let mut n = DList::new();
847 assert_eq!(n.rev_iter().next(), None);
849 let mut it = n.rev_iter();
850 assert_eq!(it.size_hint(), (1, Some(1)));
851 assert_eq!(it.next().unwrap(), &4);
852 assert_eq!(it.size_hint(), (0, Some(0)));
853 assert_eq!(it.next(), None);
858 let mut m = generate_test();
859 let mut len = m.len();
860 for (i, elt) in m.mut_iter().enumerate() {
861 assert_eq!(i as int, *elt);
865 let mut n = DList::new();
866 assert!(n.mut_iter().next().is_none());
869 let mut it = n.mut_iter();
870 assert_eq!(it.size_hint(), (2, Some(2)));
871 assert!(it.next().is_some());
872 assert!(it.next().is_some());
873 assert_eq!(it.size_hint(), (0, Some(0)));
874 assert!(it.next().is_none());
878 fn test_iterator_mut_double_end() {
879 let mut n = DList::new();
880 assert!(n.mut_iter().next_back().is_none());
884 let mut it = n.mut_iter();
885 assert_eq!(it.size_hint(), (3, Some(3)));
886 assert_eq!(*it.next().unwrap(), 6);
887 assert_eq!(it.size_hint(), (2, Some(2)));
888 assert_eq!(*it.next_back().unwrap(), 4);
889 assert_eq!(it.size_hint(), (1, Some(1)));
890 assert_eq!(*it.next_back().unwrap(), 5);
891 assert!(it.next_back().is_none());
892 assert!(it.next().is_none());
896 fn test_insert_prev() {
897 let mut m = list_from(&[0,2,4,6,8]);
900 let mut it = m.mut_iter();
906 it.insert_next(*elt + 1);
907 match it.peek_next() {
908 Some(x) => assert_eq!(*x, *elt + 2),
909 None => assert_eq!(8, *elt),
918 assert_eq!(m.len(), 3 + len * 2);
919 assert_eq!(m.move_iter().collect::<~[int]>(), ~[-2,0,1,2,3,4,5,6,7,8,9,0,1]);
924 let mut m = list_from([0, 1, 3, 5, 6, 7, 2]);
925 let n = list_from([-1, 0, 0, 7, 7, 9]);
926 let len = m.len() + n.len();
927 m.merge(n, |a, b| a <= b);
928 assert_eq!(m.len(), len);
930 let res = m.move_iter().collect::<~[int]>();
931 assert_eq!(res, ~[-1, 0, 0, 0, 1, 3, 5, 6, 7, 2, 7, 7, 9]);
935 fn test_insert_ordered() {
936 let mut n = DList::new();
938 assert_eq!(n.len(), 1);
939 assert_eq!(n.pop_front(), Some(1));
941 let mut m = DList::new();
946 assert_eq!(~[2,3,4], m.move_iter().collect::<~[int]>());
950 fn test_mut_rev_iter() {
951 let mut m = generate_test();
952 for (i, elt) in m.mut_rev_iter().enumerate() {
953 assert_eq!((6-i) as int, *elt);
955 let mut n = DList::new();
956 assert!(n.mut_rev_iter().next().is_none());
958 let mut it = n.mut_rev_iter();
959 assert!(it.next().is_some());
960 assert!(it.next().is_none());
965 let n = list_from([1,2,3]);
968 assert_eq!(~[&1,&2,&3], n.iter().collect::<~[&int]>());
974 let mut n: DList<u8> = list_from([]);
975 let mut m = list_from([]);
985 let n: DList<int> = list_from([]);
986 let m = list_from([1,2,3]);
996 let n = list_from([nan]);
997 let m = list_from([nan]);
1003 let n = list_from([nan]);
1004 let one = list_from([1.0]);
1005 assert!(!(n < one));
1006 assert!(!(n > one));
1007 assert!(!(n <= one));
1008 assert!(!(n >= one));
1010 let u = list_from([1.0,2.0,nan]);
1011 let v = list_from([1.0,2.0,3.0]);
1017 let s = list_from([1.0,2.0,4.0,2.0]);
1018 let t = list_from([1.0,2.0,3.0,2.0]);
1021 assert!(!(s <= one));
1035 fn fuzz_test(sz: int) {
1036 let mut m = DList::new::<int>();
1038 for i in range(0, sz) {
1040 let r: u8 = rand::random();
1044 if v.len() > 0 { v.pop(); }
1048 if v.len() > 0 { v.shift(); }
1064 for (a, &b) in m.move_iter().zip(v.iter()) {
1068 assert_eq!(i, v.len());
1072 fn bench_collect_into(b: &mut test::BenchHarness) {
1075 let _: DList<int> = v.iter().map(|x| *x).collect();
1080 fn bench_push_front(b: &mut test::BenchHarness) {
1081 let mut m = DList::new::<int>();
1088 fn bench_push_back(b: &mut test::BenchHarness) {
1089 let mut m = DList::new::<int>();
1096 fn bench_push_back_pop_back(b: &mut test::BenchHarness) {
1097 let mut m = DList::new::<int>();
1105 fn bench_push_front_pop_front(b: &mut test::BenchHarness) {
1106 let mut m = DList::new::<int>();
1114 fn bench_rotate_forward(b: &mut test::BenchHarness) {
1115 let mut m = DList::new::<int>();
1124 fn bench_rotate_backward(b: &mut test::BenchHarness) {
1125 let mut m = DList::new::<int>();
1129 m.rotate_backward();
1134 fn bench_iter(b: &mut test::BenchHarness) {
1135 let v = &[0, ..128];
1136 let m: DList<int> = v.iter().map(|&x|x).collect();
1138 assert!(m.iter().len() == 128);
1142 fn bench_iter_mut(b: &mut test::BenchHarness) {
1143 let v = &[0, ..128];
1144 let mut m: DList<int> = v.iter().map(|&x|x).collect();
1146 assert!(m.mut_iter().len() == 128);
1150 fn bench_iter_rev(b: &mut test::BenchHarness) {
1151 let v = &[0, ..128];
1152 let m: DList<int> = v.iter().map(|&x|x).collect();
1154 assert!(m.rev_iter().len() == 128);
1158 fn bench_iter_mut_rev(b: &mut test::BenchHarness) {
1159 let v = &[0, ..128];
1160 let mut m: DList<int> = v.iter().map(|&x|x).collect();
1162 assert!(m.mut_rev_iter().len() == 128);