Skip to content

Commit

Permalink
Rename iterators for consistency
Browse files Browse the repository at this point in the history
Rename existing iterators to get rid of the Iterator suffix and to
give them names that better describe the things being iterated over.
  • Loading branch information
Palmer Cox committed Jan 18, 2014
1 parent c58d2ba commit 3fd8c8b
Show file tree
Hide file tree
Showing 30 changed files with 476 additions and 477 deletions.
28 changes: 14 additions & 14 deletions src/libextra/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,12 @@ impl Bitv {
}

#[inline]
pub fn iter<'a>(&'a self) -> BitvIterator<'a> {
BitvIterator {bitv: self, next_idx: 0, end_idx: self.nbits}
pub fn iter<'a>(&'a self) -> Bits<'a> {
Bits {bitv: self, next_idx: 0, end_idx: self.nbits}
}

#[inline]
pub fn rev_iter<'a>(&'a self) -> Invert<BitvIterator<'a>> {
pub fn rev_iter<'a>(&'a self) -> Invert<Bits<'a>> {
self.iter().invert()
}

Expand Down Expand Up @@ -578,13 +578,13 @@ fn iterate_bits(base: uint, bits: uint, f: |uint| -> bool) -> bool {
}

/// An iterator for `Bitv`.
pub struct BitvIterator<'a> {
pub struct Bits<'a> {
priv bitv: &'a Bitv,
priv next_idx: uint,
priv end_idx: uint,
}

