core: rename vec::rev_each{,i} to vec::each{,i}_reverse
I'm making this change because the _reverse suffix is more commonly used in libcore/libstd.
This commit is contained in:
parent
4cb9ca9296
commit
fe74a1c9a2
3 changed files with 37 additions and 14 deletions
|
@ -1005,7 +1005,7 @@ pub pure fn foldl<T, U>(z: T, v: &[U], p: &fn(t: T, u: &U) -> T) -> T {
|
|||
*/
|
||||
pub pure fn foldr<T, U: Copy>(v: &[T], z: U, p: &fn(t: &T, u: U) -> U) -> U {
|
||||
let mut accum = z;
|
||||
for rev_each(v) |elt| {
|
||||
for v.each_reverse |elt| {
|
||||
accum = p(elt, accum);
|
||||
}
|
||||
accum
|
||||
|
@ -1411,8 +1411,8 @@ pub pure fn eachi<T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) {
|
|||
* Return true to continue, false to break.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub pure fn rev_each<T>(v: &'r [T], blk: &fn(v: &'r T) -> bool) {
|
||||
rev_eachi(v, |_i, v| blk(v))
|
||||
pub pure fn each_reverse<T>(v: &'r [T], blk: &fn(v: &'r T) -> bool) {
|
||||
eachi_reverse(v, |_i, v| blk(v))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1421,7 +1421,7 @@ pub pure fn rev_each<T>(v: &'r [T], blk: &fn(v: &'r T) -> bool) {
|
|||
* Return true to continue, false to break.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub pure fn rev_eachi<T>(v: &'r [T], blk: &fn(i: uint, v: &'r T) -> bool) {
|
||||
pub pure fn eachi_reverse<T>(v: &'r [T], blk: &fn(i: uint, v: &'r T) -> bool) {
|
||||
let mut i = v.len();
|
||||
while i > 0 {
|
||||
i -= 1;
|
||||
|
@ -1736,6 +1736,8 @@ pub trait ImmutableVector<T> {
|
|||
pure fn initn(&self, n: uint) -> &'self [T];
|
||||
pure fn last(&self) -> &'self T;
|
||||
pure fn last_opt(&self) -> Option<&'self T>;
|
||||
pure fn each_reverse(&self, blk: &fn(&T) -> bool);
|
||||
pure fn eachi_reverse(&self, blk: &fn(uint, &T) -> bool);
|
||||
pure fn foldr<U: Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U;
|
||||
pure fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U];
|
||||
pure fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U];
|
||||
|
@ -1785,6 +1787,18 @@ impl<T> ImmutableVector<T> for &'self [T] {
|
|||
#[inline]
|
||||
pure fn last_opt(&self) -> Option<&'self T> { last_opt(*self) }
|
||||
|
||||
/// Iterates over a vector's elements in reverse.
|
||||
#[inline]
|
||||
pure fn each_reverse(&self, blk: &fn(&T) -> bool) {
|
||||
each_reverse(*self, blk)
|
||||
}
|
||||
|
||||
/// Iterates over a vector's elements and indices in reverse.
|
||||
#[inline]
|
||||
pure fn eachi_reverse(&self, blk: &fn(uint, &T) -> bool) {
|
||||
eachi_reverse(*self, blk)
|
||||
}
|
||||
|
||||
/// Reduce a vector from right to left
|
||||
#[inline]
|
||||
pure fn foldr<U:Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U {
|
||||
|
@ -3131,16 +3145,17 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_reach_empty() {
|
||||
for rev_each::<int>(~[]) |_v| {
|
||||
fn test_each_reverse_empty() {
|
||||
let v: ~[int] = ~[];
|
||||
for v.each_reverse |_v| {
|
||||
fail!(); // should never execute
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_reach_nonempty() {
|
||||
fn test_each_reverse_nonempty() {
|
||||
let mut i = 0;
|
||||
for rev_each(~[1, 2, 3]) |v| {
|
||||
for each_reverse(~[1, 2, 3]) |v| {
|
||||
if i == 0 { fail_unless!(*v == 3); }
|
||||
i += *v
|
||||
}
|
||||
|
@ -3148,9 +3163,9 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_reachi() {
|
||||
fn test_eachi_reverse() {
|
||||
let mut i = 0;
|
||||
for rev_eachi(~[0, 1, 2]) |j, v| {
|
||||
for eachi_reverse(~[0, 1, 2]) |j, v| {
|
||||
if i == 0 { fail_unless!(*v == 2); }
|
||||
fail_unless!(j == *v as uint);
|
||||
i += *v;
|
||||
|
@ -3158,6 +3173,14 @@ mod tests {
|
|||
fail_unless!(i == 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eachi_reverse_empty() {
|
||||
let v: ~[int] = ~[];
|
||||
for v.eachi_reverse |_i, _v| {
|
||||
fail!(); // should never execute
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_each_permutation() {
|
||||
let mut results: ~[~[int]];
|
||||
|
|
|
@ -1264,7 +1264,7 @@ pub fn trans_block_cleanups_(bcx: block,
|
|||
bcx.ccx().sess.opts.debugging_opts & session::no_landing_pads != 0;
|
||||
if bcx.unreachable && !no_lpads { return bcx; }
|
||||
let mut bcx = bcx;
|
||||
for vec::rev_each(cleanups) |cu| {
|
||||
for cleanups.each_reverse |cu| {
|
||||
match *cu {
|
||||
clean(cfn, cleanup_type) | clean_temp(_, cfn, cleanup_type) => {
|
||||
// Some types don't need to be cleaned up during
|
||||
|
|
|
@ -324,7 +324,7 @@ pub impl BigUint {
|
|||
if s_len < o_len { return -1; }
|
||||
if s_len > o_len { return 1; }
|
||||
|
||||
for vec::rev_eachi(self.data) |i, elm| {
|
||||
for self.data.eachi_reverse |i, elm| {
|
||||
match (*elm, other.data[i]) {
|
||||
(l, r) if l < r => return -1,
|
||||
(l, r) if l > r => return 1,
|
||||
|
@ -387,7 +387,7 @@ pub impl BigUint {
|
|||
let bn = *b.data.last();
|
||||
let mut d = ~[];
|
||||
let mut carry = 0;
|
||||
for vec::rev_each(an) |elt| {
|
||||
for an.each_reverse |elt| {
|
||||
let ai = BigDigit::to_uint(carry, *elt);
|
||||
let di = ai / (bn as uint);
|
||||
fail_unless!(di < BigDigit::base);
|
||||
|
@ -499,7 +499,7 @@ pub impl BigUint {
|
|||
|
||||
let mut borrow = 0;
|
||||
let mut shifted = ~[];
|
||||
for vec::rev_each(self.data) |elem| {
|
||||
for self.data.each_reverse |elem| {
|
||||
shifted = ~[(*elem >> n_bits) | borrow] + shifted;
|
||||
borrow = *elem << (uint::bits - n_bits);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue