Skip to content

Commit 3fd8c8b

Browse files
author
Palmer Cox
committed
Rename iterators for consistency
Rename existing iterators to get rid of the Iterator suffix and to give them names that better describe the things being iterated over.
1 parent c58d2ba commit 3fd8c8b

30 files changed

+476
-477
lines changed

src/libextra/bitv.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,12 @@ impl Bitv {
414414
}
415415

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

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

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

580580
/// An iterator for `Bitv`.
581-
pub struct BitvIterator<'a> {
581+
pub struct Bits<'a> {
582582
priv bitv: &'a Bitv,
583583
priv next_idx: uint,
584584
priv end_idx: uint,
585585
}
586586

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

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

617-
impl<'a> ExactSize<bool> for BitvIterator<'a> {}
617+
impl<'a> ExactSize<bool> for Bits<'a> {}
618618

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

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

731731
pub fn difference(&self, other: &BitvSet, f: |&uint| -> bool) -> bool {
@@ -871,7 +871,7 @@ impl BitvSet {
871871
/// and w1/w2 are the words coming from the two vectors self, other.
872872
fn commons<'a>(&'a self, other: &'a BitvSet)
873873
-> Map<'static, ((uint, &'a uint), &'a ~[uint]), (uint, uint, uint),
874-
Zip<Enumerate<vec::VecIterator<'a, uint>>, Repeat<&'a ~[uint]>>> {
874+
Zip<Enumerate<vec::Items<'a, uint>>, Repeat<&'a ~[uint]>>> {
875875
let min = num::min(self.bitv.storage.len(), other.bitv.storage.len());
876876
self.bitv.storage.slice(0, min).iter().enumerate()
877877
.zip(Repeat::new(&other.bitv.storage))
@@ -887,7 +887,7 @@ impl BitvSet {
887887
/// `other`.
888888
fn outliers<'a>(&'a self, other: &'a BitvSet)
889889
-> Map<'static, ((uint, &'a uint), uint), (bool, uint, uint),
890-
Zip<Enumerate<vec::VecIterator<'a, uint>>, Repeat<uint>>> {
890+
Zip<Enumerate<vec::Items<'a, uint>>, Repeat<uint>>> {
891891
let slen = self.bitv.storage.len();
892892
let olen = other.bitv.storage.len();
893893

@@ -903,12 +903,12 @@ impl BitvSet {
903903
}
904904
}
905905

906-
pub struct BitvSetIterator<'a> {
906+
pub struct BitPositions<'a> {
907907
priv set: &'a BitvSet,
908908
priv next_idx: uint
909909
}
910910

911-
impl<'a> Iterator<uint> for BitvSetIterator<'a> {
911+
impl<'a> Iterator<uint> for BitPositions<'a> {
912912
#[inline]
913913
fn next(&mut self) -> Option<uint> {
914914
while self.next_idx < self.set.capacity() {

src/libextra/dlist.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ struct Node<T> {
4848

4949
/// Double-ended DList iterator
5050
#[deriving(Clone)]
51-
pub struct DListIterator<'a, T> {
51+
pub struct Items<'a, T> {
5252
priv head: &'a Link<T>,
5353
priv tail: Rawlink<Node<T>>,
5454
priv nelem: uint,
5555
}
5656

5757
/// Double-ended mutable DList iterator
58-
pub struct MutDListIterator<'a, T> {
58+
pub struct MutItems<'a, T> {
5959
priv list: &'a mut DList<T>,
6060
priv head: Rawlink<Node<T>>,
6161
priv tail: Rawlink<Node<T>>,
@@ -64,7 +64,7 @@ pub struct MutDListIterator<'a, T> {
6464

6565
/// DList consuming iterator
6666
#[deriving(Clone)]
67-
pub struct MoveIterator<T> {
67+
pub struct MoveItems<T> {
6868
priv list: DList<T>
6969
}
7070

@@ -362,24 +362,24 @@ impl<T> DList<T> {
362362

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

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

375375
/// Provide a forward iterator with mutable references
376376
#[inline]
377-
pub fn mut_iter<'a>(&'a mut self) -> MutDListIterator<'a, T> {
377+
pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a, T> {
378378
let head_raw = match self.list_head {
379379
Some(ref mut h) => Rawlink::some(*h),
380380
None => Rawlink::none(),
381381
};
382-
MutDListIterator{
382+
MutItems{
383383
nelem: self.len(),
384384
head: head_raw,
385385
tail: self.list_tail,
@@ -388,20 +388,20 @@ impl<T> DList<T> {
388388
}
389389
/// Provide a reverse iterator with mutable references
390390
#[inline]
391-
pub fn mut_rev_iter<'a>(&'a mut self) -> Invert<MutDListIterator<'a, T>> {
391+
pub fn mut_rev_iter<'a>(&'a mut self) -> Invert<MutItems<'a, T>> {
392392
self.mut_iter().invert()
393393
}
394394

395395

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

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

441441

442-
impl<'a, A> Iterator<&'a A> for DListIterator<'a, A> {
442+
impl<'a, A> Iterator<&'a A> for Items<'a, A> {
443443
#[inline]
444444
fn next(&mut self) -> Option<&'a A> {
445445
if self.nelem == 0 {
@@ -458,7 +458,7 @@ impl<'a, A> Iterator<&'a A> for DListIterator<'a, A> {
458458
}
459459
}
460460

461-
impl<'a, A> DoubleEndedIterator<&'a A> for DListIterator<'a, A> {
461+
impl<'a, A> DoubleEndedIterator<&'a A> for Items<'a, A> {
462462
#[inline]
463463
fn next_back(&mut self) -> Option<&'a A> {
464464
if self.nelem == 0 {
@@ -473,9 +473,9 @@ impl<'a, A> DoubleEndedIterator<&'a A> for DListIterator<'a, A> {
473473
}
474474
}
475475

476-
impl<'a, A> ExactSize<&'a A> for DListIterator<'a, A> {}
476+
impl<'a, A> ExactSize<&'a A> for Items<'a, A> {}
477477

478-
impl<'a, A> Iterator<&'a mut A> for MutDListIterator<'a, A> {
478+
impl<'a, A> Iterator<&'a mut A> for MutItems<'a, A> {
479479
#[inline]
480480
fn next(&mut self) -> Option<&'a mut A> {
481481
if self.nelem == 0 {
@@ -497,7 +497,7 @@ impl<'a, A> Iterator<&'a mut A> for MutDListIterator<'a, A> {
497497
}
498498
}
499499

500-
impl<'a, A> DoubleEndedIterator<&'a mut A> for MutDListIterator<'a, A> {
500+
impl<'a, A> DoubleEndedIterator<&'a mut A> for MutItems<'a, A> {
501501
#[inline]
502502
fn next_back(&mut self) -> Option<&'a mut A> {
503503
if self.nelem == 0 {
@@ -511,7 +511,7 @@ impl<'a, A> DoubleEndedIterator<&'a mut A> for MutDListIterator<'a, A> {
511511
}
512512
}
513513

514-
impl<'a, A> ExactSize<&'a mut A> for MutDListIterator<'a, A> {}
514+
impl<'a, A> ExactSize<&'a mut A> for MutItems<'a, A> {}
515515

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

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

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

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

@@ -572,7 +572,7 @@ impl<A> Iterator<A> for MoveIterator<A> {
572572
}
573573
}
574574

