1 // Copyright 2012-2014 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 //! collections::deque::Deque`.
18 // DList is constructed like a singly-linked list over the field `next`.
19 // including the last link being None; each Node owns its `next` field.
21 // Backlinks over DList::prev are raw pointers that form a full chain in
22 // the reverse direction.
30 /// A doubly-linked list.
34 list_tail: Rawlink<Node<T>>,
37 type Link<T> = Option<Box<Node<T>>>;
38 struct Rawlink<T> { p: *mut T }
42 prev: Rawlink<Node<T>>,
46 /// Double-ended DList iterator
47 pub struct Items<'a, T> {
49 tail: Rawlink<Node<T>>,
53 // FIXME #11820: the &'a Option<> of the Link stops clone working.
54 impl<'a, T> Clone for Items<'a, T> {
55 fn clone(&self) -> Items<'a, T> { *self }
58 /// Double-ended mutable DList iterator
59 pub struct MutItems<'a, T> {
60 list: &'a mut DList<T>,
61 head: Rawlink<Node<T>>,
62 tail: Rawlink<Node<T>>,
66 /// DList consuming iterator
68 pub struct MoveItems<T> {
72 /// Rawlink is a type like Option<T> but for holding a raw pointer
74 /// Like Option::None for Rawlink
75 fn none() -> Rawlink<T> {
76 Rawlink{p: ptr::mut_null()}
79 /// Like Option::Some for Rawlink
80 fn some(n: &mut T) -> Rawlink<T> {
84 /// Convert the `Rawlink` into an Option value
85 fn resolve_immut(&self) -> Option<&T> {
86 unsafe { self.p.to_option() }
89 /// Convert the `Rawlink` into an Option value
90 fn resolve(&mut self) -> Option<&mut T> {
94 Some(unsafe { mem::transmute(self.p) })
98 /// Return the `Rawlink` and replace with `Rawlink::none()`
99 fn take(&mut self) -> Rawlink<T> {
100 mem::replace(self, Rawlink::none())
104 impl<T> Clone for Rawlink<T> {
106 fn clone(&self) -> Rawlink<T> {
112 fn new(v: T) -> Node<T> {
113 Node{value: v, next: None, prev: Rawlink::none()}
117 /// Set the .prev field on `next`, then return `Some(next)`
118 fn link_with_prev<T>(mut next: Box<Node<T>>, prev: Rawlink<Node<T>>)
124 impl<T> Container for DList<T> {
127 fn is_empty(&self) -> bool {
128 self.list_head.is_none()
132 fn len(&self) -> uint {
137 impl<T> Mutable for DList<T> {
138 /// Remove all elements from the DList
142 fn clear(&mut self) {
149 /// Add a Node first in the list
151 fn push_front_node(&mut self, mut new_head: Box<Node<T>>) {
152 match self.list_head {
154 self.list_tail = Rawlink::some(new_head);
155 self.list_head = link_with_prev(new_head, Rawlink::none());
157 Some(ref mut head) => {
158 new_head.prev = Rawlink::none();
159 head.prev = Rawlink::some(new_head);
160 mem::swap(head, &mut new_head);
161 head.next = Some(new_head);
167 /// Remove the first Node and return it, or None if the list is empty
169 fn pop_front_node(&mut self) -> Option<Box<Node<T>>> {
170 self.list_head.take().map(|mut front_node| {
172 match front_node.next.take() {
173 Some(node) => self.list_head = link_with_prev(node, Rawlink::none()),
174 None => self.list_tail = Rawlink::none()
180 /// Add a Node last in the list
182 fn push_back_node(&mut self, mut new_tail: Box<Node<T>>) {
183 match self.list_tail.resolve() {
184 None => return self.push_front_node(new_tail),
186 self.list_tail = Rawlink::some(new_tail);
187 tail.next = link_with_prev(new_tail, Rawlink::some(tail));
193 /// Remove the last Node and return it, or None if the list is empty
195 fn pop_back_node(&mut self) -> Option<Box<Node<T>>> {
196 self.list_tail.resolve().map_or(None, |tail| {
198 self.list_tail = tail.prev;
199 match tail.prev.resolve() {
200 None => self.list_head.take(),
201 Some(tail_prev) => tail_prev.next.take()
207 impl<T> Deque<T> for DList<T> {
208 /// Provide a reference to the front element, or None if the list is empty
210 fn front<'a>(&'a self) -> Option<&'a T> {
211 self.list_head.as_ref().map(|head| &head.value)
214 /// Provide a mutable reference to the front element, or None if the list is empty
216 fn front_mut<'a>(&'a mut self) -> Option<&'a mut T> {
217 self.list_head.as_mut().map(|head| &mut head.value)
220 /// Provide a reference to the back element, or None if the list is empty
222 fn back<'a>(&'a self) -> Option<&'a T> {
223 let tmp = self.list_tail.resolve_immut(); // FIXME: #3511: shouldn't need variable
224 tmp.as_ref().map(|tail| &tail.value)
227 /// Provide a mutable reference to the back element, or None if the list is empty
229 fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> {
230 let tmp: Option<&'a mut Node<T>> =
231 self.list_tail.resolve(); // FIXME: #3511: shouldn't need variable
232 tmp.map(|tail| &mut tail.value)
235 /// Add an element first in the list
238 fn push_front(&mut self, elt: T) {
239 self.push_front_node(box Node::new(elt))
242 /// Remove the first element and return it, or None if the list is empty
245 fn pop_front(&mut self) -> Option<T> {
246 self.pop_front_node().map(|box Node{value, ..}| value)
249 /// Add an element last in the list
252 fn push_back(&mut self, elt: T) {
253 self.push_back_node(box Node::new(elt))
256 /// Remove the last element and return it, or None if the list is empty
259 fn pop_back(&mut self) -> Option<T> {
260 self.pop_back_node().map(|box Node{value, ..}| value)
265 /// Create an empty DList
267 pub fn new() -> DList<T> {
268 DList{list_head: None, list_tail: Rawlink::none(), length: 0}
271 /// Move the last element to the front of the list.
273 /// If the list is empty, do nothing.
275 pub fn rotate_forward(&mut self) {
276 self.pop_back_node().map(|tail| {
277 self.push_front_node(tail)
281 /// Move the first element to the back of the list.
283 /// If the list is empty, do nothing.
285 pub fn rotate_backward(&mut self) {
286 self.pop_front_node().map(|head| {
287 self.push_back_node(head)
291 /// Add all elements from `other` to the end of the list
294 pub fn append(&mut self, mut other: DList<T>) {
295 match self.list_tail.resolve() {
296 None => *self = other,
298 // Carefully empty `other`.
299 let o_tail = other.list_tail.take();
300 let o_length = other.length;
301 match other.list_head.take() {
304 tail.next = link_with_prev(node, self.list_tail);
305 self.list_tail = o_tail;
306 self.length += o_length;
313 /// Add all elements from `other` to the beginning of the list
317 pub fn prepend(&mut self, mut other: DList<T>) {
318 mem::swap(self, &mut other);
322 /// Insert `elt` before the first `x` in the list where `f(x, elt)` is true,
326 pub fn insert_when(&mut self, elt: T, f: |&T, &T| -> bool) {
328 let mut it = self.mut_iter();
330 match it.peek_next() {
332 Some(x) => if f(x, &elt) { break }
340 /// Merge DList `other` into this DList, using the function `f`.
341 /// Iterate the both DList with `a` from self and `b` from `other`, and
342 /// put `a` in the result if `f(a, b)` is true, else `b`.
345 pub fn merge(&mut self, mut other: DList<T>, f: |&T, &T| -> bool) {
347 let mut it = self.mut_iter();
349 let take_a = match (it.peek_next(), other.front()) {
350 (_ , None) => return,
352 (Some(ref mut x), Some(y)) => f(*x, y),
357 it.insert_next_node(other.pop_front_node().unwrap());
365 /// Provide a forward iterator
367 pub fn iter<'a>(&'a self) -> Items<'a, T> {
368 Items{nelem: self.len(), head: &self.list_head, tail: self.list_tail}
371 /// Provide a forward iterator with mutable references
373 pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> {
374 let head_raw = match self.list_head {
375 Some(ref mut h) => Rawlink::some(*h),
376 None => Rawlink::none(),
381 tail: self.list_tail,
387 /// Consume the list into an iterator yielding elements by value
389 pub fn move_iter(self) -> MoveItems<T> {
390 MoveItems{list: self}
394 impl<T: TotalOrd> DList<T> {
395 /// Insert `elt` sorted in ascending order
399 pub fn insert_ordered(&mut self, elt: T) {
400 self.insert_when(elt, |a, b| a >= b)
405 impl<T> Drop for DList<T> {
407 // Dissolve the dlist in backwards direction
408 // Just dropping the list_head can lead to stack exhaustion
409 // when length is >> 1_000_000
410 let mut tail = self.list_tail;
412 match tail.resolve() {
415 prev.next.take(); // release Box<Node<T>>
421 self.list_head = None;
422 self.list_tail = Rawlink::none();
427 impl<'a, A> Iterator<&'a A> for Items<'a, A> {
429 fn next(&mut self) -> Option<&'a A> {
433 self.head.as_ref().map(|head| {
435 self.head = &head.next;
441 fn size_hint(&self) -> (uint, Option<uint>) {
442 (self.nelem, Some(self.nelem))
446 impl<'a, A> DoubleEndedIterator<&'a A> for Items<'a, A> {
448 fn next_back(&mut self) -> Option<&'a A> {
452 let tmp = self.tail.resolve_immut(); // FIXME: #3511: shouldn't need variable
453 tmp.as_ref().map(|prev| {
455 self.tail = prev.prev;
461 impl<'a, A> ExactSize<&'a A> for Items<'a, A> {}
463 impl<'a, A> Iterator<&'a mut A> for MutItems<'a, A> {
465 fn next(&mut self) -> Option<&'a mut A> {
469 self.head.resolve().map(|next| {
471 self.head = match next.next {
472 Some(ref mut node) => Rawlink::some(&mut **node),
473 None => Rawlink::none(),
480 fn size_hint(&self) -> (uint, Option<uint>) {
481 (self.nelem, Some(self.nelem))
485 impl<'a, A> DoubleEndedIterator<&'a mut A> for MutItems<'a, A> {
487 fn next_back(&mut self) -> Option<&'a mut A> {
491 self.tail.resolve().map(|prev| {
493 self.tail = prev.prev;
499 impl<'a, A> ExactSize<&'a mut A> for MutItems<'a, A> {}
501 /// Allow mutating the DList while iterating
502 pub trait ListInsertion<A> {
503 /// Insert `elt` just after to the element most recently returned by `.next()`
505 /// The inserted element does not appear in the iteration.
506 fn insert_next(&mut self, elt: A);
508 /// Provide a reference to the next element, without changing the iterator
509 fn peek_next<'a>(&'a mut self) -> Option<&'a mut A>;
512 // private methods for MutItems
513 impl<'a, A> MutItems<'a, A> {
514 fn insert_next_node(&mut self, mut ins_node: Box<Node<A>>) {
515 // Insert before `self.head` so that it is between the
516 // previously yielded element and self.head.
518 // The inserted node will not appear in further iteration.
519 match self.head.resolve() {
520 None => { self.list.push_back_node(ins_node); }
522 let prev_node = match node.prev.resolve() {
523 None => return self.list.push_front_node(ins_node),
526 let node_own = prev_node.next.take_unwrap();
527 ins_node.next = link_with_prev(node_own, Rawlink::some(ins_node));
528 prev_node.next = link_with_prev(ins_node, Rawlink::some(prev_node));
529 self.list.length += 1;
535 impl<'a, A> ListInsertion<A> for MutItems<'a, A> {
537 fn insert_next(&mut self, elt: A) {
538 self.insert_next_node(box Node::new(elt))
542 fn peek_next<'a>(&'a mut self) -> Option<&'a mut A> {
546 self.head.resolve().map(|head| &mut head.value)
550 impl<A> Iterator<A> for MoveItems<A> {
552 fn next(&mut self) -> Option<A> { self.list.pop_front() }
555 fn size_hint(&self) -> (uint, Option<uint>) {
556 (self.list.length, Some(self.list.length))
560 impl<A> DoubleEndedIterator<A> for MoveItems<A> {
562 fn next_back(&mut self) -> Option<A> { self.list.pop_back() }
565 impl<A> FromIterator<A> for DList<A> {
566 fn from_iter<T: Iterator<A>>(iterator: T) -> DList<A> {
567 let mut ret = DList::new();
568 ret.extend(iterator);
573 impl<A> Extendable<A> for DList<A> {
574 fn extend<T: Iterator<A>>(&mut self, mut iterator: T) {
575 for elt in iterator { self.push_back(elt); }
579 impl<A: Eq> Eq for DList<A> {
580 fn eq(&self, other: &DList<A>) -> bool {
581 self.len() == other.len() &&
582 iter::order::eq(self.iter(), other.iter())
585 fn ne(&self, other: &DList<A>) -> bool {
586 self.len() != other.len() ||
587 iter::order::ne(self.iter(), other.iter())
591 impl<A: Ord> Ord for DList<A> {
592 fn lt(&self, other: &DList<A>) -> bool {
593 iter::order::lt(self.iter(), other.iter())
595 fn le(&self, other: &DList<A>) -> bool {
596 iter::order::le(self.iter(), other.iter())
598 fn gt(&self, other: &DList<A>) -> bool {
599 iter::order::gt(self.iter(), other.iter())
601 fn ge(&self, other: &DList<A>) -> bool {
602 iter::order::ge(self.iter(), other.iter())
606 impl<A: Clone> Clone for DList<A> {
607 fn clone(&self) -> DList<A> {
608 self.iter().map(|x| x.clone()).collect()
615 use self::test::Bencher;
618 use super::{DList, Node, ListInsertion};
620 pub fn check_links<T>(list: &DList<T>) {
622 let mut last_ptr: Option<&Node<T>> = None;
623 let mut node_ptr: &Node<T>;
624 match list.list_head {
625 None => { assert_eq!(0u, list.length); return }
626 Some(ref node) => node_ptr = &**node,
629 match (last_ptr, node_ptr.prev.resolve_immut()) {
631 (None , _ ) => fail!("prev link for list_head"),
632 (Some(p), Some(pptr)) => {
633 assert_eq!(p as *Node<T>, pptr as *Node<T>);
635 _ => fail!("prev link is none, not good"),
637 match node_ptr.next {
639 last_ptr = Some(node_ptr);
649 assert_eq!(len, list.length);
654 let mut m: DList<Box<int>> = DList::new();
655 assert_eq!(m.pop_front(), None);
656 assert_eq!(m.pop_back(), None);
657 assert_eq!(m.pop_front(), None);
659 assert_eq!(m.pop_front(), Some(box 1));
662 assert_eq!(m.len(), 2);
663 assert_eq!(m.pop_front(), Some(box 2));
664 assert_eq!(m.pop_front(), Some(box 3));
665 assert_eq!(m.len(), 0);
666 assert_eq!(m.pop_front(), None);
671 assert_eq!(m.pop_front(), Some(box 1));
673 let mut n = DList::new();
677 assert_eq!(n.front().unwrap(), &3);
678 let x = n.front_mut().unwrap();
683 assert_eq!(n.back().unwrap(), &2);
684 let y = n.back_mut().unwrap();
688 assert_eq!(n.pop_front(), Some(0));
689 assert_eq!(n.pop_front(), Some(1));
693 fn generate_test() -> DList<int> {
694 list_from(&[0,1,2,3,4,5,6])
698 fn list_from<T: Clone>(v: &[T]) -> DList<T> {
699 v.iter().map(|x| (*x).clone()).collect()
705 let mut m = DList::new();
706 let mut n = DList::new();
709 assert_eq!(m.len(), 1);
710 assert_eq!(m.pop_back(), Some(2));
714 let mut m = DList::new();
715 let n = DList::new();
718 assert_eq!(m.len(), 1);
719 assert_eq!(m.pop_back(), Some(2));
723 let v = vec![1,2,3,4,5];
724 let u = vec![9,8,1,2,3,4,5];
725 let mut m = list_from(v.as_slice());
726 m.append(list_from(u.as_slice()));
728 let sum = v.append(u.as_slice());
729 assert_eq!(sum.len(), m.len());
730 for elt in sum.move_iter() {
731 assert_eq!(m.pop_front(), Some(elt))
738 let mut m = DList::new();
739 let mut n = DList::new();
742 assert_eq!(m.len(), 1);
743 assert_eq!(m.pop_back(), Some(2));
747 let v = vec![1,2,3,4,5];
748 let u = vec![9,8,1,2,3,4,5];
749 let mut m = list_from(v.as_slice());
750 m.prepend(list_from(u.as_slice()));
752 let sum = u.append(v.as_slice());
753 assert_eq!(sum.len(), m.len());
754 for elt in sum.move_iter() {
755 assert_eq!(m.pop_front(), Some(elt))
761 let mut n: DList<int> = DList::new();
762 n.rotate_backward(); check_links(&n);
763 assert_eq!(n.len(), 0);
764 n.rotate_forward(); check_links(&n);
765 assert_eq!(n.len(), 0);
767 let v = vec![1,2,3,4,5];
768 let mut m = list_from(v.as_slice());
769 m.rotate_backward(); check_links(&m);
770 m.rotate_forward(); check_links(&m);
771 assert_eq!(v.iter().collect::<Vec<&int>>(), m.iter().collect());
772 m.rotate_forward(); check_links(&m);
773 m.rotate_forward(); check_links(&m);
774 m.pop_front(); check_links(&m);
775 m.rotate_forward(); check_links(&m);
776 m.rotate_backward(); check_links(&m);
777 m.push_front(9); check_links(&m);
778 m.rotate_forward(); check_links(&m);
779 assert_eq!(vec![3,9,5,1,2], m.move_iter().collect());
784 let m = generate_test();
785 for (i, elt) in m.iter().enumerate() {
786 assert_eq!(i as int, *elt);
788 let mut n = DList::new();
789 assert_eq!(n.iter().next(), None);
791 let mut it = n.iter();
792 assert_eq!(it.size_hint(), (1, Some(1)));
793 assert_eq!(it.next().unwrap(), &4);
794 assert_eq!(it.size_hint(), (0, Some(0)));
795 assert_eq!(it.next(), None);
799 fn test_iterator_clone() {
800 let mut n = DList::new();
804 let mut it = n.iter();
806 let mut jt = it.clone();
807 assert_eq!(it.next(), jt.next());
808 assert_eq!(it.next_back(), jt.next_back());
809 assert_eq!(it.next(), jt.next());
813 fn test_iterator_double_end() {
814 let mut n = DList::new();
815 assert_eq!(n.iter().next(), None);
819 let mut it = n.iter();
820 assert_eq!(it.size_hint(), (3, Some(3)));
821 assert_eq!(it.next().unwrap(), &6);
822 assert_eq!(it.size_hint(), (2, Some(2)));
823 assert_eq!(it.next_back().unwrap(), &4);
824 assert_eq!(it.size_hint(), (1, Some(1)));
825 assert_eq!(it.next_back().unwrap(), &5);
826 assert_eq!(it.next_back(), None);
827 assert_eq!(it.next(), None);
832 let m = generate_test();
833 for (i, elt) in m.iter().rev().enumerate() {
834 assert_eq!((6 - i) as int, *elt);
836 let mut n = DList::new();
837 assert_eq!(n.iter().rev().next(), None);
839 let mut it = n.iter().rev();
840 assert_eq!(it.size_hint(), (1, Some(1)));
841 assert_eq!(it.next().unwrap(), &4);
842 assert_eq!(it.size_hint(), (0, Some(0)));
843 assert_eq!(it.next(), None);
848 let mut m = generate_test();
849 let mut len = m.len();
850 for (i, elt) in m.mut_iter().enumerate() {
851 assert_eq!(i as int, *elt);
855 let mut n = DList::new();
856 assert!(n.mut_iter().next().is_none());
859 let mut it = n.mut_iter();
860 assert_eq!(it.size_hint(), (2, Some(2)));
861 assert!(it.next().is_some());
862 assert!(it.next().is_some());
863 assert_eq!(it.size_hint(), (0, Some(0)));
864 assert!(it.next().is_none());
868 fn test_iterator_mut_double_end() {
869 let mut n = DList::new();
870 assert!(n.mut_iter().next_back().is_none());
874 let mut it = n.mut_iter();
875 assert_eq!(it.size_hint(), (3, Some(3)));
876 assert_eq!(*it.next().unwrap(), 6);
877 assert_eq!(it.size_hint(), (2, Some(2)));
878 assert_eq!(*it.next_back().unwrap(), 4);
879 assert_eq!(it.size_hint(), (1, Some(1)));
880 assert_eq!(*it.next_back().unwrap(), 5);
881 assert!(it.next_back().is_none());
882 assert!(it.next().is_none());
886 fn test_insert_prev() {
887 let mut m = list_from(&[0,2,4,6,8]);
890 let mut it = m.mut_iter();
896 it.insert_next(*elt + 1);
897 match it.peek_next() {
898 Some(x) => assert_eq!(*x, *elt + 2),
899 None => assert_eq!(8, *elt),
908 assert_eq!(m.len(), 3 + len * 2);
909 assert_eq!(m.move_iter().collect::<Vec<int>>(), vec![-2,0,1,2,3,4,5,6,7,8,9,0,1]);
914 let mut m = list_from([0, 1, 3, 5, 6, 7, 2]);
915 let n = list_from([-1, 0, 0, 7, 7, 9]);
916 let len = m.len() + n.len();
917 m.merge(n, |a, b| a <= b);
918 assert_eq!(m.len(), len);
920 let res = m.move_iter().collect::<Vec<int>>();
921 assert_eq!(res, vec![-1, 0, 0, 0, 1, 3, 5, 6, 7, 2, 7, 7, 9]);
925 fn test_insert_ordered() {
926 let mut n = DList::new();
928 assert_eq!(n.len(), 1);
929 assert_eq!(n.pop_front(), Some(1));
931 let mut m = DList::new();
936 assert_eq!(vec![2,3,4], m.move_iter().collect::<Vec<int>>());
940 fn test_mut_rev_iter() {
941 let mut m = generate_test();
942 for (i, elt) in m.mut_iter().rev().enumerate() {
943 assert_eq!((6-i) as int, *elt);
945 let mut n = DList::new();
946 assert!(n.mut_iter().rev().next().is_none());
948 let mut it = n.mut_iter().rev();
949 assert!(it.next().is_some());
950 assert!(it.next().is_none());
955 let n = list_from([1,2,3]);
958 assert_eq!(&[&1,&2,&3], n.iter().collect::<Vec<&int>>().as_slice());
964 let mut n: DList<u8> = list_from([]);
965 let mut m = list_from([]);
972 let n = list_from([2,3,4]);
973 let m = list_from([1,2,3]);
979 let n: DList<int> = list_from([]);
980 let m = list_from([1,2,3]);
990 let n = list_from([nan]);
991 let m = list_from([nan]);
997 let n = list_from([nan]);
998 let one = list_from([1.0]);
1000 assert!(!(n > one));
1001 assert!(!(n <= one));
1002 assert!(!(n >= one));
1004 let u = list_from([1.0,2.0,nan]);
1005 let v = list_from([1.0,2.0,3.0]);
1011 let s = list_from([1.0,2.0,4.0,2.0]);
1012 let t = list_from([1.0,2.0,3.0,2.0]);
1015 assert!(!(s <= one));
1021 for _ in range(0, 25) {
1029 fn fuzz_test(sz: int) {
1030 let mut m: DList<int> = DList::new();
1032 for i in range(0, sz) {
1034 let r: u8 = rand::random();
1058 for (a, &b) in m.move_iter().zip(v.iter()) {
1062 assert_eq!(i, v.len());
1066 fn bench_collect_into(b: &mut test::Bencher) {
1069 let _: DList<int> = v.iter().map(|x| *x).collect();
1074 fn bench_push_front(b: &mut test::Bencher) {
1075 let mut m: DList<int> = DList::new();
1082 fn bench_push_back(b: &mut test::Bencher) {
1083 let mut m: DList<int> = DList::new();
1090 fn bench_push_back_pop_back(b: &mut test::Bencher) {
1091 let mut m: DList<int> = DList::new();
1099 fn bench_push_front_pop_front(b: &mut test::Bencher) {
1100 let mut m: DList<int> = DList::new();
1108 fn bench_rotate_forward(b: &mut test::Bencher) {
1109 let mut m: DList<int> = DList::new();
1118 fn bench_rotate_backward(b: &mut test::Bencher) {
1119 let mut m: DList<int> = DList::new();
1123 m.rotate_backward();
1128 fn bench_iter(b: &mut test::Bencher) {
1129 let v = &[0, ..128];
1130 let m: DList<int> = v.iter().map(|&x|x).collect();
1132 assert!(m.iter().len() == 128);
1136 fn bench_iter_mut(b: &mut test::Bencher) {
1137 let v = &[0, ..128];
1138 let mut m: DList<int> = v.iter().map(|&x|x).collect();
1140 assert!(m.mut_iter().len() == 128);
1144 fn bench_iter_rev(b: &mut test::Bencher) {
1145 let v = &[0, ..128];
1146 let m: DList<int> = v.iter().map(|&x|x).collect();
1148 assert!(m.iter().rev().len() == 128);
1152 fn bench_iter_mut_rev(b: &mut test::Bencher) {
1153 let v = &[0, ..128];
1154 let mut m: DList<int> = v.iter().map(|&x|x).collect();
1156 assert!(m.mut_iter().rev().len() == 128);