Skip to content

Commit

Permalink
Rename Invert to Flip - Issue 10632
Browse files Browse the repository at this point in the history
Renamed the invert() function in iter.rs to flip().

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.
  • Loading branch information
mankyKitty committed Jan 23, 2014
1 parent 657e353 commit 55d6e0e
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 94 deletions.
6 changes: 3 additions & 3 deletions doc/guide-container.md
Expand Up @@ -336,7 +336,7 @@ The `DoubleEndedIterator` trait represents an iterator able to yield elements
from either end of a range. It inherits from the `Iterator` trait and extends
it with the `next_back` function.

A `DoubleEndedIterator` can be flipped with the `invert` adaptor, returning
A `DoubleEndedIterator` can be flipped with the `flip` adaptor, returning
another `DoubleEndedIterator` with `next` and `next_back` exchanged.

~~~
Expand All @@ -347,7 +347,7 @@ println!("{:?}", it.next()); // prints `Some(&2)`
println!("{:?}", it.next_back()); // prints `Some(&6)`
// prints `5`, `4` and `3`
for &x in it.invert() {
for &x in it.flip() {
println!("{}", x)
}
~~~
Expand All @@ -366,7 +366,7 @@ let mut it = xs.iter().chain(ys.iter()).map(|&x| x * 2);
println!("{:?}", it.next()); // prints `Some(2)`
// prints `16`, `14`, `12`, `10`, `8`, `6`, `4`
for x in it.invert() {
for x in it.flip() {
println!("{}", x);
}
~~~
Expand Down
8 changes: 4 additions & 4 deletions src/libextra/bitv.rs
Expand Up @@ -13,7 +13,7 @@

use std::cmp;
use std::iter::RandomAccessIterator;
use std::iter::{Invert, Enumerate, Repeat, Map, Zip};
use std::iter::{Flip, Enumerate, Repeat, Map, Zip};
use std::num;
use std::ops;
use std::uint;
Expand Down Expand Up @@ -387,7 +387,7 @@ impl Bitv {
}
}

/// Invert all bits
/// Flip all bits
#[inline]
pub fn negate(&mut self) {
match self.rep {
Expand Down Expand Up @@ -428,8 +428,8 @@ impl Bitv {
}

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

/// Returns `true` if all bits are 0
Expand Down
14 changes: 7 additions & 7 deletions src/libextra/dlist.rs
Expand Up @@ -25,7 +25,7 @@
use std::cast;
use std::ptr;
use std::util;
use std::iter::Invert;
use std::iter::Flip;
use std::iter;

use container::Deque;
Expand Down Expand Up @@ -368,8 +368,8 @@ impl<T> DList<T> {

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

/// Provide a forward iterator with mutable references
Expand All @@ -388,8 +388,8 @@ impl<T> DList<T> {
}
/// Provide a reverse iterator with mutable references
#[inline]
pub fn mut_rev_iter<'a>(&'a mut self) -> Invert<MutItems<'a, T>> {
self.mut_iter().invert()
pub fn mut_rev_iter<'a>(&'a mut self) -> Flip<MutItems<'a, T>> {
self.mut_iter().flip()
}


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

/// Consume the list into an iterator yielding elements by value, in reverse
#[inline]
pub fn move_rev_iter(self) -> Invert<MoveItems<T>> {
self.move_iter().invert()
pub fn move_rev_iter(self) -> Flip<MoveItems<T>> {
self.move_iter().flip()
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/libextra/ringbuf.rs
Expand Up @@ -15,7 +15,7 @@

use std::num;
use std::vec;
use std::iter::{Invert, RandomAccessIterator};
use std::iter::{Flip, RandomAccessIterator};

use container::Deque;

Expand Down Expand Up @@ -192,8 +192,8 @@ impl<T> RingBuf<T> {
}

/// Back-to-front iterator.
pub fn rev_iter<'a>(&'a self) -> Invert<Items<'a, T>> {
self.iter().invert()
pub fn rev_iter<'a>(&'a self) -> Flip<Items<'a, T>> {
self.iter().flip()
}

