diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index c9d1d9d13fb..5e1025ebfb2 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -240,7 +240,8 @@ impl BinaryHeap { /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn iter(&self) -> Iter { - Iter { iter: self.data.iter() } } + Iter { iter: self.data.iter() } + } /// Creates a consuming iterator, that is, one that moves each value out of /// the binary heap in arbitrary order. The binary heap cannot be used diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 01096c1fd4e..24d991cda72 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -88,7 +88,7 @@ pub struct BTreeMap { } /// An abstract base over-which all other BTree iterators are built. -struct AbsEntries { +struct AbsIter { lca: T, left: RingBuf, right: RingBuf, @@ -96,28 +96,28 @@ struct AbsEntries { } /// An iterator over a BTreeMap's entries. -pub struct Entries<'a, K: 'a, V: 'a> { - inner: AbsEntries> +pub struct Iter<'a, K: 'a, V: 'a> { + inner: AbsIter> } /// A mutable iterator over a BTreeMap's entries. -pub struct MutEntries<'a, K: 'a, V: 'a> { - inner: AbsEntries> +pub struct IterMut<'a, K: 'a, V: 'a> { + inner: AbsIter> } /// An owning iterator over a BTreeMap's entries. -pub struct MoveEntries { - inner: AbsEntries> +pub struct IntoIter { + inner: AbsIter> } /// An iterator over a BTreeMap's keys. pub struct Keys<'a, K: 'a, V: 'a> { - inner: Map<(&'a K, &'a V), &'a K, Entries<'a, K, V>, fn((&'a K, &'a V)) -> &'a K> + inner: Map<(&'a K, &'a V), &'a K, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K> } /// An iterator over a BTreeMap's values. pub struct Values<'a, K: 'a, V: 'a> { - inner: Map<(&'a K, &'a V), &'a V, Entries<'a, K, V>, fn((&'a K, &'a V)) -> &'a V> + inner: Map<(&'a K, &'a V), &'a V, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V> } /// A view into a single entry in a map, which may either be vacant or occupied. @@ -929,7 +929,7 @@ enum StackOp { } impl + DoubleEndedIterator>> - Iterator<(K, V)> for AbsEntries { + Iterator<(K, V)> for AbsIter { // This function is pretty long, but only because there's a lot of cases to consider. // Our iterator represents two search paths, left and right, to the smallest and largest // elements we have yet to yield. lca represents the least common ancestor of these two paths, @@ -995,7 +995,7 @@ impl + DoubleEndedIterator>> } impl + DoubleEndedIterator>> - DoubleEndedIterator<(K, V)> for AbsEntries { + DoubleEndedIterator<(K, V)> for AbsIter { // next_back is totally symmetric to next fn next_back(&mut self) -> Option<(K, V)> { loop { @@ -1032,34 +1032,34 @@ impl + DoubleEndedIterator>> } } -impl<'a, K, V> Iterator<(&'a K, &'a V)> for Entries<'a, K, V> { +impl<'a, K, V> Iterator<(&'a K, &'a V)> for Iter<'a, K, V> { fn next(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl<'a, K, V> DoubleEndedIterator<(&'a K, &'a V)> for Entries<'a, K, V> { +impl<'a, K, V> DoubleEndedIterator<(&'a K, &'a V)> for Iter<'a, K, V> { fn next_back(&mut self) -> Option<(&'a K, &'a V)> { self.inner.next_back() } } -impl<'a, K, V> ExactSizeIterator<(&'a K, &'a V)> for Entries<'a, K, V> {} +impl<'a, K, V> ExactSizeIterator<(&'a K, &'a V)> for Iter<'a, K, V> {} -impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for MutEntries<'a, K, V> { +impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> { fn next(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl<'a, K, V> DoubleEndedIterator<(&'a K, &'a mut V)> for MutEntries<'a, K, V> { +impl<'a, K, V> DoubleEndedIterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> { fn next_back(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next_back() } } -impl<'a, K, V> ExactSizeIterator<(&'a K, &'a mut V)> for MutEntries<'a, K, V> {} +impl<'a, K, V> ExactSizeIterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> {} -impl Iterator<(K, V)> for MoveEntries { +impl Iterator<(K, V)> for IntoIter { fn next(&mut self) -> Option<(K, V)> { self.inner.next() } fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl DoubleEndedIterator<(K, V)> for MoveEntries { +impl DoubleEndedIterator<(K, V)> for IntoIter { fn next_back(&mut self) -> Option<(K, V)> { self.inner.next_back() } } -impl ExactSizeIterator<(K, V)> for MoveEntries {} +impl ExactSizeIterator<(K, V)> for IntoIter {} impl<'a, K, V> Iterator<&'a K> for Keys<'a, K, V> { @@ -1140,10 +1140,10 @@ impl BTreeMap { /// assert_eq!((*first_key, *first_value), (1u, "a")); /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter<'a>(&'a self) -> Entries<'a, K, V> { + pub fn iter<'a>(&'a self) -> Iter<'a, K, V> { let len = self.len(); - Entries { - inner: AbsEntries { + Iter { + inner: AbsIter { lca: Traverse::traverse(&self.root), left: RingBuf::new(), right: RingBuf::new(), @@ -1172,10 +1172,10 @@ impl BTreeMap { /// } /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, K, V> { + pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, K, V> { let len = self.len(); - MutEntries { - inner: AbsEntries { + IterMut { + inner: AbsIter { lca: Traverse::traverse(&mut self.root), left: RingBuf::new(), right: RingBuf::new(), @@ -1201,10 +1201,10 @@ impl BTreeMap { /// } /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn into_iter(self) -> MoveEntries { + pub fn into_iter(self) -> IntoIter { let len = self.len(); - MoveEntries { - inner: AbsEntries { + IntoIter { + inner: AbsIter { lca: Traverse::traverse(self.root), left: RingBuf::new(), right: RingBuf::new(), diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 26e82994f56..3b403d45d82 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -13,7 +13,7 @@ use core::prelude::*; -use btree_map::{BTreeMap, Keys, MoveEntries}; +use btree_map::{BTreeMap, Keys}; use std::hash::Hash; use core::borrow::BorrowFrom; use core::default::Default; @@ -39,29 +39,29 @@ pub struct Iter<'a, T: 'a> { /// An owning iterator over a BTreeSet's items. pub struct IntoIter { - iter: Map<(T, ()), T, MoveEntries, fn((T, ())) -> T> + iter: Map<(T, ()), T, ::btree_map::IntoIter, fn((T, ())) -> T> } /// A lazy iterator producing elements in the set difference (in-order). -pub struct DifferenceItems<'a, T:'a> { +pub struct Difference<'a, T:'a> { a: Peekable<&'a T, Iter<'a, T>>, b: Peekable<&'a T, Iter<'a, T>>, } /// A lazy iterator producing elements in the set symmetric difference (in-order). -pub struct SymDifferenceItems<'a, T:'a> { +pub struct SymmetricDifference<'a, T:'a> { a: Peekable<&'a T, Iter<'a, T>>, b: Peekable<&'a T, Iter<'a, T>>, } /// A lazy iterator producing elements in the set intersection (in-order). -pub struct IntersectionItems<'a, T:'a> { +pub struct Intersection<'a, T:'a> { a: Peekable<&'a T, Iter<'a, T>>, b: Peekable<&'a T, Iter<'a, T>>, } /// A lazy iterator producing elements in the set union (in-order). -pub struct UnionItems<'a, T:'a> { +pub struct Union<'a, T:'a> { a: Peekable<&'a T, Iter<'a, T>>, b: Peekable<&'a T, Iter<'a, T>>, } @@ -151,8 +151,8 @@ impl BTreeSet { /// assert_eq!(diff, vec![1u]); /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn difference<'a>(&'a self, other: &'a BTreeSet) -> DifferenceItems<'a, T> { - DifferenceItems{a: self.iter().peekable(), b: other.iter().peekable()} + pub fn difference<'a>(&'a self, other: &'a BTreeSet) -> Difference<'a, T> { + Difference{a: self.iter().peekable(), b: other.iter().peekable()} } /// Visits the values representing the symmetric difference, in ascending order. @@ -175,8 +175,8 @@ impl BTreeSet { /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn symmetric_difference<'a>(&'a self, other: &'a BTreeSet) - -> SymDifferenceItems<'a, T> { - SymDifferenceItems{a: self.iter().peekable(), b: other.iter().peekable()} + -> SymmetricDifference<'a, T> { + SymmetricDifference{a: self.iter().peekable(), b: other.iter().peekable()} } /// Visits the values representing the intersection, in ascending order. @@ -199,8 +199,8 @@ impl BTreeSet { /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn intersection<'a>(&'a self, other: &'a BTreeSet) - -> IntersectionItems<'a, T> { - IntersectionItems{a: self.iter().peekable(), b: other.iter().peekable()} + -> Intersection<'a, T> { + Intersection{a: self.iter().peekable(), b: other.iter().peekable()} } /// Visits the values representing the union, in ascending order. @@ -220,8 +220,8 @@ impl BTreeSet { /// assert_eq!(union, vec![1u,2]); /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn union<'a>(&'a self, other: &'a BTreeSet) -> UnionItems<'a, T> { - UnionItems{a: self.iter().peekable(), b: other.iter().peekable()} + pub fn union<'a>(&'a self, other: &'a BTreeSet) -> Union<'a, T> { + Union{a: self.iter().peekable(), b: other.iter().peekable()} } /// Return the number of elements in the set @@ -573,7 +573,7 @@ fn cmp_opt(x: Option<&T>, y: Option<&T>, } } -impl<'a, T: Ord> Iterator<&'a T> for DifferenceItems<'a, T> { +impl<'a, T: Ord> Iterator<&'a T> for Difference<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { match cmp_opt(self.a.peek(), self.b.peek(), Less, Less) { @@ -585,7 +585,7 @@ impl<'a, T: Ord> Iterator<&'a T> for DifferenceItems<'a, T> { } } -impl<'a, T: Ord> Iterator<&'a T> for SymDifferenceItems<'a, T> { +impl<'a, T: Ord> Iterator<&'a T> for SymmetricDifference<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { match cmp_opt(self.a.peek(), self.b.peek(), Greater, Less) { @@ -597,7 +597,7 @@ impl<'a, T: Ord> Iterator<&'a T> for SymDifferenceItems<'a, T> { } } -impl<'a, T: Ord> Iterator<&'a T> for IntersectionItems<'a, T> { +impl<'a, T: Ord> Iterator<&'a T> for Intersection<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { let o_cmp = match (self.a.peek(), self.b.peek()) { @@ -615,7 +615,7 @@ impl<'a, T: Ord> Iterator<&'a T> for IntersectionItems<'a, T> { } } -impl<'a, T: Ord> Iterator<&'a T> for UnionItems<'a, T> { +impl<'a, T: Ord> Iterator<&'a T> for Union<'a, T> { fn next(&mut self) -> Option<&'a T> { loop { match cmp_opt(self.a.peek(), self.b.peek(), Greater, Less) { diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 802be427189..999025840ca 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -176,8 +176,8 @@ impl VecMap { /// } /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter<'r>(&'r self) -> Entries<'r, V> { - Entries { + pub fn iter<'r>(&'r self) -> Iter<'r, V> { + Iter { front: 0, back: self.v.len(), iter: self.v.iter() @@ -207,8 +207,8 @@ impl VecMap { /// } /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter_mut<'r>(&'r mut self) -> MutEntries<'r, V> { - MutEntries { + pub fn iter_mut<'r>(&'r mut self) -> IterMut<'r, V> { + IterMut { front: 0, back: self.v.len(), iter: self.v.iter_mut() @@ -605,34 +605,34 @@ macro_rules! double_ended_iterator { } /// An iterator over the key-value pairs of a map. -pub struct Entries<'a, V:'a> { +pub struct Iter<'a, V:'a> { front: uint, back: uint, iter: slice::Iter<'a, Option> } -iterator! { impl Entries -> (uint, &'a V), as_ref } -double_ended_iterator! { impl Entries -> (uint, &'a V), as_ref } +iterator! { impl Iter -> (uint, &'a V), as_ref } +double_ended_iterator! { impl Iter -> (uint, &'a V), as_ref } /// An iterator over the key-value pairs of a map, with the /// values being mutable. -pub struct MutEntries<'a, V:'a> { +pub struct IterMut<'a, V:'a> { front: uint, back: uint, iter: slice::IterMut<'a, Option> } -iterator! { impl MutEntries -> (uint, &'a mut V), as_mut } -double_ended_iterator! { impl MutEntries -> (uint, &'a mut V), as_mut } +iterator! { impl IterMut -> (uint, &'a mut V), as_mut } +double_ended_iterator! { impl IterMut -> (uint, &'a mut V), as_mut } /// An iterator over the keys of a map. pub struct Keys<'a, V: 'a> { - iter: Map<(uint, &'a V), uint, Entries<'a, V>, fn((uint, &'a V)) -> uint> + iter: Map<(uint, &'a V), uint, Iter<'a, V>, fn((uint, &'a V)) -> uint> } /// An iterator over the values of a map. pub struct Values<'a, V: 'a> { - iter: Map<(uint, &'a V), &'a V, Entries<'a, V>, fn((uint, &'a V)) -> &'a V> + iter: Map<(uint, &'a V), &'a V, Iter<'a, V>, fn((uint, &'a V)) -> &'a V> } /// A consuming iterator over the key-value pairs of a map. diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 6092a45c97d..26684864c4c 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -781,7 +781,7 @@ iterator!{struct Iter -> *const T, &'a T} #[experimental = "needs review"] impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} - #[experimental = "needs review"] +#[stable] impl<'a, T> Clone for Iter<'a, T> { fn clone(&self) -> Iter<'a, T> { *self } } diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 8149864afd4..692f120737a 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -914,8 +914,8 @@ impl, V, S, H: Hasher> HashMap { /// } /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter_mut(&mut self) -> MutEntries { - MutEntries { inner: self.table.iter_mut() } + pub fn iter_mut(&mut self) -> IterMut { + IterMut { inner: self.table.iter_mut() } } /// Creates a consuming iterator, that is, one that moves each key-value @@ -936,10 +936,10 @@ impl, V, S, H: Hasher> HashMap { /// let vec: Vec<(&str, int)> = map.into_iter().collect(); /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn into_iter(self) -> MoveEntries { + pub fn into_iter(self) -> IntoIter { fn last_two((_, b, c): (A, B, C)) -> (B, C) { (b, c) } - MoveEntries { + IntoIter { inner: self.table.into_iter().map(last_two) } } @@ -1306,16 +1306,16 @@ pub struct Entries<'a, K: 'a, V: 'a> { } /// HashMap mutable values iterator -pub struct MutEntries<'a, K: 'a, V: 'a> { - inner: table::MutEntries<'a, K, V> +pub struct IterMut<'a, K: 'a, V: 'a> { + inner: table::IterMut<'a, K, V> } /// HashMap move iterator -pub struct MoveEntries { +pub struct IntoIter { inner: iter::Map< (SafeHash, K, V), (K, V), - table::MoveEntries, + table::IntoIter, fn((SafeHash, K, V)) -> (K, V), > } @@ -1374,12 +1374,12 @@ impl<'a, K, V> Iterator<(&'a K, &'a V)> for Entries<'a, K, V> { #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for MutEntries<'a, K, V> { +impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> { #[inline] fn next(&mut self) -> Option<(&'a K, &'a mut V)> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } -impl Iterator<(K, V)> for MoveEntries { +impl Iterator<(K, V)> for IntoIter { #[inline] fn next(&mut self) -> Option<(K, V)> { self.inner.next() } #[inline] fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } } diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index f587669d3da..a2c31591d8d 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -21,7 +21,7 @@ use iter::{Iterator, IteratorExt, FromIterator, Map, Chain, Extend}; use option::Option::{Some, None, mod}; use result::Result::{Ok, Err}; -use super::map::{mod, HashMap, MoveEntries, Keys, INITIAL_CAPACITY}; +use super::map::{mod, HashMap, Keys, INITIAL_CAPACITY}; // FIXME(conventions): implement BitOr, BitAnd, BitXor, and Sub @@ -625,7 +625,7 @@ pub struct Iter<'a, K: 'a> { /// HashSet move iterator pub struct IntoIter { - iter: Map<(K, ()), K, MoveEntries, fn((K, ())) -> K> + iter: Map<(K, ()), K, map::IntoIter, fn((K, ())) -> K> } /// HashSet drain iterator diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index ce7dbd8ea5e..8f2152c5a9d 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -664,17 +664,17 @@ impl RawTable { } } - pub fn iter_mut(&mut self) -> MutEntries { - MutEntries { + pub fn iter_mut(&mut self) -> IterMut { + IterMut { iter: self.raw_buckets(), elems_left: self.size(), } } - pub fn into_iter(self) -> MoveEntries { + pub fn into_iter(self) -> IntoIter { let RawBuckets { raw, hashes_end, .. } = self.raw_buckets(); // Replace the marker regardless of lifetime bounds on parameters. - MoveEntries { + IntoIter { iter: RawBuckets { raw: raw, hashes_end: hashes_end, @@ -776,13 +776,13 @@ pub struct Entries<'a, K: 'a, V: 'a> { } /// Iterator over mutable references to entries in a table. -pub struct MutEntries<'a, K: 'a, V: 'a> { +pub struct IterMut<'a, K: 'a, V: 'a> { iter: RawBuckets<'a, K, V>, elems_left: uint, } /// Iterator over the entries in a table, consuming the table. -pub struct MoveEntries { +pub struct IntoIter { table: RawTable, iter: RawBuckets<'static, K, V> } @@ -809,7 +809,7 @@ impl<'a, K, V> Iterator<(&'a K, &'a V)> for Entries<'a, K, V> { } } -impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for MutEntries<'a, K, V> { +impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for IterMut<'a, K, V> { fn next(&mut self) -> Option<(&'a K, &'a mut V)> { self.iter.next().map(|bucket| { self.elems_left -= 1; @@ -825,7 +825,7 @@ impl<'a, K, V> Iterator<(&'a K, &'a mut V)> for MutEntries<'a, K, V> { } } -impl Iterator<(SafeHash, K, V)> for MoveEntries { +impl Iterator<(SafeHash, K, V)> for IntoIter { fn next(&mut self) -> Option<(SafeHash, K, V)> { self.iter.next().map(|bucket| { self.table.size -= 1;