Implement consuming iterators for ~[], remove vec::{consume, consume_reverse, map_consume}.
This commit is contained in:
parent
55f155521d
commit
eee6775642
14 changed files with 123 additions and 158 deletions
|
|
@ -95,13 +95,13 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph {
|
|||
}
|
||||
}
|
||||
|
||||
do vec::map_consume(graph) |mut v| {
|
||||
do graph.consume_iter().transform |mut v| {
|
||||
let mut vec = ~[];
|
||||
do v.consume |i| {
|
||||
vec.push(i);
|
||||
}
|
||||
vec
|
||||
}
|
||||
}.collect()
|
||||
}
|
||||
|
||||
fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] {
|
||||
|
|
|
|||
|
|
@ -28,20 +28,21 @@ fn calc(children: uint, parent_wait_chan: &Chan<Chan<Chan<int>>>) {
|
|||
wait_port
|
||||
};
|
||||
|
||||
let child_start_chans: ~[Chan<Chan<int>>] = vec::map_consume(wait_ports, |port| port.recv());
|
||||
let child_start_chans: ~[Chan<Chan<int>>] =
|
||||
wait_ports.consume_iter().transform(|port| port.recv()).collect();
|
||||
|
||||
let (start_port, start_chan) = stream::<Chan<int>>();
|
||||
parent_wait_chan.send(start_chan);
|
||||
let parent_result_chan: Chan<int> = start_port.recv();
|
||||
|
||||
let child_sum_ports: ~[Port<int>] = do vec::map_consume(child_start_chans) |child_start_chan| {
|
||||
let (child_sum_port, child_sum_chan) = stream::<int>();
|
||||
child_start_chan.send(child_sum_chan);
|
||||
child_sum_port
|
||||
};
|
||||
let child_sum_ports: ~[Port<int>] =
|
||||
do child_start_chans.consume_iter().transform |child_start_chan| {
|
||||
let (child_sum_port, child_sum_chan) = stream::<int>();
|
||||
child_start_chan.send(child_sum_chan);
|
||||
child_sum_port
|
||||
}.collect();
|
||||
|
||||
let mut sum = 0;
|
||||
vec::consume(child_sum_ports, |_, sum_port| sum += sum_port.recv() );
|
||||
let sum = child_sum_ports.consume_iter().fold(0, |sum, sum_port| sum + sum_port.recv() );
|
||||
|
||||
parent_result_chan.send(sum + 1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue