vec: rm obsolete zip and zip_slice
These are obsoleted by the generic iterator `zip` adaptor. Unlike these, it does not clone the elements or allocate a new vector by default.
This commit is contained in:
parent
1f89eb867a
commit
45426c3b4c
src
@ -782,11 +782,8 @@ mod test_qsort3 {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_qsort {
|
||||
|
||||
use sort::*;
|
||||
|
||||
use std::vec;
|
||||
|
||||
fn check_sort(v1: &mut [int], v2: &mut [int]) {
|
||||
let len = v1.len();
|
||||
fn leual(a: &int, b: &int) -> bool { *a <= *b }
|
||||
@ -835,9 +832,7 @@ mod test_qsort {
|
||||
|
||||
let immut_names = names;
|
||||
|
||||
let pairs = vec::zip_slice(expected, immut_names);
|
||||
for p in pairs.iter() {
|
||||
let (a, b) = *p;
|
||||
for (&a, &b) in expected.iter().zip(immut_names.iter()) {
|
||||
debug!("%d %d", a, b);
|
||||
assert_eq!(a, b);
|
||||
}
|
||||
|
@ -1121,7 +1121,6 @@ mod tests {
|
||||
|
||||
use std::either;
|
||||
use std::comm::{stream, SharedChan};
|
||||
use std::vec;
|
||||
use tempfile;
|
||||
use std::os;
|
||||
|
||||
@ -1309,14 +1308,8 @@ mod tests {
|
||||
~"test::parse_ignored_flag",
|
||||
~"test::sort_tests"];
|
||||
|
||||
let pairs = vec::zip(expected, filtered);
|
||||
|
||||
for p in pairs.iter() {
|
||||
match *p {
|
||||
(ref a, ref b) => {
|
||||
assert!(*a == b.desc.name.to_str());
|
||||
}
|
||||
}
|
||||
for (a, b) in expected.iter().zip(filtered.iter()) {
|
||||
assert!(*a == b.desc.name.to_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -390,39 +390,6 @@ pub fn unzip<T,U>(v: ~[(T, U)]) -> (~[T], ~[U]) {
|
||||
(ts, us)
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert two vectors to a vector of pairs, by reference. As zip().
|
||||
*/
|
||||
pub fn zip_slice<T:Clone,U:Clone>(v: &[T], u: &[U]) -> ~[(T, U)] {
|
||||
let mut zipped = ~[];
|
||||
let sz = v.len();
|
||||
let mut i = 0u;
|
||||
assert_eq!(sz, u.len());
|
||||
while i < sz {
|
||||
zipped.push((v[i].clone(), u[i].clone()));
|
||||
i += 1u;
|
||||
}
|
||||
zipped
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert two vectors to a vector of pairs.
|
||||
*
|
||||
* Returns a vector of tuples, where the i-th tuple contains the
|
||||
* i-th elements from each of the input vectors.
|
||||
*/
|
||||
pub fn zip<T, U>(mut v: ~[T], mut u: ~[U]) -> ~[(T, U)] {
|
||||
let mut i = v.len();
|
||||
assert_eq!(i, u.len());
|
||||
let mut w = with_capacity(i);
|
||||
while i > 0 {
|
||||
w.push((v.pop(),u.pop()));
|
||||
i -= 1;
|
||||
}
|
||||
w.reverse();
|
||||
w
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over all permutations of vector `v`.
|
||||
*
|
||||
@ -2865,14 +2832,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_zip_unzip() {
|
||||
let v1 = ~[1, 2, 3];
|
||||
let v2 = ~[4, 5, 6];
|
||||
|
||||
let z1 = zip(v1, v2);
|
||||
|
||||
assert_eq!((1, 4), z1[0]);
|
||||
assert_eq!((2, 5), z1[1]);
|
||||
assert_eq!((3, 6), z1[2]);
|
||||
let z1 = ~[(1, 4), (2, 5), (3, 6)];
|
||||
|
||||
let (left, right) = unzip(z1);
|
||||
|
||||
|
@ -1,44 +0,0 @@
|
||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// In this case, the code should compile and should
|
||||
// succeed at runtime
|
||||
|
||||
use std::vec;
|
||||
|
||||
fn enum_chars(start: u8, end: u8) -> ~[char] {
|
||||
assert!(start < end);
|
||||
let mut i = start;
|
||||
let mut r = ~[];
|
||||
while i <= end { r.push(i as char); i += 1u as u8; }
|
||||
return r;
|
||||
}
|
||||
|
||||
fn enum_uints(start: uint, end: uint) -> ~[uint] {
|
||||
assert!(start < end);
|
||||
let mut i = start;
|
||||
let mut r = ~[];
|
||||
while i <= end { r.push(i); i += 1u; }
|
||||
return r;
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let a = 'a' as u8;
|
||||
let j = 'j' as u8;
|
||||
let k = 1u;
|
||||
let l = 10u;
|
||||
let chars = enum_chars(a, j);
|
||||
let ints = enum_uints(k, l);
|
||||
|
||||
let ps = vec::zip(chars, ints);
|
||||
|
||||
assert_eq!(ps.head(), &('a', 1u));
|
||||
assert_eq!(ps.last(), &(j as char, 10u));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user