Skip to content

Commit bf9c255

Browse files
committed
auto merge of #11686 : mankyKitty/rust/rename-invert-to-flip-issue-10632, r=alexcrichton
Renamed the ```invert()``` function in ```iter.rs``` to ```flip()```, from #10632 Also renamed the ```Invert<T>``` type to ```Flip<T>```. Some related code comments changed. Documentation that I could find has been updated, and all the instances I could locate where the function/type were called have been updated as well. This is my first contribution to Rust! Apologies in advance if I've snarfed the PR process, I'm not used to rebase. I initially had issues with the ```codegen``` section of the tests failing, however the ```make check``` process is not reporting any failures at this time. I think that was a local env issue more than me facerolling my changes. :)
2 parents 2b62371 + 292ed3e commit bf9c255

File tree

15 files changed

+96
-96
lines changed

15 files changed

+96
-96
lines changed

doc/guide-container.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ The `DoubleEndedIterator` trait represents an iterator able to yield elements
336336
from either end of a range. It inherits from the `Iterator` trait and extends
337337
it with the `next_back` function.
338338

339-
A `DoubleEndedIterator` can be flipped with the `invert` adaptor, returning
340-
another `DoubleEndedIterator` with `next` and `next_back` exchanged.
339+
A `DoubleEndedIterator` can have its direction changed with the `rev` adaptor,
340+
returning another `DoubleEndedIterator` with `next` and `next_back` exchanged.
341341

342342
~~~
343343
let xs = [1, 2, 3, 4, 5, 6];
@@ -347,7 +347,7 @@ println!("{:?}", it.next()); // prints `Some(&2)`
347347
println!("{:?}", it.next_back()); // prints `Some(&6)`
348348
349349
// prints `5`, `4` and `3`
350-
for &x in it.invert() {
350+
for &x in it.rev() {
351351
println!("{}", x)
352352
}
353353
~~~
@@ -366,7 +366,7 @@ let mut it = xs.iter().chain(ys.iter()).map(|&x| x * 2);
366366
println!("{:?}", it.next()); // prints `Some(2)`
367367
368368
// prints `16`, `14`, `12`, `10`, `8`, `6`, `4`
369-
for x in it.invert() {
369+
for x in it.rev() {
370370
println!("{}", x);
371371
}
372372
~~~

src/libextra/bitv.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use std::cmp;
1515
use std::iter::RandomAccessIterator;
16-
use std::iter::{Invert, Enumerate, Repeat, Map, Zip};
16+
use std::iter::{Rev, Enumerate, Repeat, Map, Zip};
1717
use std::num;
1818
use std::ops;
1919
use std::uint;
@@ -387,7 +387,7 @@ impl Bitv {
387387
}
388388
}
389389

390-
/// Invert all bits
390+
/// Flip all bits
391391
#[inline]
392392
pub fn negate(&mut self) {
393393
match self.rep {
@@ -428,8 +428,8 @@ impl Bitv {
428428
}
429429

430430
#[inline]
431-
pub fn rev_iter<'a>(&'a self) -> Invert<Bits<'a>> {
432-
self.iter().invert()
431+
pub fn rev_iter<'a>(&'a self) -> Rev<Bits<'a>> {
432+
self.iter().rev()
433433
}
434434

435435
/// Returns `true` if all bits are 0

src/libextra/dlist.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use std::cast;
2626
use std::ptr;
2727
use std::util;
28-
use std::iter::Invert;
28+
use std::iter::Rev;
2929
use std::iter;
3030

3131
use container::Deque;
@@ -368,8 +368,8 @@ impl<T> DList<T> {
368368

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

375375
/// Provide a forward iterator with mutable references
@@ -388,8 +388,8 @@ 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<MutItems<'a, T>> {
392-
self.mut_iter().invert()
391+
pub fn mut_rev_iter<'a>(&'a mut self) -> Rev<MutItems<'a, T>> {
392+
self.mut_iter().rev()
393393
}
394394

395395

@@ -401,8 +401,8 @@ impl<T> DList<T> {
401401

402402
/// Consume the list into an iterator yielding elements by value, in reverse
403403
#[inline]
404-
pub fn move_rev_iter(self) -> Invert<MoveItems<T>> {
405-
self.move_iter().invert()
404+
pub fn move_rev_iter(self) -> Rev<MoveItems<T>> {
405+
self.move_iter().rev()
406406
}
407407
}
408408

src/libextra/ringbuf.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
use std::num;
1717
use std::vec;
18-
use std::iter::{Invert, RandomAccessIterator};
18+
use std::iter::{Rev, RandomAccessIterator};
1919

2020
use container::Deque;
2121

@@ -192,8 +192,8 @@ impl<T> RingBuf<T> {
192192
}
193193

194194
/// Back-to-front iterator.
195-
pub fn rev_iter<'a>(&'a self) -> Invert<Items<'a, T>> {
196-
self.iter().invert()
195+
pub fn rev_iter<'a>(&'a self) -> Rev<Items<'a, T>> {
196+
self.iter().rev()
197197
}
198198

