From 60cb9c003c48f29396470611e0caa544f3acea89 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 21 Jul 2013 19:31:40 +0200 Subject: [PATCH 01/10] serialize: implement Encodable for DList This impl was missing for unknown reason. --- src/libextra/serialize.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs index 679e5e46547..600c7c10fec 100644 --- a/src/libextra/serialize.rs +++ b/src/libextra/serialize.rs @@ -662,6 +662,19 @@ impl< } } +impl< + S: Encoder, + T: Encodable +> Encodable for DList { + fn encode(&self, s: &mut S) { + do s.emit_seq(self.len()) |s| { + for self.iter().enumerate().advance |(i, e)| { + s.emit_seq_elt(i, |s| e.encode(s)); + } + } + } +} + impl> Decodable for DList { fn decode(d: &mut D) -> DList { let mut list = DList::new(); From 5336bdcab1b452e2192332b3397f315d4ee51e51 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 21 Jul 2013 19:31:40 +0200 Subject: [PATCH 02/10] dlist: Simplify match clauses to use Option methods Make the core Deque implementation a bit simpler by using Option methods when we simply map on a Some value, and deduplicate some common lines. --- src/libextra/dlist.rs | 98 +++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 65 deletions(-) diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index fe05b48988e..6d9b9f8efad 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -175,21 +175,12 @@ impl Deque for DList { /// /// O(1) fn pop_back(&mut self) -> Option { - match self.list_tail.resolve() { - None => None, - Some(tail) => { - self.length -= 1; - let tail_own = match tail.prev.resolve() { - None => { - self.list_tail = Rawlink::none(); - self.list_head.take_unwrap() - }, - Some(tail_prev) => { - self.list_tail = tail.prev; - tail_prev.next.take_unwrap() - } - }; - Some(tail_own.value) + do self.list_tail.resolve().map_consume |tail| { + self.length -= 1; + self.list_tail = tail.prev; + match tail.prev.resolve() { + None => self.list_head.take_unwrap().value, + Some(tail_prev) => tail_prev.next.take_unwrap().value } } } @@ -217,21 +208,13 @@ impl Deque for DList { /// /// O(1) fn pop_front(&mut self) -> Option { - match self.list_head.take() { - None => None, - Some(old_head) => { - self.length -= 1; - match *old_head { - Node{value: value, next: Some(next), prev: _} => { - self.list_head = link_with_prev(next, Rawlink::none()); - Some(value) - } - Node{value: value, next: None, prev: _} => { - self.list_tail = Rawlink::none(); - Some(value) - } - } + do self.list_head.take().map_consume |~Node{value, next, _}| { + self.length -= 1; + match next { + Some(node) => self.list_head = link_with_prev(node, Rawlink::none()), + None => self.list_tail = Rawlink::none() } + value } } } @@ -251,7 +234,7 @@ impl DList { None => *self = other, Some(tail) => { match other { - DList{list_head: None, list_tail: _, length: _} => return, + DList{list_head: None, _} => return, DList{list_head: Some(node), list_tail: o_tail, length: o_length} => { tail.next = link_with_prev(node, self.list_tail); self.list_tail = o_tail; @@ -377,13 +360,10 @@ impl<'self, A> Iterator<&'self A> for DListIterator<'self, A> { if self.nelem == 0 { return None; } - match *self.head { - None => None, - Some(ref head) => { - self.nelem -= 1; - self.head = &head.next; - Some(&head.value) - } + do self.head.map |head| { + self.nelem -= 1; + self.head = &head.next; + &head.value } } @@ -399,13 +379,10 @@ impl<'self, A> DoubleEndedIterator<&'self A> for DListIterator<'self, A> { if self.nelem == 0 { return None; } - match self.tail.resolve() { - None => None, - Some(prev) => { - self.nelem -= 1; - self.tail = prev.prev; - Some(&prev.value) - } + do self.tail.resolve().map_consume |prev| { + self.nelem -= 1; + self.tail = prev.prev; + &prev.value } } } @@ -416,16 +393,13 @@ impl<'self, A> Iterator<&'self mut A> for MutDListIterator<'self, A> { if self.nelem == 0 { return None; } - match self.head.resolve() { - None => None, - Some(next) => { - self.nelem -= 1; - self.head = match next.next { - Some(ref mut node) => Rawlink::some(&mut **node), - None => Rawlink::none(), - }; - Some(&mut next.value) - } + do self.head.resolve().map_consume |next| { + self.nelem -= 1; + self.head = match next.next { + Some(ref mut node) => Rawlink::some(&mut **node), + None => Rawlink::none(), + }; + &mut next.value } } @@ -441,13 +415,10 @@ impl<'self, A> DoubleEndedIterator<&'self mut A> for MutDListIterator<'self, A> if self.nelem == 0 { return None; } - match self.tail.resolve() { - None => None, - Some(prev) => { - self.nelem -= 1; - self.tail = prev.prev; - Some(&mut prev.value) - } + do self.tail.resolve().map_consume |prev| { + self.nelem -= 1; + self.tail = prev.prev; + &mut prev.value } } } @@ -484,10 +455,7 @@ impl<'self, A> ListInsertion for MutDListIterator<'self, A> { #[inline] fn peek_next<'a>(&'a mut self) -> Option<&'a mut A> { - match self.head.resolve() { - None => None, - Some(head) => Some(&mut head.value), - } + self.head.resolve().map_consume(|head| &mut head.value) } } From 78d0cf1409a0598a03d1e5474d9f417669e271bd Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 21 Jul 2013 19:31:40 +0200 Subject: [PATCH 03/10] dlist: Factor out pop and push operations by list node Factor out internal methods for pop/push ~Node, This allows moving nodes instead of destructuring and allocating new. Make use of this in .merge() so that it requires no allocations when merging two DList. --- src/libextra/dlist.rs | 166 +++++++++++++++++++++++++++--------------- 1 file changed, 108 insertions(+), 58 deletions(-) diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 6d9b9f8efad..9e8982ecf8d 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -102,6 +102,12 @@ impl Clone for Rawlink { } } +impl Node { + fn new(v: T) -> Node { + Node{value: v, next: None, prev: Rawlink::none()} + } +} + /// Set the .prev field on `next`, then return `Some(next)` fn link_with_prev(mut next: ~Node, prev: Rawlink>) -> Link { next.prev = prev; @@ -131,6 +137,66 @@ impl Mutable for DList { } } +// private methods +impl DList { + /// Add a Node first in the list + #[inline] + fn push_front_node(&mut self, mut new_head: ~Node) { + match self.list_head { + None => { + self.list_tail = Rawlink::some(new_head); + self.list_head = link_with_prev(new_head, Rawlink::none()); + } + Some(ref mut head) => { + new_head.prev = Rawlink::none(); + head.prev = Rawlink::some(new_head); + util::swap(head, &mut new_head); + head.next = Some(new_head); + } + } + self.length += 1; + } + + /// Remove the first Node and return it, or None if the list is empty + #[inline] + fn pop_front_node(&mut self) -> Option<~Node> { + do self.list_head.take().map_consume |mut front_node| { + self.length -= 1; + match front_node.next.take() { + Some(node) => self.list_head = link_with_prev(node, Rawlink::none()), + None => self.list_tail = Rawlink::none() + } + front_node + } + } + + /// Add a Node last in the list + #[inline] + fn push_back_node(&mut self, mut new_tail: ~Node) { + match self.list_tail.resolve() { + None => return self.push_front_node(new_tail), + Some(tail) => { + self.list_tail = Rawlink::some(new_tail); + tail.next = link_with_prev(new_tail, Rawlink::some(tail)); + } + } + self.length += 1; + } + + /// Remove the last Node and return it, or None if the list is empty + #[inline] + fn pop_back_node(&mut self) -> Option<~Node> { + do self.list_tail.resolve().map_consume |tail| { + self.length -= 1; + self.list_tail = tail.prev; + match tail.prev.resolve() { + None => self.list_head.take_unwrap(), + Some(tail_prev) => tail_prev.next.take_unwrap() + } + } + } +} + impl Deque for DList { /// Provide a reference to the front element, or None if the list is empty #[inline] @@ -156,66 +222,32 @@ impl Deque for DList { self.list_tail.resolve().map_mut(|tail| &mut tail.value) } - /// Add an element last in the list - /// - /// O(1) - fn push_back(&mut self, elt: T) { - match self.list_tail.resolve() { - None => return self.push_front(elt), - Some(tail) => { - let mut new_tail = ~Node{value: elt, next: None, prev: self.list_tail}; - self.list_tail = Rawlink::some(new_tail); - tail.next = Some(new_tail); - } - } - self.length += 1; - } - - /// Remove the last element and return it, or None if the list is empty - /// - /// O(1) - fn pop_back(&mut self) -> Option { - do self.list_tail.resolve().map_consume |tail| { - self.length -= 1; - self.list_tail = tail.prev; - match tail.prev.resolve() { - None => self.list_head.take_unwrap().value, - Some(tail_prev) => tail_prev.next.take_unwrap().value - } - } - } - /// Add an element first in the list /// /// O(1) fn push_front(&mut self, elt: T) { - let mut new_head = ~Node{value: elt, next: None, prev: Rawlink::none()}; - match self.list_head { - None => { - self.list_tail = Rawlink::some(new_head); - self.list_head = Some(new_head); - } - Some(ref mut head) => { - head.prev = Rawlink::some(new_head); - util::swap(head, &mut new_head); - head.next = Some(new_head); - } - } - self.length += 1; + self.push_front_node(~Node::new(elt)) } /// Remove the first element and return it, or None if the list is empty /// /// O(1) fn pop_front(&mut self) -> Option { - do self.list_head.take().map_consume |~Node{value, next, _}| { - self.length -= 1; - match next { - Some(node) => self.list_head = link_with_prev(node, Rawlink::none()), - None => self.list_tail = Rawlink::none() - } - value - } + self.pop_front_node().map_consume(|~Node{value, _}| value) + } + + /// Add an element last in the list + /// + /// O(1) + fn push_back(&mut self, elt: T) { + self.push_back_node(~Node::new(elt)) + } + + /// Remove the last element and return it, or None if the list is empty + /// + /// O(1) + fn pop_back(&mut self) -> Option { + self.pop_back_node().map_consume(|~Node{value, _}| value) } } @@ -289,7 +321,7 @@ impl DList { if take_a { it.next(); } else { - it.insert_next(other.pop_front().unwrap()); + it.insert_next_node(other.pop_front_node().unwrap()); } } } @@ -433,18 +465,20 @@ pub trait ListInsertion { fn peek_next<'a>(&'a mut self) -> Option<&'a mut A>; } -impl<'self, A> ListInsertion for MutDListIterator<'self, A> { - fn insert_next(&mut self, elt: A) { - // Insert an element before `self.head` so that it is between the +// private methods for MutDListIterator +impl<'self, A> MutDListIterator<'self, A> { + fn insert_next_node(&mut self, mut ins_node: ~Node) { + // Insert before `self.head` so that it is between the // previously yielded element and self.head. + // + // The inserted node will not appear in further iteration. match self.head.resolve() { - None => { self.list.push_back(elt); } + None => { self.list.push_back_node(ins_node); } Some(node) => { let prev_node = match node.prev.resolve() { - None => return self.list.push_front(elt), + None => return self.list.push_front_node(ins_node), Some(prev) => prev, }; - let mut ins_node = ~Node{value: elt, next: None, prev: Rawlink::none()}; let node_own = prev_node.next.take_unwrap(); ins_node.next = link_with_prev(node_own, Rawlink::some(ins_node)); prev_node.next = link_with_prev(ins_node, Rawlink::some(prev_node)); @@ -452,6 +486,13 @@ impl<'self, A> ListInsertion for MutDListIterator<'self, A> { } } } +} + +impl<'self, A> ListInsertion for MutDListIterator<'self, A> { + #[inline] + fn insert_next(&mut self, elt: A) { + self.insert_next_node(~Node::new(elt)) + } #[inline] fn peek_next<'a>(&'a mut self) -> Option<&'a mut A> { @@ -929,7 +970,6 @@ mod tests { m.push(0); } } - #[bench] fn bench_push_back_pop_back(b: &mut test::BenchHarness) { let mut m = DList::new::(); @@ -947,6 +987,16 @@ mod tests { } } + #[bench] + fn bench_push_front_pop_front(b: &mut test::BenchHarness) { + let mut m = DList::new::(); + do b.iter { + m.push_front(0); + m.pop_front(); + } + } + + #[bench] fn bench_iter(b: &mut test::BenchHarness) { let v = &[0, ..128]; From b71c3d250f23eb15829229e69d69fa7df1d0dfe3 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 21 Jul 2013 19:31:40 +0200 Subject: [PATCH 04/10] dlist: Add .rotate_to_front(), .rotate_to_back() Add methods to move back element to front or front element to back, without reallocating nodes. --- src/libextra/dlist.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 9e8982ecf8d..189f20c9740 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -258,6 +258,26 @@ impl DList { DList{list_head: None, list_tail: Rawlink::none(), length: 0} } + /// Move the last element to the front of the list. + /// + /// If the list is empty, do nothing. + #[inline] + pub fn rotate_to_front(&mut self) { + do self.pop_back_node().map_consume |tail| { + self.push_front_node(tail) + }; + } + + /// Move the first element to the back of the list. + /// + /// If the list is empty, do nothing. + #[inline] + pub fn rotate_to_back(&mut self) { + do self.pop_front_node().map_consume |head| { + self.push_back_node(head) + }; + } + /// Add all elements from `other` to the end of the list /// /// O(1) @@ -688,6 +708,29 @@ mod tests { } } + #[test] + fn test_rotate() { + let mut n = DList::new::(); + n.rotate_to_back(); check_links(&n); + assert_eq!(n.len(), 0); + n.rotate_to_front(); check_links(&n); + assert_eq!(n.len(), 0); + + let v = ~[1,2,3,4,5]; + let mut m = list_from(v); + m.rotate_to_back(); check_links(&m); + m.rotate_to_front(); check_links(&m); + assert_eq!(v.iter().collect::<~[&int]>(), m.iter().collect()); + m.rotate_to_front(); check_links(&m); + m.rotate_to_front(); check_links(&m); + m.pop_front(); check_links(&m); + m.rotate_to_front(); check_links(&m); + m.rotate_to_back(); check_links(&m); + m.push_front(9); check_links(&m); + m.rotate_to_front(); check_links(&m); + assert_eq!(~[3,9,5,1,2], m.consume_iter().collect()); + } + #[test] fn test_iterator() { let m = generate_test(); From bfa9b43b711c4d5db78d46cb70a6f8951b177a8f Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 21 Jul 2013 21:05:48 +0200 Subject: [PATCH 05/10] dlist: Add bench test for rotate_to_{front, back} --- src/libextra/dlist.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 189f20c9740..77c67387d95 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -1039,6 +1039,25 @@ mod tests { } } + #[bench] + fn bench_rotate_to_front(b: &mut test::BenchHarness) { + let mut m = DList::new::(); + m.push_front(0); + m.push_front(1); + do b.iter { + m.rotate_to_front(); + } + } + + #[bench] + fn bench_rotate_to_back(b: &mut test::BenchHarness) { + let mut m = DList::new::(); + m.push_front(0); + m.push_front(1); + do b.iter { + m.rotate_to_back(); + } + } #[bench] fn bench_iter(b: &mut test::BenchHarness) { From b1a071e3149e5dac0e8df863479e2f29632e5399 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 21 Jul 2013 21:05:48 +0200 Subject: [PATCH 06/10] dlist: Remove bench tests for vec These tests for ~[] performance don't really belong here, they were for comparison. --- src/libextra/dlist.rs | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 77c67387d95..a2436c9a42d 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -975,13 +975,6 @@ mod tests { let _: DList = v.iter().transform(|x| *x).collect(); } } - #[bench] - fn bench_collect_into_vec(b: &mut test::BenchHarness) { - let v = &[0, ..64]; - do b.iter { - let _: ~[int] = v.iter().transform(|&x|x).collect(); - } - } #[bench] fn bench_push_front(b: &mut test::BenchHarness) { @@ -990,14 +983,6 @@ mod tests { m.push_front(0); } } - #[bench] - fn bench_push_front_vec_size10(b: &mut test::BenchHarness) { - let mut m = ~[0, ..10]; - do b.iter { - m.unshift(0); - m.pop(); // to keep it fair, dont' grow the vec - } - } #[bench] fn bench_push_back(b: &mut test::BenchHarness) { @@ -1006,13 +991,7 @@ mod tests { m.push_back(0); } } - #[bench] - fn bench_push_back_vec(b: &mut test::BenchHarness) { - let mut m = ~[]; - do b.iter { - m.push(0); - } - } + #[bench] fn bench_push_back_pop_back(b: &mut test::BenchHarness) { let mut m = DList::new::(); @@ -1021,14 +1000,6 @@ mod tests { m.pop_back(); } } - #[bench] - fn bench_push_back_pop_back_vec(b: &mut test::BenchHarness) { - let mut m = ~[]; - do b.iter { - m.push(0); - m.pop(); - } - } #[bench] fn bench_push_front_pop_front(b: &mut test::BenchHarness) { @@ -1091,12 +1062,5 @@ mod tests { assert!(m.mut_rev_iter().len_() == 128); } } - #[bench] - fn bench_iter_vec(b: &mut test::BenchHarness) { - let v = &[0, ..128]; - do b.iter { - for v.iter().advance |_| {} - } - } } From 21adfd564555428d0af11e7f22b42e05698d74fd Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 21 Jul 2013 21:05:48 +0200 Subject: [PATCH 07/10] dlist: Use Ord for .insert_ordered() We don't need TotalOrd for ordered insertion, just the normal sort order Ord. --- src/libextra/dlist.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index a2436c9a42d..068dea7b8cc 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -23,7 +23,6 @@ // the reverse direction. use std::cast; -use std::cmp; use std::ptr; use std::util; use std::iterator::{FromIterator, InvertIterator}; @@ -396,13 +395,13 @@ impl DList { } } -impl DList { +impl DList { /// Insert `elt` sorted in ascending order /// /// O(N) #[inline] pub fn insert_ordered(&mut self, elt: T) { - self.insert_when(elt, |a, b| a.cmp(b) != cmp::Less); + self.insert_when(elt, |a, b| a >= b) } } From cf437a273033a16c4084acc07b1341ee86bd5bbd Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 21 Jul 2013 22:37:14 +0200 Subject: [PATCH 08/10] dlist: Remove extraneous unwrap in .pop_back_node() --- src/libextra/dlist.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 068dea7b8cc..a715d4aeeae 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -185,12 +185,12 @@ impl DList { /// Remove the last Node and return it, or None if the list is empty #[inline] fn pop_back_node(&mut self) -> Option<~Node> { - do self.list_tail.resolve().map_consume |tail| { + do self.list_tail.resolve().map_consume_default(None) |tail| { self.length -= 1; self.list_tail = tail.prev; match tail.prev.resolve() { - None => self.list_head.take_unwrap(), - Some(tail_prev) => tail_prev.next.take_unwrap() + None => self.list_head.take(), + Some(tail_prev) => tail_prev.next.take() } } } From 52b4a2eb6f094db7eabcf605598b9266869fa9d6 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Mon, 22 Jul 2013 17:51:11 +0200 Subject: [PATCH 09/10] dlist: Fix .peek_next() w.r.t double ended iterators .peek_next() needs to check the element counter just like the .next() and .next_back() iterators do. Also clarify .insert_next() doc w.r.t double ended iteration. --- src/libextra/dlist.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index a715d4aeeae..276d8004314 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -477,7 +477,9 @@ impl<'self, A> DoubleEndedIterator<&'self mut A> for MutDListIterator<'self, A> /// Allow mutating the DList while iterating pub trait ListInsertion { - /// Insert `elt` just after to the most recently yielded element + /// Insert `elt` just after to the element most recently returned by `.next()` + /// + /// The inserted element does not appear in the iteration. fn insert_next(&mut self, elt: A); /// Provide a reference to the next element, without changing the iterator @@ -515,6 +517,9 @@ impl<'self, A> ListInsertion for MutDListIterator<'self, A> { #[inline] fn peek_next<'a>(&'a mut self) -> Option<&'a mut A> { + if self.nelem == 0 { + return None + } self.head.resolve().map_consume(|head| &mut head.value) } } From 6e24b750e248078a0b3c86203a2e2a01cbf3cc23 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Tue, 23 Jul 2013 01:31:30 +0200 Subject: [PATCH 10/10] dlist: Rename rotate methods to .rotate_forward() and .rotate_backward() --- src/libextra/dlist.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 276d8004314..77060c4b11e 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -261,7 +261,7 @@ impl DList { /// /// If the list is empty, do nothing. #[inline] - pub fn rotate_to_front(&mut self) { + pub fn rotate_forward(&mut self) { do self.pop_back_node().map_consume |tail| { self.push_front_node(tail) }; @@ -271,7 +271,7 @@ impl DList { /// /// If the list is empty, do nothing. #[inline] - pub fn rotate_to_back(&mut self) { + pub fn rotate_backward(&mut self) { do self.pop_front_node().map_consume |head| { self.push_back_node(head) }; @@ -715,23 +715,23 @@ mod tests { #[test] fn test_rotate() { let mut n = DList::new::(); - n.rotate_to_back(); check_links(&n); + n.rotate_backward(); check_links(&n); assert_eq!(n.len(), 0); - n.rotate_to_front(); check_links(&n); + n.rotate_forward(); check_links(&n); assert_eq!(n.len(), 0); let v = ~[1,2,3,4,5]; let mut m = list_from(v); - m.rotate_to_back(); check_links(&m); - m.rotate_to_front(); check_links(&m); + m.rotate_backward(); check_links(&m); + m.rotate_forward(); check_links(&m); assert_eq!(v.iter().collect::<~[&int]>(), m.iter().collect()); - m.rotate_to_front(); check_links(&m); - m.rotate_to_front(); check_links(&m); + m.rotate_forward(); check_links(&m); + m.rotate_forward(); check_links(&m); m.pop_front(); check_links(&m); - m.rotate_to_front(); check_links(&m); - m.rotate_to_back(); check_links(&m); + m.rotate_forward(); check_links(&m); + m.rotate_backward(); check_links(&m); m.push_front(9); check_links(&m); - m.rotate_to_front(); check_links(&m); + m.rotate_forward(); check_links(&m); assert_eq!(~[3,9,5,1,2], m.consume_iter().collect()); } @@ -1015,22 +1015,22 @@ mod tests { } #[bench] - fn bench_rotate_to_front(b: &mut test::BenchHarness) { + fn bench_rotate_forward(b: &mut test::BenchHarness) { let mut m = DList::new::(); m.push_front(0); m.push_front(1); do b.iter { - m.rotate_to_front(); + m.rotate_forward(); } } #[bench] - fn bench_rotate_to_back(b: &mut test::BenchHarness) { + fn bench_rotate_backward(b: &mut test::BenchHarness) { let mut m = DList::new::(); m.push_front(0); m.push_front(1); do b.iter { - m.rotate_to_back(); + m.rotate_backward(); } }