/// Front-to-back iterator which returns mutable values.
Expand Down Expand Up @@ -223,8 +223,8 @@ impl<T> RingBuf<T> {
}

/// Back-to-front iterator which returns mutable values.
pub fn mut_rev_iter<'a>(&'a mut self) -> Invert<MutItems<'a, T>> {
self.mut_iter().invert()
pub fn mut_rev_iter<'a>(&'a mut self) -> Flip<MutItems<'a, T>> {
self.mut_iter().flip()
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/libextra/smallintmap.rs
Expand Up @@ -15,7 +15,7 @@

#[allow(missing_doc)];

use std::iter::{Enumerate, FilterMap, Invert};
use std::iter::{Enumerate, FilterMap, Flip};
use std::util::replace;
use std::vec;

Expand Down Expand Up @@ -140,14 +140,14 @@ 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> {
self.iter().invert()
self.iter().flip()
}

/// 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> {
self.mut_iter().invert()
self.mut_iter().flip()
}

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

iterator!(impl Entries -> (uint, &'a T), get_ref)
double_ended_iterator!(impl Entries -> (uint, &'a T), get_ref)
pub type RevEntries<'a, T> = Invert<Entries<'a, T>>;
pub type RevEntries<'a, T> = Flip<Entries<'a, T>>;

pub struct MutEntries<'a, T> {
priv front: uint,
Expand All @@ -251,7 +251,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)
pub type RevMutEntries<'a, T> = Invert<MutEntries<'a, T>>;
pub type RevMutEntries<'a, T> = Flip<MutEntries<'a, T>>;

#[cfg(test)]
mod test_map {
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/process.rs
Expand Up @@ -460,7 +460,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
fail!("failure in dup3(err_fd, 2): {}", os::last_os_error());
}
// close all other fds
for fd in range(3, getdtablesize()).invert() {
for fd in range(3, getdtablesize()).flip() {
if fd != output.fd() {
close(fd as c_int);
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/trans/cleanup.rs
Expand Up @@ -203,7 +203,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
*/

let scopes = self.scopes.borrow();
for scope in scopes.get().iter().invert() {
for scope in scopes.get().iter().flip() {
match scope.kind {
LoopScopeKind(id, _) => {
return id;
Expand Down Expand Up @@ -325,7 +325,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
cleanup_scope);

let mut scopes = self.scopes.borrow_mut();
for scope in scopes.get().mut_iter().invert() {
for scope in scopes.get().mut_iter().flip() {
if scope.kind.is_ast_with_id(cleanup_scope) {
scope.cleanups.push(cleanup);
scope.clear_cached_exits();
Expand Down Expand Up @@ -368,7 +368,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
*/

let scopes = self.scopes.borrow();
scopes.get().iter().invert().any(|s| s.needs_invoke())
scopes.get().iter().flip().any(|s| s.needs_invoke())
}

fn get_landing_pad(&self) -> BasicBlockRef {
Expand Down Expand Up @@ -415,7 +415,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
* Returns the id of the current top-most AST scope, if any.
*/
let scopes = self.scopes.borrow();
for scope in scopes.get().iter().invert() {
for scope in scopes.get().iter().flip() {
match scope.kind {
CustomScopeKind | LoopScopeKind(..) => {}
AstScopeKind(i) => {
Expand All @@ -428,7 +428,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {

fn top_nonempty_cleanup_scope(&self) -> Option<uint> {
let scopes = self.scopes.borrow();
scopes.get().iter().invert().position(|s| !s.cleanups.is_empty())
scopes.get().iter().flip().position(|s| !s.cleanups.is_empty())
}

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

let mut bcx = bcx;
if !bcx.unreachable.get() {
for cleanup in scope.cleanups.iter().invert() {
for cleanup in scope.cleanups.iter().flip() {
bcx = cleanup.trans(bcx);
}
}
Expand Down Expand Up @@ -619,7 +619,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
debug!("generating cleanups for {}", name);
let bcx_in = self.new_block(label.is_unwind(), name, None);
let mut bcx_out = bcx_in;
for cleanup in scope.cleanups.iter().invert() {
for cleanup in scope.cleanups.iter().flip() {
if cleanup_is_suitable_for(*cleanup, label) {
bcx_out = cleanup.trans(bcx_out);
}
Expand Down
52 changes: 26 additions & 26 deletions src/libstd/iter.rs
Expand Up @@ -672,19 +672,19 @@ pub trait DoubleEndedIterator<A>: Iterator<A> {

/// Flip the direction of the iterator
///
/// The inverted iterator flips the ends on an iterator that can already
/// The flipped iterator swaps the ends on an iterator that can already
/// be iterated from the front and from the back.
///
///
/// If the iterator also implements RandomAccessIterator, the inverted
/// If the iterator also implements RandomAccessIterator, the flipped
/// iterator is also random access, with the indices starting at the back
/// of the original iterator.
///
/// Note: Random access with inverted indices still only applies to the first
/// Note: Random access with flipped indices still only applies to the first
/// `uint::max_value` elements of the original iterator.
#[inline]
fn invert(self) -> Invert<Self> {
Invert{iter: self}
fn flip(self) -> Flip<Self> {
Flip{iter: self}
}
}

Expand Down Expand Up @@ -759,30 +759,30 @@ pub trait ExactSize<A> : DoubleEndedIterator<A> {
// Adaptors that may overflow in `size_hint` are not, i.e. `Chain`.
impl<A, T: ExactSize<A>> ExactSize<(uint, A)> for Enumerate<T> {}
impl<'a, A, T: ExactSize<A>> ExactSize<A> for Inspect<'a, A, T> {}
impl<A, T: ExactSize<A>> ExactSize<A> for Invert<T> {}
impl<A, T: ExactSize<A>> ExactSize<A> for Flip<T> {}
impl<'a, A, B, T: ExactSize<A>> ExactSize<B> for Map<'a, A, B, T> {}
impl<A, B, T: ExactSize<A>, U: ExactSize<B>> ExactSize<(A, B)> for Zip<T, U> {}

/// An double-ended iterator with the direction inverted
#[deriving(Clone)]
pub struct Invert<T> {
pub struct Flip<T> {
priv iter: T
}

impl<A, T: DoubleEndedIterator<A>> Iterator<A> for Invert<T> {
impl<A, T: DoubleEndedIterator<A>> Iterator<A> for Flip<T> {
#[inline]
fn next(&mut self) -> Option<A> { self.iter.next_back() }
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}

impl<A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Invert<T> {
impl<A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Flip<T> {
#[inline]
fn next_back(&mut self) -> Option<A> { self.iter.next() }
}

impl<A, T: DoubleEndedIterator<A> + RandomAccessIterator<A>> RandomAccessIterator<A>
for Invert<T> {
for Flip<T> {
#[inline]
fn indexable(&self) -> uint { self.iter.indexable() }
#[inline]
Expand Down Expand Up @@ -2590,12 +2590,12 @@ mod tests {
}

#[test]
fn test_invert() {
fn test_flip() {
let xs = [2, 4, 6, 8, 10, 12, 14, 16];
let mut it = xs.iter();
it.next();
it.next();
assert_eq!(it.invert().map(|&x| x).collect::<~[int]>(), ~[16, 14, 12, 10, 8, 6]);
assert_eq!(it.flip().map(|&x| x).collect::<~[int]>(), ~[16, 14, 12, 10, 8, 6]);
}

#[test]
Expand Down Expand Up @@ -2662,7 +2662,7 @@ mod tests {
fn test_double_ended_chain() {
let xs = [1, 2, 3, 4, 5];
let ys = ~[7, 9, 11];
let mut it = xs.iter().chain(ys.iter()).invert();
let mut it = xs.iter().chain(ys.iter()).flip();
assert_eq!(it.next().unwrap(), &11)
assert_eq!(it.next().unwrap(), &9)
assert_eq!(it.next_back().unwrap(), &1)
Expand Down Expand Up @@ -2764,10 +2764,10 @@ mod tests {
}

#[test]
fn test_random_access_invert() {
fn test_random_access_flip() {
let xs = [1, 2, 3, 4, 5];
check_randacc_iter(xs.iter().invert(), xs.len());
let mut it = xs.iter().invert();
check_randacc_iter(xs.iter().flip(), xs.len());
let mut it = xs.iter().flip();
it.next();
it.next_back();
it.next();
Expand Down Expand Up @@ -2833,13 +2833,13 @@ mod tests {

#[test]
fn test_double_ended_range() {
assert_eq!(range(11i, 14).invert().collect::<~[int]>(), ~[13i, 12, 11]);
for _ in range(10i, 0).invert() {
assert_eq!(range(11i, 14).flip().collect::<~[int]>(), ~[13i, 12, 11]);
for _ in range(10i, 0).flip() {
fail!("unreachable");
}

assert_eq!(range(11u, 14).invert().collect::<~[uint]>(), ~[13u, 12, 11]);
for _ in range(10u, 0).invert() {
assert_eq!(range(11u, 14).flip().collect::<~[uint]>(), ~[13u, 12, 11]);
for _ in range(10u, 0).flip() {
fail!("unreachable");
}
}
Expand Down Expand Up @@ -2886,11 +2886,11 @@ mod tests {

assert_eq!(range(0i, 5).collect::<~[int]>(), ~[0i, 1, 2, 3, 4]);
assert_eq!(range(-10i, -1).collect::<~[int]>(), ~[-10, -9, -8, -7, -6, -5, -4, -3, -2]);
assert_eq!(range(0i, 5).invert().collect::<~[int]>(), ~[4, 3, 2, 1, 0]);
assert_eq!(range(0i, 5).flip().collect::<~[int]>(), ~[4, 3, 2, 1, 0]);
assert_eq!(range(200, -5).collect::<~[int]>(), ~[]);
assert_eq!(range(200, -5).invert().collect::<~[int]>(), ~[]);
assert_eq!(range(200, -5).flip().collect::<~[int]>(), ~[]);
assert_eq!(range(200, 200).collect::<~[int]>(), ~[]);
assert_eq!(range(200, 200).invert().collect::<~[int]>(), ~[]);
assert_eq!(range(200, 200).flip().collect::<~[int]>(), ~[]);

assert_eq!(range(0i, 100).size_hint(), (100, Some(100)));
// this test is only meaningful when sizeof uint < sizeof u64
Expand All @@ -2902,11 +2902,11 @@ mod tests {
#[test]
fn test_range_inclusive() {
assert_eq!(range_inclusive(0i, 5).collect::<~[int]>(), ~[0i, 1, 2, 3, 4, 5]);
assert_eq!(range_inclusive(0i, 5).invert().collect::<~[int]>(), ~[5i, 4, 3, 2, 1, 0]);
assert_eq!(range_inclusive(0i, 5).flip().collect::<~[int]>(), ~[5i, 4, 3, 2, 1, 0]);
assert_eq!(range_inclusive(200, -5).collect::<~[int]>(), ~[]);
assert_eq!(range_inclusive(200, -5).invert().collect::<~[int]>(), ~[]);
assert_eq!(range_inclusive(200, -5).flip().collect::<~[int]>(), ~[]);
assert_eq!(range_inclusive(200, 200).collect::<~[int]>(), ~[200]);
assert_eq!(range_inclusive(200, 200).invert().collect::<~[int]>(), ~[200]);
assert_eq!(range_inclusive(200, 200).flip().collect::<~[int]>(), ~[200]);
}

#[test]
Expand Down

0 comments on commit 55d6e0e

Please sign in to comment.