199199
/// Front-to-back iterator which returns mutable values.
@@ -223,8 +223,8 @@ impl<T> RingBuf<T> {
223223
}
224224

225225
/// Back-to-front iterator which returns mutable values.
226-
pub fn mut_rev_iter<'a>(&'a mut self) -> Invert<MutItems<'a, T>> {
227-
self.mut_iter().invert()
226+
pub fn mut_rev_iter<'a>(&'a mut self) -> Rev<MutItems<'a, T>> {
227+
self.mut_iter().rev()
228228
}
229229
}
230230

src/libextra/smallintmap.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#[allow(missing_doc)];
1717

18-
use std::iter::{Enumerate, FilterMap, Invert};
18+
use std::iter::{Enumerate, FilterMap, Rev};
1919
use std::util::replace;
2020
use std::vec;
2121

@@ -140,14 +140,14 @@ impl<V> SmallIntMap<V> {
140140
/// An iterator visiting all key-value pairs in descending order by the keys.
141141
/// Iterator element type is (uint, &'r V)
142142
pub fn rev_iter<'r>(&'r self) -> RevEntries<'r, V> {
143-
self.iter().invert()
143+
self.iter().rev()
144144
}
145145

146146
/// An iterator visiting all key-value pairs in descending order by the keys,
147147
/// with mutable references to the values
148148
/// Iterator element type is (uint, &'r mut V)
149149
pub fn mut_rev_iter<'r>(&'r mut self) -> RevMutEntries <'r, V> {
150-
self.mut_iter().invert()
150+
self.mut_iter().rev()
151151
}
152152

153153
/// Empties the hash map, moving all values into the specified closure
@@ -241,7 +241,7 @@ pub struct Entries<'a, T> {
241241

