`
mindfocus
  • 浏览: 17001 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

Map-Reduce in C Language

阅读更多
#include <stdio.h>
#include <stdio.h>

#define ERROR -1;

/* 函数原型声明 */
typedef int (*mapFunction)(int);
typedef int (*reduceFunction)(int, int);

void map(mapFunction func, int *list, int len) {
	int i;
	for (i = 0; i < len; i++) {
		list[i] = func(list[i]);
	}
}

int reduce(reduceFunction func, int *list, int len) {
	if (len <= 0) {
		return ERROR;
	}
	int result = 0;
	int i;
	for (i = 0; i < len; i++) {
		result = func(result, list[i]);
	}
	return result;
}

/* 函数原型定义 */
int square(int i) {	return i * i; }
int add(int i, int j) {	return i + j; }

/* 测试 */
int main(int argc, char*argv[]) {
	int array[5] = {1, 2, 3, 4, 5};
	int len = sizeof(array)/sizeof(array[0]);

	mapFunction mapFuncPointer = (mapFunction) &square;
	reduceFunction reduceFuncPointer = (reduceFunction) &add;

	map(mapFuncPointer, array, len);  //映射
	int result = reduce(reduceFuncPointer, array, len); // 化简
	printf("The result is %d ", result); // 0 + 1 + 4 + 9 + 16 = 30
	return 0;
}
分享到:
评论

相关推荐

    Hive - A Warehousing Solution Over a Map-Reduce.pdf

    In addition, HiveQL supports custom map-reduce scripts to be plugged into queries. The language includes a type sys- tem with support for tables containing primitive types, col- lections like arrays ...

    F14-EX24-music-language:fall14classes24-map-filter-reduce

    6.005 秋季 14 班 24 特定领域的音乐语言

    Programming Pig

    At the present time, Pig's infrastructure layer consists of a compiler that produces sequences of Map-Reduce programs, for which large-scale parallel implementations already exist (e.g., the Hadoop ...

    Learning [removed] JavaScript programming Vol 1: The language core

    Learning [removed] The non-boring beginner’s guide to ...The big arrangement with map, reduce, filter,… Again from the beginning with recursion That’s where I stay strict! Appetite for Destructuring

    Data-Intensive Text Processing with MapReduce Jimmy Lin and Chris Dyer

    6.4.2 Brief Digression: Language Modeling with MapReduce 6.4.3 Word Alignment 6.4.4 Experiments 6.5 EM-Like Algorithms 6.5.1 Gradient-Based Optimization and Log-Linear Models 6.6 Summary and ...

    ARM® Compiler v5.06 for µVision® armasm User Guide

    6.4 Built-in variables and constants 6.5 Identifying versions of armasm in source code 6.6 Diagnostic messages 6.7 Interlocks diagnostics 6.8 Automatic IT block generation 6.9 Thumb branch target ...

    伦敦:在Python和Hadoop中实现Map Reduce作业

    伦敦使用Python和GraphX的Spark中的身份图。参考指示创建虚拟环境virtualenv -p python3 .envsource .env/bin/activatepip install -r requirements.txt构建Docker映像./bin/build.sh slave./bin/build.sh master./...

    Mastering Concurrency Programming with Java 8

    Toward the end, we will cover the new inclusions in Java 8 API, the Map and Reduce model, and the Map and Collect model. The book will also teach you about the data structures and synchronization ...

    谷歌地图 delphi 封装库 2013 0.1.9 全面支持google maps api

    - Improvement: TGMMaps -&gt; changed xxToStr and StrToxxx methods to reduce code - Improvement: TGMMaps -&gt; the Printxxxx and SaveToJPGFile methods now uses methods of WebControls unit - Bug fixed: ...

    hadoop_3hadoop_3

    初看Map/Reduce这两个词,熟悉Function Language的人一定感觉很熟悉。FP把这样的函数称为”higher order function”(”High order function”被成为Function Programming的利器之一哦),也就是说,这些函数是编写...

    hadoop_2hadoop_2

    初看Map/Reduce这两个词,熟悉Function Language的人一定感觉很熟悉。FP把这样的函数称为”higher order function”(”High order function”被成为Function Programming的利器之一哦),也就是说,这些函数是编写...

    Java SE 8 for the Really Impatient

    that can be passed to common utility functions, making Java collections far more flexible * Major updates to concurrent programming that make use of lambda expressions (filter/map/reduce) and improve ...

    Functional Programming pdf 2018

    See how Swift, the development language for iOS, encourages you to build highly scalable apps using functional techniques like map and reduce. Discover how Scala allows you to transition gently but ...

    Learning Couchbase(PACKT,2015)

    retrieval using map reduce and inbuilt disaster recovery by replicating document across the geographical region, make it one of the most powerful, scalable and comprehensive NoSQL in the market....

    EurekaLog_7.5.0.0_Enterprise

    Later is supported when map2dbg.exe tool is placed in \Bin folder of EurekaLog installation (separate download is required) 5)....Added: Exception2HRESULT in EAppDLL to simplify developing DLLs with ...

    Apache Accumulo for Developers

    It’s assumed that you have an understanding of how Hadoop works, both HDFS and the Map/Reduce. No prior knowledge of ZooKeeper is assumed. Table of Contents Chapter 1: Building an Accumulo Cluster ...

    QGIS Python Programming Cookbook - Second Edition

    You will also learn to create, edit, and optimize a vector layer for faster queries, reproject a vector layer, reduce the number of vertices in a vector layer without losing critical data, and ...

Global site tag (gtag.js) - Google Analytics