#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) □
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;
}
分享到:
相关推荐
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 ...
6.005 秋季 14 班 24 特定领域的音乐语言
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] 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
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 ...
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和GraphX的Spark中的身份图。参考指示创建虚拟环境virtualenv -p python3 .envsource .env/bin/activatepip install -r requirements.txt构建Docker映像./bin/build.sh slave./bin/build.sh master./...
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 ...
- Improvement: TGMMaps -> changed xxToStr and StrToxxx methods to reduce code - Improvement: TGMMaps -> the Printxxxx and SaveToJPGFile methods now uses methods of WebControls unit - Bug fixed: ...
初看Map/Reduce这两个词,熟悉Function Language的人一定感觉很熟悉。FP把这样的函数称为”higher order function”(”High order function”被成为Function Programming的利器之一哦),也就是说,这些函数是编写...
初看Map/Reduce这两个词,熟悉Function Language的人一定感觉很熟悉。FP把这样的函数称为”higher order function”(”High order function”被成为Function Programming的利器之一哦),也就是说,这些函数是编写...
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 ...
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 ...
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....
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 ...
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 ...
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 ...