Skip to content

Removed rev_iter in favor of DoubleEndedIterator #13648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/doc/guide-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ differently.
Containers implement iteration over the contained elements by returning an
iterator object. For example, vector slices several iterators available:

* `iter()` and `rev_iter()`, for immutable references to the elements
* `mut_iter()` and `mut_rev_iter()`, for mutable references to the elements
* `move_iter()` and `move_rev_iter()`, to move the elements out by-value
* `iter()` for immutable references to the elements
* `mut_iter()` for mutable references to the elements
* `move_iter()` to move the elements out by-value

A typical mutable container will implement at least `iter()`, `mut_iter()` and
`move_iter()` along with the reverse variants if it maintains an order.
`move_iter()`. If it maintains an order, the returned iterators will be
`DoubleEndedIterator`s, which are described below.

### Freezing

Expand Down Expand Up @@ -265,7 +266,7 @@ Iterators offer generic conversion to containers with the `collect` adaptor:

~~~
let xs = [0, 1, 1, 2, 3, 5, 8];
let ys = xs.rev_iter().skip(1).map(|&x| x * 2).collect::<~[int]>();
let ys = xs.iter().rev().skip(1).map(|&x| x * 2).collect::<~[int]>();
assert_eq!(ys, ~[10, 6, 4, 2, 2, 0]);
~~~

Expand Down Expand Up @@ -358,9 +359,6 @@ for &x in it.rev() {
}
~~~

The `rev_iter` and `mut_rev_iter` methods on vectors just return an inverted
version of the standard immutable and mutable vector iterators.

The `chain`, `map`, `filter`, `filter_map` and `inspect` adaptors are
`DoubleEndedIterator` implementations if the underlying iterators are.

Expand Down
1 change: 1 addition & 0 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ impl Bitv {
}

#[inline]
#[deprecated = "replaced by .iter().rev()"]
pub fn rev_iter<'a>(&'a self) -> Rev<Bits<'a>> {
self.iter().rev()
}
Expand Down
25 changes: 13 additions & 12 deletions src/libcollections/dlist.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -370,8 +370,8 @@ impl<T> DList<T> {
Items{nelem: self.len(), head: &self.list_head, tail: self.list_tail}
}

/// Provide a reverse iterator
#[inline]
#[deprecated = "replaced by .iter().rev()"]
pub fn rev_iter<'a>(&'a self) -> Rev<Items<'a, T>> {
self.iter().rev()
}
Expand All @@ -390,8 +390,9 @@ impl<T> DList<T> {
list: self
}
}
/// Provide a reverse iterator with mutable references

#[inline]
#[deprecated = "replaced by .mut_iter().rev()"]
pub fn mut_rev_iter<'a>(&'a mut self) -> Rev<MutItems<'a, T>> {
self.mut_iter().rev()
}
Expand All @@ -403,8 +404,8 @@ impl<T> DList<T> {
MoveItems{list: self}
}