575-
impl<A> DoubleEndedIterator<A> for MoveIterator<A> {
575+
impl<A> DoubleEndedIterator<A> for MoveItems<A> {
576576
#[inline]
577577
fn next_back(&mut self) -> Option<A> { self.list.pop_back() }
578578
}

src/libextra/enum_set.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ impl<E:CLike> EnumSet<E> {
7777
}
7878

7979
/// Returns an iterator over an EnumSet
80-
pub fn iter(&self) -> EnumSetIterator<E> {
81-
EnumSetIterator::new(self.bits)
80+
pub fn iter(&self) -> Items<E> {
81+
Items::new(self.bits)
8282
}
8383
}
8484

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

103103
/// An iterator over an EnumSet
104-
pub struct EnumSetIterator<E> {
104+
pub struct Items<E> {
105105
priv index: uint,
106106
priv bits: uint,
107107
}
108108

109-
impl<E:CLike> EnumSetIterator<E> {
110-
fn new(bits: uint) -> EnumSetIterator<E> {
111-
EnumSetIterator { index: 0, bits: bits }
109+
impl<E:CLike> Items<E> {
110+
fn new(bits: uint) -> Items<E> {
111+
Items { index: 0, bits: bits }
112112
}
113113
}
114114

115-
impl<E:CLike> Iterator<E> for EnumSetIterator<E> {
115+
impl<E:CLike> Iterator<E> for Items<E> {
116116
fn next(&mut self) -> Option<E> {
117117
if (self.bits == 0) {
118118
return None;

src/libextra/glob.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/*!
1212
* Support for matching file paths against Unix shell style patterns.
1313
*
14-
* The `glob` and `glob_with` functions, in concert with the `GlobIterator`
14+
* The `glob` and `glob_with` functions, in concert with the `Paths`
1515
* type, allow querying the filesystem for all files that match a particular
1616
* pattern - just like the libc `glob` function (for an example see the `glob`
1717
* documentation). The methods on the `Pattern` type provide functionality
@@ -32,7 +32,7 @@ use std::path::is_sep;
3232
* An iterator that yields Paths from the filesystem that match a particular
3333
* pattern - see the `glob` function for more details.
3434
*/
35-
pub struct GlobIterator {
35+
pub struct Paths {
3636
priv root: Path,
3737
priv dir_patterns: ~[Pattern],
3838
priv options: MatchOptions,
@@ -67,7 +67,7 @@ pub struct GlobIterator {
6767
/// /media/pictures/puppies.jpg
6868
/// ```
6969
///
70-
pub fn glob(pattern: &str) -> GlobIterator {
70+
pub fn glob(pattern: &str) -> Paths {
7171
glob_with(pattern, MatchOptions::new())
7272
}
7373

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

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

109-
GlobIterator {
109+
Paths {
110110
root: root,
111111
dir_patterns: dir_patterns,
112112
options: options,
113113
todo: todo,
114114
}
115115
}
116116

117-
impl Iterator<Path> for GlobIterator {
117+
impl Iterator<Path> for Paths {
118118

119119
fn next(&mut self) -> Option<Path> {
120120
loop {

src/libextra/priority_queue.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ impl<T:Ord> Mutable for PriorityQueue<T> {
3636
impl<T:Ord> PriorityQueue<T> {
3737
/// An iterator visiting all values in underlying vector, in
3838
/// arbitrary order.
39-
pub fn iter<'a>(&'a self) -> PriorityQueueIterator<'a, T> {
40-
PriorityQueueIterator { iter: self.data.iter() }
39+
pub fn iter<'a>(&'a self) -> Items<'a, T> {
40+
Items { iter: self.data.iter() }
4141
}
4242

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

179179
/// PriorityQueue iterator
180-
pub struct PriorityQueueIterator <'a, T> {
181-
priv iter: vec::VecIterator<'a, T>,
180+
pub struct Items <'a, T> {
181+
priv iter: vec::Items<'a, T>,
182182
}
183183

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

0 commit comments

Comments
 (0)