-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapreduce.h
More file actions
63 lines (55 loc) · 1.92 KB
/
mapreduce.h
File metadata and controls
63 lines (55 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// DO NOT modify this file! This is your program's API, which must be held
// constant.
#ifndef MAPREDUCE_H
#define MAPREDUCE_H
// typedefs
typedef void (*Mapper)(char* file_name);
typedef void (*Reducer)(char* key, unsigned int partition_idx);
// library functions that must be implemented
/**
* Run the MapReduce framework
* Parameters:
* file_count - Number of files (i.e. input splits)
* file_names - Array of filenames
* mapper - Function pointer to the map function
* reducer - Function pointer to the reduce function
* num_workers - Number of threads in the thread pool
* num_parts - Number of partitions to be created
*/
void MR_Run(unsigned int file_count, char* file_names[],
Mapper mapper, Reducer reducer,
unsigned int num_workers, unsigned int num_parts);
/**
* Write a specific map output, a <key, value> pair, to a partition
* Parameters:
* key - Key of the output
* value - Value of the output
*/
void MR_Emit(char* key, char* value);
/**
* Hash a mapper's output to determine the partition that will hold it
* Parameters:
* key - Key of a specific map output
* num_partitions- Total number of partitions
* Return:
* unsigned int - Index of the partition
*/
unsigned int MR_Partitioner(char* key, unsigned int num_partitions);
/**
* Run the reducer callback function for each <key, (list of values)>
* retrieved from a partition
* Parameters:
* threadarg - Pointer to a hidden args object
*/
void MR_Reduce(void* threadarg);
/**
* Get the next value of the given key in the partition
* Parameters:
* key - Key of the values being reduced
* partition_idx - Index of the partition containing this key
* Return:
* char * - Value of the next <key, value> pair if its key is the current key
* NULL - Otherwise
*/
char* MR_GetNext(char* key, unsigned int partition_idx);
#endif