/// Consume the list into an iterator yielding elements by value, in reverse
#[inline]
#[deprecated = "replaced by .move_iter().rev()"]
pub fn move_rev_iter(self) -> Rev<MoveItems<T>> {
self.move_iter().rev()
}
Expand Down Expand Up @@ -849,13 +850,13 @@ mod tests {
#[test]
fn test_rev_iter() {
let m = generate_test();
for (i, elt) in m.rev_iter().enumerate() {
for (i, elt) in m.iter().rev().enumerate() {
assert_eq!((6 - i) as int, *elt);
}
let mut n = DList::new();
assert_eq!(n.rev_iter().next(), None);
assert_eq!(n.iter().rev().next(), None);
n.push_front(4);
let mut it = n.rev_iter();
let mut it = n.iter().rev();
assert_eq!(it.size_hint(), (1, Some(1)));
assert_eq!(it.next().unwrap(), &4);
assert_eq!(it.size_hint(), (0, Some(0)));
Expand Down Expand Up @@ -958,13 +959,13 @@ mod tests {
#[test]
fn test_mut_rev_iter() {
let mut m = generate_test();
for (i, elt) in m.mut_rev_iter().enumerate() {
for (i, elt) in m.mut_iter().rev().enumerate() {
assert_eq!((6-i) as int, *elt);
}
let mut n = DList::new();
assert!(n.mut_rev_iter().next().is_none());
assert!(n.mut_iter().rev().next().is_none());
n.push_front(4);
let mut it = n.mut_rev_iter();
let mut it = n.mut_iter().rev();
assert!(it.next().is_some());
assert!(it.next().is_none());
}
Expand Down Expand Up @@ -1164,15 +1165,15 @@ mod tests {
let v = &[0, ..128];
let m: DList<int> = v.iter().map(|&x|x).collect();
b.iter(|| {
assert!(m.rev_iter().len() == 128);
assert!(m.iter().rev().len() == 128);
})
}
#[bench]
fn bench_iter_mut_rev(b: &mut test::Bencher) {
let v = &[0, ..128];
let mut m: DList<int> = v.iter().map(|&x|x).collect();
b.iter(|| {
assert!(m.mut_rev_iter().len() == 128);
assert!(m.mut_iter().rev().len() == 128);
})
}
}
4 changes: 2 additions & 2 deletions src/libcollections/priority_queue.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -382,7 +382,7 @@ mod tests {
fn test_from_iter() {
let xs = vec!(9u, 8, 7, 6, 5, 4, 3, 2, 1);

let mut q: PriorityQueue<uint> = xs.as_slice().rev_iter().map(|&x| x).collect();
let mut q: PriorityQueue<uint> = xs.as_slice().iter().rev().map(|&x| x).collect();

for &x in xs.iter() {
assert_eq!(q.pop(), x);
Expand Down
22 changes: 11 additions & 11 deletions src/libcollections/ringbuf.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -190,7 +190,7 @@ impl<T> RingBuf<T> {
Items{index: 0, rindex: self.nelts, lo: self.lo, elts: self.elts.as_slice()}
}

/// Back-to-front iterator.
#[deprecated = "replaced by .iter().rev()"]
pub fn rev_iter<'a>(&'a self) -> Rev<Items<'a, T>> {
self.iter().rev()
}
Expand Down Expand Up @@ -221,7 +221,7 @@ impl<T> RingBuf<T> {
}
}

/// Back-to-front iterator which returns mutable values.
#[deprecated = "replaced by .mut_iter().rev()"]
pub fn mut_rev_iter<'a>(&'a mut self) -> Rev<MutItems<'a, T>> {
self.mut_iter().rev()
}
Expand Down Expand Up @@ -702,31 +702,31 @@ mod tests {
#[test]
fn test_rev_iter() {
let mut d = RingBuf::new();
assert_eq!(d.rev_iter().next(), None);
assert_eq!(d.iter().rev().next(), None);

for i in range(0, 5) {
d.push_back(i);
}
assert_eq!(d.rev_iter().collect::<Vec<&int>>().as_slice(), &[&4,&3,&2,&1,&0]);
assert_eq!(d.iter().rev().collect::<Vec<&int>>().as_slice(), &[&4,&3,&2,&1,&0]);

for i in range(6, 9) {
d.push_front(i);
}
assert_eq!(d.rev_iter().collect::<Vec<&int>>().as_slice(), &[&4,&3,&2,&1,&0,&6,&7,&8]);
assert_eq!(d.iter().rev().collect::<Vec<&int>>().as_slice(), &[&4,&3,&2,&1,&0,&6,&7,&8]);
}

#[test]
fn test_mut_rev_iter_wrap() {
let mut d = RingBuf::with_capacity(3);
assert!(d.mut_rev_iter().next().is_none());
assert!(d.mut_iter().rev().next().is_none());

d.push_back(1);
d.push_back(2);
d.push_back(3);
assert_eq!(d.pop_front(), Some(1));
d.push_back(4);

assert_eq!(d.mut_rev_iter().map(|x| *x).collect::<Vec<int>>(),
assert_eq!(d.mut_iter().rev().map(|x| *x).collect::<Vec<int>>(),
vec!(4, 3, 2));
}

Expand Down Expand Up @@ -756,19 +756,19 @@ mod tests {
#[test]
fn test_mut_rev_iter() {
let mut d = RingBuf::new();
assert!(d.mut_rev_iter().next().is_none());
assert!(d.mut_iter().rev().next().is_none());

for i in range(0u, 3) {
d.push_front(i);
}

for (i, elt) in d.mut_rev_iter().enumerate() {
for (i, elt) in d.mut_iter().rev().enumerate() {
assert_eq!(*elt, i);
*elt = i;
}

{
let mut it = d.mut_rev_iter();
let mut it = d.mut_iter().rev();
assert_eq!(*it.next().unwrap(), 0);
assert_eq!(*it.next().unwrap(), 1);
assert_eq!(*it.next().unwrap(), 2);
Expand Down
23 changes: 11 additions & 12 deletions src/libcollections/smallintmap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -142,16 +142,13 @@ impl<V> SmallIntMap<V> {
}
}

/// An iterator visiting all key-value pairs in descending order by the keys.
/// Iterator element type is (uint, &'r V)
pub fn rev_iter<'r>(&'r self) -> RevEntries<'r, V> {
#[deprecated = "replaced by .iter().rev()"]
pub fn rev_iter<'r>(&'r self) -> Rev<Entries<'r, V>> {
self.iter().rev()
}

/// An iterator visiting all key-value pairs in descending order by the keys,
/// with mutable references to the values
/// Iterator element type is (uint, &'r mut V)
pub fn mut_rev_iter<'r>(&'r mut self) -> RevMutEntries <'r, V> {
#[deprecated = "replaced by .mut_iter().rev()"]
pub fn mut_rev_iter<'r>(&'r mut self) -> Rev<MutEntries<'r, V>> {
self.mut_iter().rev()
}

Expand Down Expand Up @@ -246,6 +243,7 @@ pub struct Entries<'a, T> {

iterator!(impl Entries -> (uint, &'a T), get_ref)
double_ended_iterator!(impl Entries -> (uint, &'a T), get_ref)
#[deprecated = "replaced by Rev<Entries<'a, T>>"]
pub type RevEntries<'a, T> = Rev<Entries<'a, T>>;

pub struct MutEntries<'a, T> {
Expand All @@ -256,6 +254,7 @@ pub struct MutEntries<'a, T> {

iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref)
double_ended_iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref)
#[deprecated = "replaced by Rev<MutEntries<'a, T>"]
pub type RevMutEntries<'a, T> = Rev<MutEntries<'a, T>>;

#[cfg(test)]
Expand Down Expand Up @@ -387,9 +386,9 @@ mod test_map {
assert!(m.insert(10, 11));

assert_eq!(m.iter().size_hint(), (0, Some(11)));
assert_eq!(m.rev_iter().size_hint(), (0, Some(11)));
assert_eq!(m.iter().rev().size_hint(), (0, Some(11)));
assert_eq!(m.mut_iter().size_hint(), (0, Some(11)));
assert_eq!(m.mut_rev_iter().size_hint(), (0, Some(11)));
assert_eq!(m.mut_iter().rev().size_hint(), (0, Some(11)));
}

#[test]
Expand Down Expand Up @@ -425,7 +424,7 @@ mod test_map {
assert!(m.insert(6, 10));
assert!(m.insert(10, 11));

let mut it = m.rev_iter();
let mut it = m.iter().rev();
assert_eq!(it.next().unwrap(), (10, &11));
assert_eq!(it.next().unwrap(), (6, &10));
assert_eq!(it.next().unwrap(), (3, &5));
Expand All @@ -444,7 +443,7 @@ mod test_map {
assert!(m.insert(6, 10));
assert!(m.insert(10, 11));

for (k, v) in m.mut_rev_iter() {
for (k, v) in m.mut_iter().rev() {
*v += k as int;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl<T> TrieNode<T> {

impl<T> TrieNode<T> {
fn each_reverse<'a>(&'a self, f: |&uint, &'a T| -> bool) -> bool {
for elt in self.children.rev_iter() {
for elt in self.children.iter().rev() {
match *elt {
Internal(ref x) => if !x.each_reverse(|i,t| f(i,t)) { return false },
External(k, ref v) => if !f(&k, v) { return false },
Expand Down
6 changes: 3 additions & 3 deletions src/libnum/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl Integer for BigUint {
let bn = *b.data.last().unwrap();
let mut d = Vec::with_capacity(an.len());
let mut carry = 0;
for elt in an.rev_iter() {
for elt in an.iter().rev() {
let ai = BigDigit::to_uint(carry, *elt);
let di = ai / (bn as uint);
assert!(di < BigDigit::base);
Expand Down Expand Up @@ -668,7 +668,7 @@ impl ToStrRadix for BigUint {
fn fill_concat(v: &[BigDigit], radix: uint, l: uint) -> ~str {
if v.is_empty() { return "0".to_owned() }
let mut s = StrBuf::with_capacity(v.len() * l);
for n in v.rev_iter() {
for n in v.iter().rev() {
let ss = (*n as uint).to_str_radix(radix);
s.push_str("0".repeat(l - ss.len()));
s.push_str(ss);
Expand Down Expand Up @@ -2187,7 +2187,7 @@ mod bigint_tests {
fn test_cmp() {
let vs = [ &[2 as BigDigit], &[1, 1], &[2, 1], &[1, 1, 1] ];
let mut nums = Vec::new();
for s in vs.rev_iter() {
for s in vs.iter().rev() {
nums.push(BigInt::from_slice(Minus, *s));
}
nums.push(Zero::zero());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ impl<'a> Liveness<'a> {

fn propagate_through_exprs(&mut self, exprs: &[@Expr], succ: LiveNode)
-> LiveNode {
exprs.rev_iter().fold(succ, |succ, expr| {
exprs.iter().rev().fold(succ, |succ, expr| {
self.propagate_through_expr(*expr, succ)
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/vtable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -94,7 +94,7 @@ fn lookup_vtables(vcx: &VtableContext,
let mut result: Vec<vtable_param_res> =
substs.tps.iter()
.rev()
.zip(type_param_defs.rev_iter())
.zip(type_param_defs.iter().rev())
.map(|(ty, def)|
lookup_vtables_for_param(vcx, span, Some(substs),
&*def.bounds, *ty, is_early))
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
None => {}
}
if default_passes {
for name in DEFAULT_PASSES.rev_iter() {
for name in DEFAULT_PASSES.iter().rev() {
passes.unshift(name.to_owned());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libserialize/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ impl ::Decoder<Error> for Decoder {
};
match o.pop(&"fields".to_owned()) {
Some(List(l)) => {
for field in l.move_rev_iter() {
for field in l.move_iter().rev() {
self.stack.push(field.clone());
}
},
Expand Down Expand Up @@ -1557,7 +1557,7 @@ impl ::Decoder<Error> for Decoder {
debug!("read_seq()");
let list = try!(expect!(self.pop(), List));
let len = list.len();
for v in list.move_rev_iter() {
for v in list.move_iter().rev() {
self.stack.push(v);
}
f(self, len)
Expand Down
Loading