#include "mapper.h" // combined value list corresponding to a word <1,1,1,1....> valueList *createNewValueListNode(char *value){ valueList *newNode = (valueList *)malloc (sizeof(valueList)); strcpy(newNode -> value, value); newNode -> next = NULL; return newNode; } // insert new count to value list valueList *insertNewValueToList(valueList *root, char *count){ valueList *tempNode = root; if(root == NULL) return createNewValueListNode(count); while(tempNode -> next != NULL) tempNode = tempNode -> next; tempNode -> next = createNewValueListNode(count); return root; } // free value list void freeValueList(valueList *root) { if(root == NULL) return; valueList *tempNode = NULL; while (root != NULL){ tempNode = root; root = root -> next; free(tempNode); } } // create intermediateDS *createNewInterDSNode(char *word, char *count){ intermediateDS *newNode = (intermediateDS *)malloc (sizeof(intermediateDS)); strcpy(newNode -> key, word); newNode -> value = NULL; newNode -> value = insertNewValueToList(newNode -> value, count); newNode -> next = NULL; return newNode; } // insert or update a to intermediate DS intermediateDS *insertPairToInterDS(intermediateDS *root, char *word, char *count){ intermediateDS *tempNode = root; if(root == NULL) return createNewInterDSNode(word, count); while(tempNode -> next != NULL) { if(strcmp(tempNode -> key, word) == 0){ tempNode -> value = insertNewValueToList(tempNode -> value, count); return root; } tempNode = tempNode -> next; } if(strcmp(tempNode -> key, word) == 0){ tempNode -> value = insertNewValueToList(tempNode -> value, count); } else { tempNode -> next = createNewInterDSNode(word, count); } return root; } // free the DS after usage. Call this once you are done with the writing of DS into file void freeInterDS(intermediateDS *root) { if(root == NULL) return; intermediateDS *tempNode = NULL; while (root != NULL) { tempNode = root; root = root -> next; freeValueList(tempNode -> value); free(tempNode); } } // emit the into intermediate DS // eats the data into the DS void emit(char *key, char *value) { //Go through intermediateDS, comparing key in list to *key. //If it exists, somehow add to the value list another "1" to the existing list. //If it never does (use string compare thing), add it to the end along with the "1". /* THIS IS NOT CURRENTLY IMPLEMENTED PROPERLY BUT SHOULD BE ABOUT RIGHT CONCEPTUALLY. intermediateDS *tempNode = NULL; while (root != NULL) { tempNode = root; root = root -> next; } */ } // map function void map(char *chunkData){ int i = 0; char *buffer; while ((buffer = getWord(chunkData, &i)) != NULL){ // get words from buffer & give it to emitter to be put into intermediateDS } // you can use getWord to retrieve words from the // chunkData one by one. Example usage in utils.h } // write intermediate data to separate word.txt files // Each file will have only one line : word 1 1 1 1 1 ... // poops the data out into separate .txt files void writeIntermediateDS() { } int main(int argc, char *argv[]) { if (argc < 2) { printf("Less number of arguments.\n"); printf("./mapper mapperID\n"); exit(0); } // ###### DO NOT REMOVE ###### mapperID = strtol(argv[1], NULL, 10); // ###### DO NOT REMOVE ###### // create folder specifically for this mapper in output/MapOut // mapOutDir has the path to the folder where the outputs of // this mapper should be stored mapOutDir = createMapDir(mapperID); // ###### DO NOT REMOVE ###### while(1) { // create an array of chunkSize=1024B and intialize all // elements with '\0' char chunkData[chunkSize + 1]; // +1 for '\0' memset(chunkData, '\0', chunkSize + 1); char *retChunk = getChunkData(mapperID); if(retChunk == NULL) { break; } strcpy(chunkData, retChunk); free(retChunk); map(chunkData); } // ###### DO NOT REMOVE ###### writeIntermediateDS(); return 0; }