首页 > 其他 > 详细

Erlang实现Mapreduce

时间:2015-09-06 01:12:34      阅读:296      评论:0      收藏:0      [点我收藏+]


-module(pmap).
-export([pmap/2]).


pmap(F, L) -> 
  S = self(),
  Pids = lists:map(fun(I) -> 
    spawn(fun() -> do_fun(S, F, I) end)
  end, L),
  gather(Pids).


gather([H|T]) ->
  receive
    {H, Result} -> [Result|gather(T)]
  end;
gather([]) ->
  [].



do_fun(Parent, F, I) ->					    
    Parent ! {self(), (catch F(I))}.


Erlang实现Mapreduce

原文:http://my.oschina.net/yang1992/blog/501468

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!