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 and is thus
14 //! efficiently usable as a double-ended queue.
16 // DList is constructed like a singly-linked list over the field `next`.
17 // including the last link being None; each Node owns its `next` field.
19 // Backlinks over DList::prev are raw pointers that form a full chain in
20 // the reverse direction.
26 use alloc::boxed::Box;
27 use core::cmp::Ordering;
28 use core::default::Default;
30 use core::hash::{Writer, Hasher, Hash};
31 use core::iter::{self, FromIterator};
35 /// A doubly-linked list.
40 list_tail: Rawlink<Node<T>>,
43 type Link<T> = Option<Box<Node<T>>>;
49 impl<T> Copy for Rawlink<T> {}
50 unsafe impl<T:'static+Send> Send for Rawlink<T> {}
51 unsafe impl<T:Send+Sync> Sync for Rawlink<T> {}
55 prev: Rawlink<Node<T>>,
59 /// An iterator over references to the items of a `DList`.
61 pub struct Iter<'a, T:'a> {
63 tail: Rawlink<Node<T>>,
67 // FIXME #19839: deriving is too aggressive on the bounds (T doesn't need to be Clone).
69 impl<'a, T> Clone for Iter<'a, T> {
70 fn clone(&self) -> Iter<'a, T> {
72 head: self.head.clone(),
79 /// An iterator over mutable references to the items of a `DList`.
81 pub struct IterMut<'a, T:'a> {
82 list: &'a mut DList<T>,
83 head: Rawlink<Node<T>>,
84 tail: Rawlink<Node<T>>,
88 /// An iterator over mutable references to the items of a `DList`.
91 pub struct IntoIter<T> {
95 /// Rawlink is a type like Option<T> but for holding a raw pointer
97 /// Like Option::None for Rawlink
98 fn none() -> Rawlink<T> {
99 Rawlink{p: ptr::null_mut()}
102 /// Like Option::Some for Rawlink
103 fn some(n: &mut T) -> Rawlink<T> {
107 /// Convert the `Rawlink` into an Option value
108 fn resolve_immut<'a>(&self) -> Option<&'a T> {
110 mem::transmute(self.p.as_ref())
114 /// Convert the `Rawlink` into an Option value
115 fn resolve<'a>(&mut self) -> Option<&'a mut T> {
116 if self.p.is_null() {
119 Some(unsafe { mem::transmute(self.p) })
123 /// Return the `Rawlink` and replace with `Rawlink::none()`
124 fn take(&mut self) -> Rawlink<T> {
125 mem::replace(self, Rawlink::none())
129 impl<T> Clone for Rawlink<T> {
131 fn clone(&self) -> Rawlink<T> {
137 fn new(v: T) -> Node<T> {
138 Node{value: v, next: None, prev: Rawlink::none()}
142 /// Set the .prev field on `next`, then return `Some(next)`
143 fn link_with_prev<T>(mut next: Box<Node<T>>, prev: Rawlink<Node<T>>)
151 /// Add a Node first in the list
153 fn push_front_node(&mut self, mut new_head: Box<Node<T>>) {
154 match self.list_head {
156 self.list_tail = Rawlink::some(&mut *new_head);
157 self.list_head = link_with_prev(new_head, Rawlink::none());
159 Some(ref mut head) => {
160 new_head.prev = Rawlink::none();
161 head.prev = Rawlink::some(&mut *new_head);
162 mem::swap(head, &mut new_head);
163 head.next = Some(new_head);
169 /// Remove the first Node and return it, or None if the list is empty
171 fn pop_front_node(&mut self) -> Option<Box<Node<T>>> {
172 self.list_head.take().map(|mut front_node| {
174 match front_node.next.take() {
175 Some(node) => self.list_head = link_with_prev(node, Rawlink::none()),
176 None => self.list_tail = Rawlink::none()
182 /// Add a Node last in the list
184 fn push_back_node(&mut self, mut new_tail: Box<Node<T>>) {
185 match self.list_tail.resolve() {
186 None => return self.push_front_node(new_tail),
188 self.list_tail = Rawlink::some(&mut *new_tail);
189 tail.next = link_with_prev(new_tail, Rawlink::some(tail));
195 /// Remove the last Node and return it, or None if the list is empty
197 fn pop_back_node(&mut self) -> Option<Box<Node<T>>> {
198 self.list_tail.resolve().map_or(None, |tail| {
200 self.list_tail = tail.prev;
201 match tail.prev.resolve() {
202 None => self.list_head.take(),
203 Some(tail_prev) => tail_prev.next.take()
210 impl<T> Default for DList<T> {
213 fn default() -> DList<T> { DList::new() }
217 /// Creates an empty `DList`.
220 pub fn new() -> DList<T> {
221 DList{list_head: None, list_tail: Rawlink::none(), length: 0}
224 /// Adds all elements from `other` to the end of the list.
226 /// This operation should compute in O(1) time.
231 /// use std::collections::DList;
233 /// let mut a = DList::new();
234 /// let mut b = DList::new();
242 /// for e in a.iter() {
243 /// println!("{}", e); // prints 1, then 2, then 3, then 4
246 #[unstable = "append should be by-mutable-reference"]
247 pub fn append(&mut self, mut other: DList<T>) {
248 match self.list_tail.resolve() {
249 None => *self = other,
251 // Carefully empty `other`.
252 let o_tail = other.list_tail.take();
253 let o_length = other.length;
254 match other.list_head.take() {
257 tail.next = link_with_prev(node, self.list_tail);
258 self.list_tail = o_tail;
259 self.length += o_length;
266 /// Provides a forward iterator.
269 pub fn iter(&self) -> Iter<T> {
270 Iter{nelem: self.len(), head: &self.list_head, tail: self.list_tail}
273 /// Provides a forward iterator with mutable references.
276 pub fn iter_mut(&mut self) -> IterMut<T> {
277 let head_raw = match self.list_head {
278 Some(ref mut h) => Rawlink::some(&mut **h),
279 None => Rawlink::none(),
284 tail: self.list_tail,
289 /// Consumes the list into an iterator yielding elements by value.
292 pub fn into_iter(self) -> IntoIter<T> {
296 /// Returns `true` if the `DList` is empty.
298 /// This operation should compute in O(1) time.
301 pub fn is_empty(&self) -> bool {
302 self.list_head.is_none()
305 /// Returns the length of the `DList`.
307 /// This operation should compute in O(1) time.
310 pub fn len(&self) -> uint {
314 /// Removes all elements from the `DList`.
316 /// This operation should compute in O(n) time.
319 pub fn clear(&mut self) {
323 /// Provides a reference to the front element, or `None` if the list is
327 pub fn front(&self) -> Option<&T> {
328 self.list_head.as_ref().map(|head| &head.value)
331 /// Provides a mutable reference to the front element, or `None` if the list
335 pub fn front_mut(&mut self) -> Option<&mut T> {
336 self.list_head.as_mut().map(|head| &mut head.value)
339 /// Provides a reference to the back element, or `None` if the list is
343 pub fn back(&self) -> Option<&T> {
344 self.list_tail.resolve_immut().as_ref().map(|tail| &tail.value)
347 /// Provides a mutable reference to the back element, or `None` if the list
351 pub fn back_mut(&mut self) -> Option<&mut T> {
352 self.list_tail.resolve().map(|tail| &mut tail.value)
355 /// Adds an element first in the list.
357 /// This operation should compute in O(1) time.
359 pub fn push_front(&mut self, elt: T) {
360 self.push_front_node(box Node::new(elt))
363 /// Removes the first element and returns it, or `None` if the list is
366 /// This operation should compute in O(1) time.
368 pub fn pop_front(&mut self) -> Option<T> {
369 self.pop_front_node().map(|box Node{value, ..}| value)
372 /// Appends an element to the back of a list
377 /// use std::collections::DList;
379 /// let mut d = DList::new();
382 /// assert_eq!(3, *d.back().unwrap());
385 pub fn push_back(&mut self, elt: T) {
386 self.push_back_node(box Node::new(elt))
389 /// Removes the last element from a list and returns it, or `None` if
395 /// use std::collections::DList;
397 /// let mut d = DList::new();
398 /// assert_eq!(d.pop_back(), None);
401 /// assert_eq!(d.pop_back(), Some(3));
404 pub fn pop_back(&mut self) -> Option<T> {
405 self.pop_back_node().map(|box Node{value, ..}| value)
411 impl<T> Drop for DList<T> {
413 // Dissolve the dlist in backwards direction
414 // Just dropping the list_head can lead to stack exhaustion
415 // when length is >> 1_000_000
416 let mut tail = self.list_tail;
418 match tail.resolve() {
421 prev.next.take(); // release Box<Node<T>>
427 self.list_head = None;
428 self.list_tail = Rawlink::none();
433 impl<'a, A> Iterator for Iter<'a, A> {
437 fn next(&mut self) -> Option<&'a A> {
441 self.head.as_ref().map(|head| {
443 self.head = &head.next;
449 fn size_hint(&self) -> (uint, Option<uint>) {
450 (self.nelem, Some(self.nelem))
455 impl<'a, A> DoubleEndedIterator for Iter<'a, A> {
457 fn next_back(&mut self) -> Option<&'a A> {
461 self.tail.resolve_immut().as_ref().map(|prev| {
463 self.tail = prev.prev;
470 impl<'a, A> ExactSizeIterator for Iter<'a, A> {}
473 impl<'a, A> Iterator for IterMut<'a, A> {
474 type Item = &'a mut A;
476 fn next(&mut self) -> Option<&'a mut A> {
480 self.head.resolve().map(|next| {
482 self.head = match next.next {
483 Some(ref mut node) => Rawlink::some(&mut **node),
484 None => Rawlink::none(),
491 fn size_hint(&self) -> (uint, Option<uint>) {
492 (self.nelem, Some(self.nelem))
497 impl<'a, A> DoubleEndedIterator for IterMut<'a, A> {
499 fn next_back(&mut self) -> Option<&'a mut A> {
503 self.tail.resolve().map(|prev| {
505 self.tail = prev.prev;
512 impl<'a, A> ExactSizeIterator for IterMut<'a, A> {}
514 // private methods for IterMut
515 impl<'a, A> IterMut<'a, A> {
516 fn insert_next_node(&mut self, mut ins_node: Box<Node<A>>) {
517 // Insert before `self.head` so that it is between the
518 // previously yielded element and self.head.
520 // The inserted node will not appear in further iteration.
521 match self.head.resolve() {
522 None => { self.list.push_back_node(ins_node); }
524 let prev_node = match node.prev.resolve() {
525 None => return self.list.push_front_node(ins_node),
528 let node_own = prev_node.next.take().unwrap();
529 ins_node.next = link_with_prev(node_own, Rawlink::some(&mut *ins_node));
530 prev_node.next = link_with_prev(ins_node, Rawlink::some(prev_node));
531 self.list.length += 1;
537 impl<'a, A> IterMut<'a, A> {
538 /// Inserts `elt` just after the element most recently returned by `.next()`.
539 /// The inserted element does not appear in the iteration.
544 /// use std::collections::DList;
546 /// let mut list: DList<int> = vec![1, 3, 4].into_iter().collect();
549 /// let mut it = list.iter_mut();
550 /// assert_eq!(it.next().unwrap(), &1);
551 /// // insert `2` after `1`
552 /// it.insert_next(2);
555 /// let vec: Vec<int> = list.into_iter().collect();
556 /// assert_eq!(vec, vec![1i, 2, 3, 4]);
560 #[unstable = "this is probably better handled by a cursor type -- we'll see"]
561 pub fn insert_next(&mut self, elt: A) {
562 self.insert_next_node(box Node::new(elt))
565 /// Provides a reference to the next element, without changing the iterator.
570 /// use std::collections::DList;
572 /// let mut list: DList<int> = vec![1, 2, 3].into_iter().collect();
574 /// let mut it = list.iter_mut();
575 /// assert_eq!(it.next().unwrap(), &1);
576 /// assert_eq!(it.peek_next().unwrap(), &2);
577 /// // We just peeked at 2, so it was not consumed from the iterator.
578 /// assert_eq!(it.next().unwrap(), &2);
581 #[unstable = "this is probably better handled by a cursor type -- we'll see"]
582 pub fn peek_next(&mut self) -> Option<&mut A> {
586 self.head.resolve().map(|head| &mut head.value)
591 impl<A> Iterator for IntoIter<A> {
595 fn next(&mut self) -> Option<A> { self.list.pop_front() }
598 fn size_hint(&self) -> (uint, Option<uint>) {
599 (self.list.length, Some(self.list.length))
604 impl<A> DoubleEndedIterator for IntoIter<A> {
606 fn next_back(&mut self) -> Option<A> { self.list.pop_back() }
610 impl<A> FromIterator<A> for DList<A> {
611 fn from_iter<T: Iterator<Item=A>>(iterator: T) -> DList<A> {
612 let mut ret = DList::new();
613 ret.extend(iterator);
619 impl<A> Extend<A> for DList<A> {
620 fn extend<T: Iterator<Item=A>>(&mut self, mut iterator: T) {
621 for elt in iterator { self.push_back(elt); }
626 impl<A: PartialEq> PartialEq for DList<A> {
627 fn eq(&self, other: &DList<A>) -> bool {
628 self.len() == other.len() &&
629 iter::order::eq(self.iter(), other.iter())
632 fn ne(&self, other: &DList<A>) -> bool {
633 self.len() != other.len() ||
634 iter::order::ne(self.iter(), other.iter())
639 impl<A: Eq> Eq for DList<A> {}
642 impl<A: PartialOrd> PartialOrd for DList<A> {
643 fn partial_cmp(&self, other: &DList<A>) -> Option<Ordering> {
644 iter::order::partial_cmp(self.iter(), other.iter())
649 impl<A: Ord> Ord for DList<A> {
651 fn cmp(&self, other: &DList<A>) -> Ordering {
652 iter::order::cmp(self.iter(), other.iter())
657 impl<A: Clone> Clone for DList<A> {
658 fn clone(&self) -> DList<A> {
659 self.iter().map(|x| x.clone()).collect()
664 impl<A: fmt::Show> fmt::Show for DList<A> {
665 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
666 try!(write!(f, "DList ["));
668 for (i, e) in self.iter().enumerate() {
669 if i != 0 { try!(write!(f, ", ")); }
670 try!(write!(f, "{:?}", *e));
678 impl<S: Writer + Hasher, A: Hash<S>> Hash<S> for DList<A> {
679 fn hash(&self, state: &mut S) {
680 self.len().hash(state);
681 for elt in self.iter() {
691 use std::hash::{self, SipHasher};
692 use std::thread::Thread;
696 use super::{DList, Node};
698 pub fn check_links<T>(list: &DList<T>) {
700 let mut last_ptr: Option<&Node<T>> = None;
701 let mut node_ptr: &Node<T>;
702 match list.list_head {
703 None => { assert_eq!(0u, list.length); return }
704 Some(ref node) => node_ptr = &**node,
707 match (last_ptr, node_ptr.prev.resolve_immut()) {
709 (None , _ ) => panic!("prev link for list_head"),
710 (Some(p), Some(pptr)) => {
711 assert_eq!(p as *const Node<T>, pptr as *const Node<T>);
713 _ => panic!("prev link is none, not good"),
715 match node_ptr.next {
717 last_ptr = Some(node_ptr);
727 assert_eq!(len, list.length);
732 let mut m: DList<Box<int>> = DList::new();
733 assert_eq!(m.pop_front(), None);
734 assert_eq!(m.pop_back(), None);
735 assert_eq!(m.pop_front(), None);
737 assert_eq!(m.pop_front(), Some(box 1));
740 assert_eq!(m.len(), 2);
741 assert_eq!(m.pop_front(), Some(box 2));
742 assert_eq!(m.pop_front(), Some(box 3));
743 assert_eq!(m.len(), 0);
744 assert_eq!(m.pop_front(), None);
749 assert_eq!(m.pop_front(), Some(box 1));
751 let mut n = DList::new();
755 assert_eq!(n.front().unwrap(), &3);
756 let x = n.front_mut().unwrap();
761 assert_eq!(n.back().unwrap(), &2);
762 let y = n.back_mut().unwrap();
766 assert_eq!(n.pop_front(), Some(0));
767 assert_eq!(n.pop_front(), Some(1));
771 fn generate_test() -> DList<int> {
772 list_from(&[0i,1,2,3,4,5,6])
776 fn list_from<T: Clone>(v: &[T]) -> DList<T> {
777 v.iter().map(|x| (*x).clone()).collect()
782 let m = generate_test();
783 for (i, elt) in m.iter().enumerate() {
784 assert_eq!(i as int, *elt);
786 let mut n = DList::new();
787 assert_eq!(n.iter().next(), None);
789 let mut it = n.iter();
790 assert_eq!(it.size_hint(), (1, Some(1)));
791 assert_eq!(it.next().unwrap(), &4);
792 assert_eq!(it.size_hint(), (0, Some(0)));
793 assert_eq!(it.next(), None);
797 fn test_iterator_clone() {
798 let mut n = DList::new();
802 let mut it = n.iter();
804 let mut jt = it.clone();
805 assert_eq!(it.next(), jt.next());
806 assert_eq!(it.next_back(), jt.next_back());
807 assert_eq!(it.next(), jt.next());
811 fn test_iterator_double_end() {
812 let mut n = DList::new();
813 assert_eq!(n.iter().next(), None);
817 let mut it = n.iter();
818 assert_eq!(it.size_hint(), (3, Some(3)));
819 assert_eq!(it.next().unwrap(), &6);
820 assert_eq!(it.size_hint(), (2, Some(2)));
821 assert_eq!(it.next_back().unwrap(), &4);
822 assert_eq!(it.size_hint(), (1, Some(1)));
823 assert_eq!(it.next_back().unwrap(), &5);
824 assert_eq!(it.next_back(), None);
825 assert_eq!(it.next(), None);
830 let m = generate_test();
831 for (i, elt) in m.iter().rev().enumerate() {
832 assert_eq!((6 - i) as int, *elt);
834 let mut n = DList::new();
835 assert_eq!(n.iter().rev().next(), None);
837 let mut it = n.iter().rev();
838 assert_eq!(it.size_hint(), (1, Some(1)));
839 assert_eq!(it.next().unwrap(), &4);
840 assert_eq!(it.size_hint(), (0, Some(0)));
841 assert_eq!(it.next(), None);
846 let mut m = generate_test();
847 let mut len = m.len();
848 for (i, elt) in m.iter_mut().enumerate() {
849 assert_eq!(i as int, *elt);
853 let mut n = DList::new();
854 assert!(n.iter_mut().next().is_none());
857 let mut it = n.iter_mut();
858 assert_eq!(it.size_hint(), (2, Some(2)));
859 assert!(it.next().is_some());
860 assert!(it.next().is_some());
861 assert_eq!(it.size_hint(), (0, Some(0)));
862 assert!(it.next().is_none());
866 fn test_iterator_mut_double_end() {
867 let mut n = DList::new();
868 assert!(n.iter_mut().next_back().is_none());
872 let mut it = n.iter_mut();
873 assert_eq!(it.size_hint(), (3, Some(3)));
874 assert_eq!(*it.next().unwrap(), 6);
875 assert_eq!(it.size_hint(), (2, Some(2)));
876 assert_eq!(*it.next_back().unwrap(), 4);
877 assert_eq!(it.size_hint(), (1, Some(1)));
878 assert_eq!(*it.next_back().unwrap(), 5);
879 assert!(it.next_back().is_none());
880 assert!(it.next().is_none());
884 fn test_insert_prev() {
885 let mut m = list_from(&[0i,2,4,6,8]);
888 let mut it = m.iter_mut();
894 it.insert_next(*elt + 1);
895 match it.peek_next() {
896 Some(x) => assert_eq!(*x, *elt + 2),
897 None => assert_eq!(8, *elt),
906 assert_eq!(m.len(), 3 + len * 2);
907 assert_eq!(m.into_iter().collect::<Vec<int>>(), vec![-2,0,1,2,3,4,5,6,7,8,9,0,1]);
911 fn test_mut_rev_iter() {
912 let mut m = generate_test();
913 for (i, elt) in m.iter_mut().rev().enumerate() {
914 assert_eq!((6-i) as int, *elt);
916 let mut n = DList::new();
917 assert!(n.iter_mut().rev().next().is_none());
919 let mut it = n.iter_mut().rev();
920 assert!(it.next().is_some());
921 assert!(it.next().is_none());
926 let n = list_from(&[1i,2,3]);
927 Thread::scoped(move || {
929 let a: &[_] = &[&1,&2,&3];
930 assert_eq!(a, n.iter().collect::<Vec<&int>>());
931 }).join().ok().unwrap();
936 let mut n: DList<u8> = list_from(&[]);
937 let mut m = list_from(&[]);
944 let n = list_from(&[2i,3,4]);
945 let m = list_from(&[1i,2,3]);
951 let mut x = DList::new();
952 let mut y = DList::new();
954 assert!(hash::hash::<_, SipHasher>(&x) == hash::hash::<_, SipHasher>(&y));
964 assert!(hash::hash::<_, SipHasher>(&x) == hash::hash::<_, SipHasher>(&y));
969 let n: DList<int> = list_from(&[]);
970 let m = list_from(&[1i,2,3]);
979 let nan = 0.0f64/0.0;
980 let n = list_from(&[nan]);
981 let m = list_from(&[nan]);
987 let n = list_from(&[nan]);
988 let one = list_from(&[1.0f64]);
991 assert!(!(n <= one));
992 assert!(!(n >= one));
994 let u = list_from(&[1.0f64,2.0,nan]);
995 let v = list_from(&[1.0f64,2.0,3.0]);
1001 let s = list_from(&[1.0f64,2.0,4.0,2.0]);
1002 let t = list_from(&[1.0f64,2.0,3.0,2.0]);
1005 assert!(!(s <= one));
1011 for _ in range(0u, 25) {
1020 let list: DList<int> = range(0i, 10).collect();
1021 assert_eq!(format!("{:?}", list), "DList [0i, 1i, 2i, 3i, 4i, 5i, 6i, 7i, 8i, 9i]");
1023 let list: DList<&str> = vec!["just", "one", "test", "more"].iter()
1026 assert_eq!(format!("{:?}", list), "DList [\"just\", \"one\", \"test\", \"more\"]");
1030 fn fuzz_test(sz: int) {
1031 let mut m: DList<int> = DList::new();
1033 for i in range(0, sz) {
1035 let r: u8 = rand::random();
1061 for (a, &b) in m.into_iter().zip(v.iter()) {
1065 assert_eq!(i, v.len());
1068 #[allow(deprecated)]
1072 let mut m = DList::new();
1073 let mut n = DList::new();
1076 assert_eq!(m.len(), 1);
1077 assert_eq!(m.pop_back(), Some(2));
1081 let mut m = DList::new();
1082 let n = DList::new();
1085 assert_eq!(m.len(), 1);
1086 assert_eq!(m.pop_back(), Some(2));
1090 let v = vec![1i,2,3,4,5];
1091 let u = vec![9i,8,1,2,3,4,5];
1092 let mut m = list_from(v.as_slice());
1093 m.append(list_from(u.as_slice()));
1096 sum.push_all(u.as_slice());
1097 assert_eq!(sum.len(), m.len());
1098 for elt in sum.into_iter() {
1099 assert_eq!(m.pop_front(), Some(elt))
1104 fn bench_collect_into(b: &mut test::Bencher) {
1107 let _: DList<int> = v.iter().map(|x| *x).collect();
1112 fn bench_push_front(b: &mut test::Bencher) {
1113 let mut m: DList<int> = DList::new();
1120 fn bench_push_back(b: &mut test::Bencher) {
1121 let mut m: DList<int> = DList::new();
1128 fn bench_push_back_pop_back(b: &mut test::Bencher) {
1129 let mut m: DList<int> = DList::new();
1137 fn bench_push_front_pop_front(b: &mut test::Bencher) {
1138 let mut m: DList<int> = DList::new();
1146 fn bench_iter(b: &mut test::Bencher) {
1148 let m: DList<int> = v.iter().map(|&x|x).collect();
1150 assert!(m.iter().count() == 128);
1154 fn bench_iter_mut(b: &mut test::Bencher) {
1156 let mut m: DList<int> = v.iter().map(|&x|x).collect();
1158 assert!(m.iter_mut().count() == 128);
1162 fn bench_iter_rev(b: &mut test::Bencher) {
1164 let m: DList<int> = v.iter().map(|&x|x).collect();
1166 assert!(m.iter().rev().count() == 128);
1170 fn bench_iter_mut_rev(b: &mut test::Bencher) {
1172 let mut m: DList<int> = v.iter().map(|&x|x).collect();
1174 assert!(m.iter_mut().rev().count() == 128);