impl<'a> Iterator<bool> for BitvIterator<'a> {
impl<'a> Iterator<bool> for Bits<'a> {
#[inline]
fn next(&mut self) -> Option<bool> {
if self.next_idx != self.end_idx {
Expand All @@ -602,7 +602,7 @@ impl<'a> Iterator<bool> for BitvIterator<'a> {
}
}

impl<'a> DoubleEndedIterator<bool> for BitvIterator<'a> {
impl<'a> DoubleEndedIterator<bool> for Bits<'a> {
#[inline]
fn next_back(&mut self) -> Option<bool> {
if self.next_idx != self.end_idx {
Expand All @@ -614,9 +614,9 @@ impl<'a> DoubleEndedIterator<bool> for BitvIterator<'a> {
}
}

impl<'a> ExactSize<bool> for BitvIterator<'a> {}
impl<'a> ExactSize<bool> for Bits<'a> {}

impl<'a> RandomAccessIterator<bool> for BitvIterator<'a> {
impl<'a> RandomAccessIterator<bool> for Bits<'a> {
#[inline]
fn indexable(&self) -> uint {
self.end_idx - self.next_idx
Expand Down Expand Up @@ -724,8 +724,8 @@ impl BitvSet {
self.other_op(other, |w1, w2| w1 ^ w2);
}

pub fn iter<'a>(&'a self) -> BitvSetIterator<'a> {
BitvSetIterator {set: self, next_idx: 0}
pub fn iter<'a>(&'a self) -> BitPositions<'a> {
BitPositions {set: self, next_idx: 0}
}

pub fn difference(&self, other: &BitvSet, f: |&uint| -> bool) -> bool {
Expand Down Expand Up @@ -871,7 +871,7 @@ impl BitvSet {
/// and w1/w2 are the words coming from the two vectors self, other.
fn commons<'a>(&'a self, other: &'a BitvSet)
-> Map<'static, ((uint, &'a uint), &'a ~[uint]), (uint, uint, uint),
Zip<Enumerate<vec::VecIterator<'a, uint>>, Repeat<&'a ~[uint]>>> {
Zip<Enumerate<vec::Items<'a, uint>>, Repeat<&'a ~[uint]>>> {
let min = num::min(self.bitv.storage.len(), other.bitv.storage.len());
self.bitv.storage.slice(0, min).iter().enumerate()
.zip(Repeat::new(&other.bitv.storage))
Expand All @@ -887,7 +887,7 @@ impl BitvSet {
/// `other`.
fn outliers<'a>(&'a self, other: &'a BitvSet)
-> Map<'static, ((uint, &'a uint), uint), (bool, uint, uint),
Zip<Enumerate<vec::VecIterator<'a, uint>>, Repeat<uint>>> {
Zip<Enumerate<vec::Items<'a, uint>>, Repeat<uint>>> {
let slen = self.bitv.storage.len();
let olen = other.bitv.storage.len();

Expand All @@ -903,12 +903,12 @@ impl BitvSet {
}
}

pub struct BitvSetIterator<'a> {
pub struct BitPositions<'a> {
priv set: &'a BitvSet,
priv next_idx: uint
}

impl<'a> Iterator<uint> for BitvSetIterator<'a> {
impl<'a> Iterator<uint> for BitPositions<'a> {
#[inline]
fn next(&mut self) -> Option<uint> {
while self.next_idx < self.set.capacity() {
Expand Down
46 changes: 23 additions & 23 deletions src/libextra/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ struct Node<T> {

/// Double-ended DList iterator
#[deriving(Clone)]
pub struct DListIterator<'a, T> {
pub struct Items<'a, T> {
priv head: &'a Link<T>,
priv tail: Rawlink<Node<T>>,
priv nelem: uint,
}

/// Double-ended mutable DList iterator
pub struct MutDListIterator<'a, T> {
pub struct MutItems<'a, T> {
priv list: &'a mut DList<T>,
priv head: Rawlink<Node<T>>,
priv tail: Rawlink<Node<T>>,
Expand All @@ -64,7 +64,7 @@ pub struct MutDListIterator<'a, T> {

/// DList consuming iterator
#[deriving(Clone)]
pub struct MoveIterator<T> {
pub struct MoveItems<T> {
priv list: DList<T>
}

Expand Down Expand Up @@ -362,24 +362,24 @@ impl<T> DList<T> {

/// Provide a forward iterator
#[inline]
pub fn iter<'a>(&'a self) -> DListIterator<'a, T> {
DListIterator{nelem: self.len(), head: &self.list_head, tail: self.list_tail}
pub fn iter<'a>(&'a self) -> Items<'a, T> {
Items{nelem: self.len(), head: &self.list_head, tail: self.list_tail}
}

/// Provide a reverse iterator
#[inline]
pub fn rev_iter<'a>(&'a self) -> Invert<DListIterator<'a, T>> {
pub fn rev_iter<'a>(&'a self) -> Invert<Items<'a, T>> {
self.iter().invert()
}

/// Provide a forward iterator with mutable references
#[inline]
pub fn mut_iter<'a>(&'a mut self) -> MutDListIterator<'a, T> {
pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> {
let head_raw = match self.list_head {
Some(ref mut h) => Rawlink::some(*h),
None => Rawlink::none(),
};
MutDListIterator{
MutItems{
nelem: self.len(),
head: head_raw,
tail: self.list_tail,
Expand All @@ -388,20 +388,20 @@ impl<T> DList<T> {
}
/// Provide a reverse iterator with mutable references
#[inline]
pub fn mut_rev_iter<'a>(&'a mut self) -> Invert<MutDListIterator<'a, T>> {
pub fn mut_rev_iter<'a>(&'a mut self) -> Invert<MutItems<'a, T>> {
self.mut_iter().invert()
}


/// Consume the list into an iterator yielding elements by value
#[inline]
pub fn move_iter(self) -> MoveIterator<T> {
MoveIterator{list: self}
pub fn move_iter(self) -> MoveItems<T> {
MoveItems{list: self}
}

/// Consume the list into an iterator yielding elements by value, in reverse
#[inline]
pub fn move_rev_iter(self) -> Invert<MoveIterator<T>> {
pub fn move_rev_iter(self) -> Invert<MoveItems<T>> {
self.move_iter().invert()
}
}
Expand Down Expand Up @@ -439,7 +439,7 @@ impl<T> Drop for DList<T> {
}


impl<'a, A> Iterator<&'a A> for DListIterator<'a, A> {
impl<'a, A> Iterator<&'a A> for Items<'a, A> {
#[inline]
fn next(&mut self) -> Option<&'a A> {
if self.nelem == 0 {
Expand All @@ -458,7 +458,7 @@ impl<'a, A> Iterator<&'a A> for DListIterator<'a, A> {
}
}

impl<'a, A> DoubleEndedIterator<&'a A> for DListIterator<'a, A> {
impl<'a, A> DoubleEndedIterator<&'a A> for Items<'a, A> {
#[inline]
fn next_back(&mut self) -> Option<&'a A> {
if self.nelem == 0 {
Expand All @@ -473,9 +473,9 @@ impl<'a, A> DoubleEndedIterator<&'a A> for DListIterator<'a, A> {
}
}

impl<'a, A> ExactSize<&'a A> for DListIterator<'a, A> {}
impl<'a, A> ExactSize<&'a A> for Items<'a, A> {}

impl<'a, A> Iterator<&'a mut A> for MutDListIterator<'a, A> {
impl<'a, A> Iterator<&'a mut A> for MutItems<'a, A> {
#[inline]
fn next(&mut self) -> Option<&'a mut A> {
if self.nelem == 0 {
Expand All @@ -497,7 +497,7 @@ impl<'a, A> Iterator<&'a mut A> for MutDListIterator<'a, A> {
}
}

impl<'a, A> DoubleEndedIterator<&'a mut A> for MutDListIterator<'a, A> {
impl<'a, A> DoubleEndedIterator<&'a mut A> for MutItems<'a, A> {
#[inline]
fn next_back(&mut self) -> Option<&'a mut A> {
if self.nelem == 0 {
Expand All @@ -511,7 +511,7 @@ impl<'a, A> DoubleEndedIterator<&'a mut A> for MutDListIterator<'a, A> {
}
}

impl<'a, A> ExactSize<&'a mut A> for MutDListIterator<'a, A> {}
impl<'a, A> ExactSize<&'a mut A> for MutItems<'a, A> {}

/// Allow mutating the DList while iterating
pub trait ListInsertion<A> {
Expand All @@ -524,8 +524,8 @@ pub trait ListInsertion<A> {
fn peek_next<'a>(&'a mut self) -> Option<&'a mut A>;
}

// private methods for MutDListIterator
impl<'a, A> MutDListIterator<'a, A> {
// private methods for MutItems
impl<'a, A> MutItems<'a, A> {
fn insert_next_node(&mut self, mut ins_node: ~Node<A>) {
// Insert before `self.head` so that it is between the
// previously yielded element and self.head.
Expand All @@ -547,7 +547,7 @@ impl<'a, A> MutDListIterator<'a, A> {
}
}

impl<'a, A> ListInsertion<A> for MutDListIterator<'a, A> {
impl<'a, A> ListInsertion<A> for MutItems<'a, A> {
#[inline]
fn insert_next(&mut self, elt: A) {
self.insert_next_node(~Node::new(elt))
Expand All @@ -562,7 +562,7 @@ impl<'a, A> ListInsertion<A> for MutDListIterator<'a, A> {
}
}

impl<A> Iterator<A> for MoveIterator<A> {
impl<A> Iterator<A> for MoveItems<A> {
#[inline]
fn next(&mut self) -> Option<A> { self.list.pop_front() }

Expand All @@ -572,7 +572,7 @@ impl<A> Iterator<A> for MoveIterator<A> {
}
}

impl<A> DoubleEndedIterator<A> for MoveIterator<A> {
impl<A> DoubleEndedIterator<A> for MoveItems<A> {
#[inline]
fn next_back(&mut self) -> Option<A> { self.list.pop_back() }
}
Expand Down
14 changes: 7 additions & 7 deletions src/libextra/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ impl<E:CLike> EnumSet<E> {
}

/// Returns an iterator over an EnumSet
pub fn iter(&self) -> EnumSetIterator<E> {
EnumSetIterator::new(self.bits)
pub fn iter(&self) -> Items<E> {
Items::new(self.bits)
}
}

Expand All @@ -101,18 +101,18 @@ impl<E:CLike> BitAnd<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
}

/// An iterator over an EnumSet
pub struct EnumSetIterator<E> {
pub struct Items<E> {
priv index: uint,
priv bits: uint,
}

impl<E:CLike> EnumSetIterator<E> {
fn new(bits: uint) -> EnumSetIterator<E> {
EnumSetIterator { index: 0, bits: bits }
impl<E:CLike> Items<E> {
fn new(bits: uint) -> Items<E> {
Items { index: 0, bits: bits }
}
}

impl<E:CLike> Iterator<E> for EnumSetIterator<E> {
impl<E:CLike> Iterator<E> for Items<E> {
fn next(&mut self) -> Option<E> {
if (self.bits == 0) {
return None;
Expand Down
14 changes: 7 additions & 7 deletions src/libextra/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/*!
* Support for matching file paths against Unix shell style patterns.
*
* The `glob` and `glob_with` functions, in concert with the `GlobIterator`
* The `glob` and `glob_with` functions, in concert with the `Paths`
* type, allow querying the filesystem for all files that match a particular
* pattern - just like the libc `glob` function (for an example see the `glob`
* documentation). The methods on the `Pattern` type provide functionality
Expand All @@ -32,7 +32,7 @@ use std::path::is_sep;
* An iterator that yields Paths from the filesystem that match a particular
* pattern - see the `glob` function for more details.
*/
pub struct GlobIterator {
pub struct Paths {
priv root: Path,
priv dir_patterns: ~[Pattern],
priv options: MatchOptions,
Expand Down Expand Up @@ -67,7 +67,7 @@ pub struct GlobIterator {
/// /media/pictures/puppies.jpg
/// ```
///
pub fn glob(pattern: &str) -> GlobIterator {
pub fn glob(pattern: &str) -> Paths {
glob_with(pattern, MatchOptions::new())
}

Expand All @@ -82,7 +82,7 @@ pub fn glob(pattern: &str) -> GlobIterator {
*
* Paths are yielded in alphabetical order, as absolute paths.
*/
pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator {
pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths {
#[cfg(windows)]
fn check_windows_verbatim(p: &Path) -> bool { path::windows::is_verbatim(p) }
#[cfg(not(windows))]
Expand All @@ -95,7 +95,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator {
if check_windows_verbatim(pat_root.get_ref()) {
// XXX: How do we want to handle verbatim paths? I'm inclined to return nothing,
// since we can't very well find all UNC shares with a 1-letter server name.
return GlobIterator { root: root, dir_patterns: ~[], options: options, todo: ~[] };
return Paths { root: root, dir_patterns: ~[], options: options, todo: ~[] };
}
root.push(pat_root.get_ref());
}
Expand All @@ -106,15 +106,15 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator {

let todo = list_dir_sorted(&root).move_iter().map(|x|(x,0u)).to_owned_vec();

GlobIterator {
Paths {
root: root,
dir_patterns: dir_patterns,
options: options,
todo: todo,
}
}

impl Iterator<Path> for GlobIterator {
impl Iterator<Path> for Paths {

fn next(&mut self) -> Option<Path> {
loop {
Expand Down
10 changes: 5 additions & 5 deletions src/libextra/priority_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ impl<T:Ord> Mutable for PriorityQueue<T> {
impl<T:Ord> PriorityQueue<T> {
/// An iterator visiting all values in underlying vector, in
/// arbitrary order.
pub fn iter<'a>(&'a self) -> PriorityQueueIterator<'a, T> {
PriorityQueueIterator { iter: self.data.iter() }
pub fn iter<'a>(&'a self) -> Items<'a, T> {
Items { iter: self.data.iter() }
}

/// Returns the greatest item in the queue - fails if empty
Expand Down Expand Up @@ -177,11 +177,11 @@ impl<T:Ord> PriorityQueue<T> {
}

/// PriorityQueue iterator
pub struct PriorityQueueIterator <'a, T> {
priv iter: vec::VecIterator<'a, T>,
pub struct Items <'a, T> {
priv iter: vec::Items<'a, T>,
}

impl<'a, T> Iterator<&'a T> for PriorityQueueIterator<'a, T> {
impl<'a, T> Iterator<&'a T> for Items<'a, T> {
#[inline]
fn next(&mut self) -> Option<(&'a T)> { self.iter.next() }

Expand Down
Loading

5 comments on commit 3fd8c8b

@bors
Copy link
Contributor

@bors bors commented on 3fd8c8b Jan 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at DaGenix@3fd8c8b

@bors
Copy link
Contributor

@bors bors commented on 3fd8c8b Jan 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging DaGenix/rust/iter-renaming = 3fd8c8b into auto

@bors
Copy link
Contributor

@bors bors commented on 3fd8c8b Jan 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DaGenix/rust/iter-renaming = 3fd8c8b merged ok, testing candidate = 1da2962

@bors
Copy link
Contributor

@bors bors commented on 3fd8c8b Jan 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 3fd8c8b Jan 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 1da2962

Please sign in to comment.