没有合适的资源?快使用搜索试试~ 我知道了~
map and reduceC语言实现
5星 · 超过95%的资源 需积分: 9 24 下载量 155 浏览量
2008-12-21
10:35:41
上传
评论 2
收藏 1KB TXT 举报
温馨提示
试读
2页
简单来说,Map是对一组数据中的每个元素进行操作,产生一组全新的数据;Reduce是对这组数据进行归约,得到一个相对简单的结果。现在就让我们用C语言来描述它们。
资源推荐
资源详情
资源评论
用C语言实现函数语言中的Map和Reduce操作
在Google 的论文《MapReduce:Simplified Data Processing on Large Clusters》中提到“Our abstraction is inspired by the map and reduce primitives present in Lisp and many other functional lanuages.”。对于大部分不熟悉函数语言的程序员来说,可能并不能够彻底理解Map和Reduce的具体含义。在这篇文章中,将采用C语言实现函数语言中的Map和Reduce操作。
简单来说,Map是对一组数据中的每个元素进行操作,产生一组全新的数据;Reduce是对这组数据进行归约,得到一个相对简单的结果。现在就让我们用C语言来描述它们。
#include
//函数指针申明
typedef int (*mapFunction)(int);
typedef int (*reduceFunction)(int,int);
#define ERROR -1;
//-----------------Map和Reduce操作-----------------
/*
* 对list数组的数据进行处理,然后存储在list数组中
*/
void map(mapFunction func,int *list,int len){
int i;
for(i=0;i
list[i] = func(list[i]);
}
}
int reduce(reduceFunction func,int *list,int len){
if(len <= 0){
return ERROR;
}
int retVal = 0;
int i;
for(i=0;i
retVal = func(retVal,list[i]);
}
return retVal;
在Google 的论文《MapReduce:Simplified Data Processing on Large Clusters》中提到“Our abstraction is inspired by the map and reduce primitives present in Lisp and many other functional lanuages.”。对于大部分不熟悉函数语言的程序员来说,可能并不能够彻底理解Map和Reduce的具体含义。在这篇文章中,将采用C语言实现函数语言中的Map和Reduce操作。
简单来说,Map是对一组数据中的每个元素进行操作,产生一组全新的数据;Reduce是对这组数据进行归约,得到一个相对简单的结果。现在就让我们用C语言来描述它们。
#include
//函数指针申明
typedef int (*mapFunction)(int);
typedef int (*reduceFunction)(int,int);
#define ERROR -1;
//-----------------Map和Reduce操作-----------------
/*
* 对list数组的数据进行处理,然后存储在list数组中
*/
void map(mapFunction func,int *list,int len){
int i;
for(i=0;i
list[i] = func(list[i]);
}
}
int reduce(reduceFunction func,int *list,int len){
if(len <= 0){
return ERROR;
}
int retVal = 0;
int i;
for(i=0;i
retVal = func(retVal,list[i]);
}
return retVal;
资源评论
- 零度的折翅2013-06-18具有一定的参考价值,谢谢楼主分享!
- asfaohgah2014-05-27还可以 但是不是wordcount的版本
yh3000
- 粉丝: 5
- 资源: 41
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功