aboutsummaryrefslogtreecommitdiffstats
path: root/P2/include
diff options
context:
space:
mode:
Diffstat (limited to 'P2/include')
-rw-r--r--P2/include/mapper.h48
-rw-r--r--P2/include/mapreduce.h8
-rw-r--r--P2/include/reducer.h27
-rw-r--r--P2/include/utils.h43
4 files changed, 126 insertions, 0 deletions
diff --git a/P2/include/mapper.h b/P2/include/mapper.h
new file mode 100644
index 0000000..c67eb08
--- /dev/null
+++ b/P2/include/mapper.h
@@ -0,0 +1,48 @@
+#ifndef MAPPER_H
+#define MAPPER_H
+
+#include "utils.h"
+
+// ###### DO NOT REMOVE ######
+#define MAXKEYSZ 100
+#define MAXVALUESZ 100
+
+// ###### DO NOT REMOVE ######
+char *mapOutDir;
+int mapperID;
+
+
+// You are free to change the intermediate data structure as it suits you
+// If you do so, ensure the provided utility functions are also changed
+// 1 1 1...
+typedef struct valueList {
+ // MAXVALUESZ can be reduced to a small value as you are only storing "1"
+ char value[MAXVALUESZ];
+ struct valueList *next;
+}valueList;
+
+// word 1 1 1...
+typedef struct intermediateDS{
+ char key[MAXKEYSZ];
+ valueList *value;
+ struct intermediateDS *next;
+}intermediateDS;
+
+intermediateDS *interDS = NULL;
+
+// ###### DO NOT REMOVE ######
+valueList *createNewValueListNode(char *value);
+valueList *insertNewValueToList(valueList *root, char *count);
+void freeValueList(valueList *root);
+
+// ###### DO NOT REMOVE ######
+intermediateDS *createNewInterDSNode(char *word, char *count);
+intermediateDS *insertPairToInterDS(intermediateDS *root, char *word, char *count);
+void freeInterDS(intermediateDS *root);
+
+// ###### DO NOT REMOVE ######
+void emit(char *key, char *value);
+void map(char *chunkData);
+void writeIntermediateDS();
+
+#endif \ No newline at end of file
diff --git a/P2/include/mapreduce.h b/P2/include/mapreduce.h
new file mode 100644
index 0000000..97fab69
--- /dev/null
+++ b/P2/include/mapreduce.h
@@ -0,0 +1,8 @@
+#ifndef MAPREDUCE_H
+#define MAPREDUCE_H
+
+#include "utils.h" //sendChunkData and shuffle
+
+void execute(char **argv, int nProcesses);
+
+#endif \ No newline at end of file
diff --git a/P2/include/reducer.h b/P2/include/reducer.h
new file mode 100644
index 0000000..44afe2a
--- /dev/null
+++ b/P2/include/reducer.h
@@ -0,0 +1,27 @@
+#ifndef REDUCER_H
+#define REDUCER_H
+
+#include "utils.h"
+
+#define MAXKEYSZ 50
+
+// ###### DO NOT REMOVE ######
+typedef struct finalKeyValueDS {
+ char key[MAXKEYSZ];
+ int value;
+ struct finalKeyValueDS *next;
+} finalKeyValueDS;
+
+finalKeyValueDS *finalDS = NULL;
+
+// ###### DO NOT REMOVE ######
+finalKeyValueDS *createFinalKeyValueNode(char *value, int count);
+finalKeyValueDS *insertNewKeyValue(finalKeyValueDS *root, char *word, int count);
+void freeFinalDS(finalKeyValueDS *root);
+
+// ###### DO NOT REMOVE ######
+void writeFinalDS(int reducerID);
+void reduce(char *key);
+
+#endif
+
diff --git a/P2/include/utils.h b/P2/include/utils.h
new file mode 100644
index 0000000..2c91cdf
--- /dev/null
+++ b/P2/include/utils.h
@@ -0,0 +1,43 @@
+#ifndef UTILS_H
+#define UTILS_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/msg.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <ctype.h>
+
+#define chunkSize 1024
+#define MSGSIZE 1100
+
+struct msgBuffer {
+ long msgType;
+ char msgText[MSGSIZE];
+};
+
+// mapper side
+int validChar(char c);
+char *getWord(char *chunk, int *i);
+char *getChunkData(int mapperID);
+void sendChunkData(char *inputFile, int nMappers);
+
+
+// reducer side
+int hashFunction(char* key, int reducers);
+int getInterData(char *key, int reducerID);
+void shuffle(int nMappers, int nReducers);
+
+// directory
+void createOutputDir();
+char *createMapDir(int mapperID);
+void removeOutputDir();
+void bookeepingCode();
+
+#endif \ No newline at end of file