auto merge of #7487 : huonw/rust/vec-kill, r=cmr

Continuation of #7430.

I haven't removed the `map` method, since the replacement `v.iter().transform(f).collect::<~[SomeType]>()` is a little ridiculous at the moment.
This commit is contained in:
bors 2013-06-30 21:14:13 -07:00
commit 07feeb95c5
68 changed files with 518 additions and 899 deletions

View file

@ -191,13 +191,13 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result {
// Do the BFS.
info!("PBFS iteration %?", i);
i += 1;
colors = do colors.mapi() |i, c| {
colors = do colors.iter().enumerate().transform |(i, c)| {
let c : color = *c;
match c {
white => {
let i = i as node_id;
let neighbors = copy graph[i];
let neighbors = &graph[i];
let mut color = white;
@ -214,17 +214,17 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result {
gray(parent) => { black(parent) }
black(parent) => { black(parent) }
}
}
}.collect()
}
// Convert the results.
do vec::map(colors) |c| {
do colors.iter().transform |c| {
match *c {
white => { -1i64 }
black(parent) => { parent }
_ => { fail!("Found remaining gray nodes in BFS") }
}
}
}.collect()
}
/// A parallel version of the bfs function.
@ -341,7 +341,7 @@ fn validate(edges: ~[(node_id, node_id)],
}
else {
while parent != root {
if vec::contains(path, &parent) {
if path.contains(&parent) {
status = false;
}

View file

@ -152,7 +152,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
// these channels will allow us to talk to each creature by 'name'/index
let to_creature: ~[Chan<Option<CreatureInfo>>] =
vec::mapi(set, |ii, col| {
set.iter().enumerate().transform(|(ii, col)| {
// create each creature as a listener with a port, and
// give us a channel to talk to each
let ii = ii;
@ -166,7 +166,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
to_rendezvous_log.clone());
}
to_creature
});
}).collect();
let mut creatures_met = 0;

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-pretty (extra blank line is inserted in vec::mapi call)
// xfail-pretty the `let to_child` line gets an extra newline
// multi tasking k-nucleotide
extern mod extra;
@ -163,14 +163,13 @@ fn main() {
// initialize each sequence sorter
let sizes = ~[1,2,3,4,6,12,18];
let streams = vec::map(sizes, |_sz| Some(stream()));
let mut streams = streams;
// initialize each sequence sorter
let sizes = ~[1u,2,3,4,6,12,18];
let mut streams = vec::from_fn(sizes.len(), |_| Some(stream::<~str>()));
let mut from_child = ~[];
let to_child = vec::mapi(sizes, |ii, sz| {
let to_child = do sizes.iter().zip(streams.mut_iter()).transform |(sz, stream_ref)| {
let sz = *sz;
let stream = util::replace(&mut streams[ii], None);
let stream = util::replace(stream_ref, None);
let (from_child_, to_parent_) = stream.unwrap();
from_child.push(from_child_);
@ -182,7 +181,7 @@ fn main() {
};
to_child
});
}.collect::<~[Chan<~[u8]>]>();
// latch stores true after we've started

View file

@ -30,7 +30,7 @@ use std::io::WriterUtil;
// Make sure this import is warned about when at least one of its imported names
// is unused
use std::vec::{filter, map}; //~ ERROR unused import
use std::vec::{filter, from_elem}; //~ ERROR unused import
mod foo {
pub struct Point{x: int, y: int}
@ -58,7 +58,5 @@ fn main() {
let a = 3;
ignore(a);
io::stdout().write_str("a");
let _a = do map([2]) |&x| {
x + 2
};
let _a = from_elem(0, 0);
}

View file

@ -1,8 +1,6 @@
// Tests that references to move-by-default values trigger moves when
// they occur as part of various kinds of expressions.
use std::vec;
struct Foo<A> { f: A }
fn guard(_s: ~str) -> bool {fail!()}
fn touch<A>(_a: &A) {}
@ -92,7 +90,7 @@ fn f110() {
fn f120() {
let mut x = ~[~"hi", ~"ho"];
vec::swap(x, 0, 1);
x.swap(0, 1);
touch(&x[0]);
touch(&x[1]);
}

View file

@ -28,7 +28,7 @@ pub fn main() {
assert!(any_negative);
// Higher precedence than unary operations:
let abs_v = do vec::map(v) |e| { e.abs() };
let abs_v = do v.iter().transform |e| { e.abs() }.collect::<~[float]>();
assert!(do abs_v.iter().all |e| { e.is_positive() });
assert!(!do abs_v.iter().any_ |e| { e.is_negative() });

View file

@ -1,20 +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.
use std::vec;
pub fn main() {
let v =
vec::map_zip(~[1, 2, 3, 4, 5],
~[true, false, false, true, true],
|i, b| if *b { -(*i) } else { *i } );
error!(v.clone());
assert_eq!(v, ~[-1, 2, 3, -4, -5]);
}

View file

@ -1,13 +1,11 @@
use std::vec;
trait Reverser {
fn reverse(&self);
fn reverse(v: &mut [uint]) {
v.reverse();
}
fn bar(v: &mut [uint]) {
vec::reverse(v);
vec::reverse(v);
vec::reverse(v);
reverse(v);
reverse(v);
reverse(v);
}
pub fn main() {

View file

@ -1,15 +1,3 @@
use std::vec;
trait Reverser {
fn reverse(self);
}
impl<'self> Reverser for &'self mut [uint] {
fn reverse(self) {
vec::reverse(self);
}
}
fn bar(v: &mut [uint]) {
v.reverse();
v.reverse();

View file

@ -69,9 +69,7 @@ fn AsciiArt(width: uint, height: uint, fill: char) -> AsciiArt {
// blank characters for each position in our canvas.
let mut lines = do vec::build_sized(height) |push| {
for height.times {
let mut line = ~[];
vec::grow_set(&mut line, width-1, &'.', '.');
push(line);
push(vec::from_elem(width, '.'));
}
};

View file

@ -9,11 +9,10 @@
// except according to those terms.
use std::util;
use std::vec;
pub fn main() {
let mut a: ~[int] = ~[0, 1, 2, 3, 4, 5, 6];
vec::swap(a, 2, 4);
a.swap(2, 4);
assert_eq!(a[2], 4);
assert_eq!(a[4], 2);
let mut n = 42;

View file

@ -15,7 +15,9 @@
extern mod std;
use std::str::StrVector;
use std::{int, vec};
use std::vec::ImmutableVector;
use std::iterator::IteratorUtil;
use std::int;
trait to_str {
fn to_str(&self) -> ~str;
@ -27,7 +29,7 @@ impl to_str for int {
impl<T:to_str> to_str for ~[T] {
fn to_str(&self) -> ~str {
~"[" + vec::map(*self, |e| e.to_str()).connect(", ") + "]"
fmt!("[%s]", self.iter().transform(|e| e.to_str()).collect::<~[~str]>().connect(", "))
}
}