242242
iterator!(impl Entries -> (uint, &'a T), get_ref)
243243
double_ended_iterator!(impl Entries -> (uint, &'a T), get_ref)
244-
pub type RevEntries<'a, T> = Invert<Entries<'a, T>>;
244+
pub type RevEntries<'a, T> = Rev<Entries<'a, T>>;
245245

246246
pub struct MutEntries<'a, T> {
247247
priv front: uint,
@@ -251,7 +251,7 @@ pub struct MutEntries<'a, T> {
251251

252252
iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref)
253253
double_ended_iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref)
254-
pub type RevMutEntries<'a, T> = Invert<MutEntries<'a, T>>;
254+
pub type RevMutEntries<'a, T> = Rev<MutEntries<'a, T>>;
255255

256256
#[cfg(test)]
257257
mod test_map {

src/libnative/io/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
460460
fail!("failure in dup3(err_fd, 2): {}", os::last_os_error());
461461
}
462462
// close all other fds
463-
for fd in range(3, getdtablesize()).invert() {
463+
for fd in range(3, getdtablesize()).rev() {
464464
if fd != output.fd() {
465465
close(fd as c_int);
466466
}

src/librustc/middle/trans/cleanup.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
203203
*/
204204

205205
let scopes = self.scopes.borrow();
206-
for scope in scopes.get().iter().invert() {
206+
for scope in scopes.get().iter().rev() {
207207
match scope.kind {
208208
LoopScopeKind(id, _) => {
209209
return id;
@@ -325,7 +325,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
325325
cleanup_scope);
326326

327327
let mut scopes = self.scopes.borrow_mut();
328-
for scope in scopes.get().mut_iter().invert() {
328+
for scope in scopes.get().mut_iter().rev() {
329329
if scope.kind.is_ast_with_id(cleanup_scope) {
330330
scope.cleanups.push(cleanup);
331331
scope.clear_cached_exits();
@@ -368,7 +368,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
368368
*/
369369

370370
let scopes = self.scopes.borrow();
371-
scopes.get().iter().invert().any(|s| s.needs_invoke())
371+
scopes.get().iter().rev().any(|s| s.needs_invoke())
372372
}
373373

374374
fn get_landing_pad(&self) -> BasicBlockRef {
@@ -415,7 +415,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
415415
* Returns the id of the current top-most AST scope, if any.
416416
*/
417417
let scopes = self.scopes.borrow();
418-
for scope in scopes.get().iter().invert() {
418+
for scope in scopes.get().iter().rev() {
419419
match scope.kind {
420420
CustomScopeKind | LoopScopeKind(..) => {}
421421
AstScopeKind(i) => {
@@ -428,7 +428,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
428428

429429
fn top_nonempty_cleanup_scope(&self) -> Option<uint> {
430430
let scopes = self.scopes.borrow();
431-
scopes.get().iter().invert().position(|s| !s.cleanups.is_empty())
431+
scopes.get().iter().rev().position(|s| !s.cleanups.is_empty())
432432
}
433433

434434
fn is_valid_to_pop_custom_scope(&self, custom_scope: CustomScopeIndex) -> bool {
@@ -450,7 +450,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
450450

451451
let mut bcx = bcx;
452452
if !bcx.unreachable.get() {
453-
for cleanup in scope.cleanups.iter().invert() {
453+
for cleanup in scope.cleanups.iter().rev() {
454454
bcx = cleanup.trans(bcx);
455455
}
456456
}
@@ -619,7 +619,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
619619
debug!("generating cleanups for {}", name);
620620
let bcx_in = self.new_block(label.is_unwind(), name, None);
621621
let mut bcx_out = bcx_in;
622-
for cleanup in scope.cleanups.iter().invert() {
622+
for cleanup in scope.cleanups.iter().rev() {
623623
if cleanup_is_suitable_for(*cleanup, label) {
624624
bcx_out = cleanup.trans(bcx_out);
625625
}

src/libstd/iter.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -670,21 +670,21 @@ pub trait DoubleEndedIterator<A>: Iterator<A> {
670670
/// Yield an element from the end of the range, returning `None` if the range is empty.
671671
fn next_back(&mut self) -> Option<A>;
672672

673-
/// Flip the direction of the iterator
673+
/// Change the direction of the iterator
674674
///
675-
/// The inverted iterator flips the ends on an iterator that can already
675+
/// The flipped iterator swaps the ends on an iterator that can already
676676
/// be iterated from the front and from the back.
677677
///
678678
///
679-
/// If the iterator also implements RandomAccessIterator, the inverted
679+
/// If the iterator also implements RandomAccessIterator, the flipped
680680
/// iterator is also random access, with the indices starting at the back
681681
/// of the original iterator.
682682
///
683-
/// Note: Random access with inverted indices still only applies to the first
683+
/// Note: Random access with flipped indices still only applies to the first
684684
/// `uint::max_value` elements of the original iterator.
685685
#[inline]
686-
fn invert(self) -> Invert<Self> {
687-
Invert{iter: self}
686+
fn rev(self) -> Rev<Self> {
687+
Rev{iter: self}
688688
}
689689
}
690690

@@ -759,30 +759,30 @@ pub trait ExactSize<A> : DoubleEndedIterator<A> {
759759
// Adaptors that may overflow in `size_hint` are not, i.e. `Chain`.
760760
impl<A, T: ExactSize<A>> ExactSize<(uint, A)> for Enumerate<T> {}
761761
impl<'a, A, T: ExactSize<A>> ExactSize<A> for Inspect<'a, A, T> {}
762-
impl<A, T: ExactSize<A>> ExactSize<A> for Invert<T> {}
762+
impl<A, T: ExactSize<A>> ExactSize<A> for Rev<T> {}
763763
impl<'a, A, B, T: ExactSize<A>> ExactSize<B> for Map<'a, A, B, T> {}
764764
impl<A, B, T: ExactSize<A>, U: ExactSize<B>> ExactSize<(A, B)> for Zip<T, U> {}
765765

766766
/// An double-ended iterator with the direction inverted
767767
#[deriving(Clone)]
768-
pub struct Invert<T> {
768+
pub struct Rev<T> {
769769
priv iter: T
770770
}
771771

772-
impl<A, T: DoubleEndedIterator<A>> Iterator<A> for Invert<T> {
772+
impl<A, T: DoubleEndedIterator<A>> Iterator<A> for Rev<T> {
773773
#[inline]
774774
fn next(&mut self) -> Option<A> { self.iter.next_back() }
775775
#[inline]
776776
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
777777
}
778778

779-
impl<A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Invert<T> {
779+
impl<A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Rev<T> {
780780
#[inline]
781781
fn next_back(&mut self) -> Option<A> { self.iter.next() }
782782
}
783783

784784
impl<A, T: DoubleEndedIterator<A> + RandomAccessIterator<A>> RandomAccessIterator<A>
785-
for Invert<T> {
785+
for Rev<T> {
786786
#[inline]
787787
fn indexable(&self) -> uint { self.iter.indexable() }
788788
#[inline]
@@ -2590,12 +2590,12 @@ mod tests {
25902590
}
25912591

25922592
#[test]
2593-
fn test_invert() {
2593+
fn test_rev() {
25942594
let xs = [2, 4, 6, 8, 10, 12, 14, 16];
25952595
let mut it = xs.iter();
25962596
it.next();
25972597
it.next();
2598-
assert_eq!(it.invert().map(|&x| x).collect::<~[int]>(), ~[16, 14, 12, 10, 8, 6]);
2598+
assert_eq!(it.rev().map(|&x| x).collect::<~[int]>(), ~[16, 14, 12, 10, 8, 6]);
25992599
}
26002600

26012601
#[test]
@@ -2662,7 +2662,7 @@ mod tests {
26622662
fn test_double_ended_chain() {
26632663
let xs = [1, 2, 3, 4, 5];
26642664
let ys = ~[7, 9, 11];
2665-
let mut it = xs.iter().chain(ys.iter()).invert();
2665+
let mut it = xs.iter().chain(ys.iter()).rev();
26662666
assert_eq!(it.next().unwrap(), &11)
26672667
assert_eq!(it.next().unwrap(), &9)
26682668
assert_eq!(it.next_back().unwrap(), &1)
@@ -2764,10 +2764,10 @@ mod tests {
27642764
}
27652765

27662766
#[test]
2767-
fn test_random_access_invert() {
2767+
fn test_random_access_rev() {
27682768
let xs = [1, 2, 3, 4, 5];
2769-
check_randacc_iter(xs.iter().invert(), xs.len());
2770-
let mut it = xs.iter().invert();
2769+
check_randacc_iter(xs.iter().rev(), xs.len());
2770+
let mut it = xs.iter().rev();
27712771
it.next();
27722772
it.next_back();
27732773
it.next();
@@ -2833,13 +2833,13 @@ mod tests {
28332833

28342834
#[test]
28352835
fn test_double_ended_range() {
2836-
assert_eq!(range(11i, 14).invert().collect::<~[int]>(), ~[13i, 12, 11]);
2837-
for _ in range(10i, 0).invert() {
2836+
assert_eq!(range(11i, 14).rev().collect::<~[int]>(), ~[13i, 12, 11]);
2837+
for _ in range(10i, 0).rev() {
28382838
fail!("unreachable");
28392839
}
28402840

2841-
assert_eq!(range(11u, 14).invert().collect::<~[uint]>(), ~[13u, 12, 11]);
2842-
for _ in range(10u, 0).invert() {
2841+
assert_eq!(range(11u, 14).rev().collect::<~[uint]>(), ~[13u, 12, 11]);
2842+
for _ in range(10u, 0).rev() {
28432843
fail!("unreachable");
28442844
}
28452845
}
@@ -2886,11 +2886,11 @@ mod tests {
28862886

28872887
assert_eq!(range(0i, 5).collect::<~[int]>(), ~[0i, 1, 2, 3, 4]);
28882888
assert_eq!(range(-10i, -1).collect::<~[int]>(), ~[-10, -9, -8, -7, -6, -5, -4, -3, -2]);
2889-
assert_eq!(range(0i, 5).invert().collect::<~[int]>(), ~[4, 3, 2, 1, 0]);
2889+
assert_eq!(range(0i, 5).rev().collect::<~[int]>(), ~[4, 3, 2, 1, 0]);
28902890
assert_eq!(range(200, -5).collect::<~[int]>(), ~[]);
2891-
assert_eq!(range(200, -5).invert().collect::<~[int]>(), ~[]);
2891+
assert_eq!(range(200, -5).rev().collect::<~[int]>(), ~[]);
28922892
assert_eq!(range(200, 200).collect::<~[int]>(), ~[]);
2893-
assert_eq!(range(200, 200).invert().collect::<~[int]>(), ~[]);
2893+
assert_eq!(range(200, 200).rev().collect::<~[int]>(), ~[]);
28942894

28952895
assert_eq!(range(0i, 100).size_hint(), (100, Some(100)));
28962896
// this test is only meaningful when sizeof uint < sizeof u64
@@ -2902,11 +2902,11 @@ mod tests {
29022902
#[test]
29032903
fn test_range_inclusive() {
29042904
assert_eq!(range_inclusive(0i, 5).collect::<~[int]>(), ~[0i, 1, 2, 3, 4, 5]);
2905-
assert_eq!(range_inclusive(0i, 5).invert().collect::<~[int]>(), ~[5i, 4, 3, 2, 1, 0]);
2905+
assert_eq!(range_inclusive(0i, 5).rev().collect::<~[int]>(), ~[5i, 4, 3, 2, 1, 0]);
29062906
assert_eq!(range_inclusive(200, -5).collect::<~[int]>(), ~[]);
2907-
assert_eq!(range_inclusive(200, -5).invert().collect::<~[int]>(), ~[]);
2907+
assert_eq!(range_inclusive(200, -5).rev().collect::<~[int]>(), ~[]);
29082908
assert_eq!(range_inclusive(200, 200).collect::<~[int]>(), ~[200]);
2909-
assert_eq!(range_inclusive(200, 200).invert().collect::<~[int]>(), ~[200]);
2909+
assert_eq!(range_inclusive(200, 200).rev().collect::<~[int]>(), ~[200]);
29102910
}
29112911

29122912
#[test]

0 commit comments

Comments
 (0)