diff options
Diffstat (limited to 'src/libstd/par.rs')
| -rw-r--r-- | src/libstd/par.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/libstd/par.rs b/src/libstd/par.rs index 38a814b22e0..65e41dba5d8 100644 --- a/src/libstd/par.rs +++ b/src/libstd/par.rs @@ -1,6 +1,5 @@ use future_spawn = future::spawn; -export map, mapi, alli, any, mapi_factory; /** * The maximum number of tasks this module will spawn for a single @@ -55,7 +54,7 @@ fn map_slices<A: Copy Send, B: Copy Send>( f(base, slice) } }; - vec::push(futures, move f); + futures.push(move f); }; base += items_per_task; } @@ -73,21 +72,21 @@ fn map_slices<A: Copy Send, B: Copy Send>( } /// A parallel version of map. -fn map<A: Copy Send, B: Copy Send>(xs: ~[A], f: fn~(A) -> B) -> ~[B] { +pub fn map<A: Copy Send, B: Copy Send>(xs: &[A], +f: fn~((&A)) -> B) -> ~[B] { vec::concat(map_slices(xs, || { fn~(_base: uint, slice : &[A], copy f) -> ~[B] { - vec::map(slice, |x| f(*x)) + vec::map(slice, |x| f(x)) } })) } /// A parallel version of mapi. -fn mapi<A: Copy Send, B: Copy Send>(xs: ~[A], - f: fn~(uint, A) -> B) -> ~[B] { +pub fn mapi<A: Copy Send, B: Copy Send>(xs: &[A], + +f: fn~(uint, (&A)) -> B) -> ~[B] { let slices = map_slices(xs, || { fn~(base: uint, slice : &[A], copy f) -> ~[B] { vec::mapi(slice, |i, x| { - f(i + base, *x) + f(i + base, x) }) } }); @@ -103,7 +102,7 @@ fn mapi<A: Copy Send, B: Copy Send>(xs: ~[A], * In this case, f is a function that creates functions to run over the * inner elements. This is to skirt the need for copy constructors. */ -fn mapi_factory<A: Copy Send, B: Copy Send>( +pub fn mapi_factory<A: Copy Send, B: Copy Send>( xs: &[A], f: fn() -> fn~(uint, A) -> B) -> ~[B] { let slices = map_slices(xs, || { let f = f(); @@ -120,21 +119,21 @@ fn mapi_factory<A: Copy Send, B: Copy Send>( } /// Returns true if the function holds for all elements in the vector. -fn alli<A: Copy Send>(xs: ~[A], f: fn~(uint, A) -> bool) -> bool { +pub fn alli<A: Copy Send>(xs: &[A], +f: fn~(uint, (&A)) -> bool) -> bool { do vec::all(map_slices(xs, || { fn~(base: uint, slice : &[A], copy f) -> bool { vec::alli(slice, |i, x| { f(i + base, x) }) } - })) |x| { x } + })) |x| { *x } } /// Returns true if the function holds for any elements in the vector. -fn any<A: Copy Send>(xs: ~[A], f: fn~(A) -> bool) -> bool { +pub fn any<A: Copy Send>(xs: &[A], +f: fn~(&(A)) -> bool) -> bool { do vec::any(map_slices(xs, || { fn~(_base : uint, slice: &[A], copy f) -> bool { vec::any(slice, |x| f(x)) } - })) |x| { x } + })) |x| { *x } } |
