#include <stdio.h> #include <stdint.h> #include <stdarg.h> #include <stdlib.h> #include <string.h> #include "utils.h" void encodeRLE(int taskId) { int i = 0; int ord = 0; struct task *curTask = taskQueue[taskId]; struct result *curResult = resultQueue[taskId]; int cursor = curTask -> fileCursor; char *curFile = fileContents[curTask -> fileIndex]; uint8_t curCount = 0; unsigned char curChar = curFile[cursor]; while (i < CHUNKSIZE && cursor < fileLengths[curTask -> fileIndex]) { if (curFile[cursor] == curChar) { curCount ++; } else { curResult -> charArray[ord] = curChar; curResult -> countArray[ord] = curCount; curChar = curFile[cursor]; curCount = 1; ord ++; } i ++; cursor ++; } curResult -> charArray[ord] = curChar; curResult -> countArray[ord] = curCount; curResult -> resultLength = ord + 1; if (DEBUG) fprintf(stderr, "task %d: %d --> %d bytes\n", taskId, i, (ord + 1) * 2); }