void processor(const std::string& ifname, const std::string& ofname) { binFileReader bfr(ifname); if (!bfr.fileOk){ return; } binFileWriter bfw(ofname); if (!bfw.fileOk) { return; } uint32_t maxTime = 0; bool isRecordValid; dataStruct1_t ds1; while (bfr.readDataStruct(ds1)) { isRecordValid = true; if ((!acceptableOperations.count(ds1.type)) || (ds1.time + 2 <= maxTime)) { isRecordValid = false; } if (maxTime < ds1.time) { maxTime = ds1.time; } if (isRecordValid) { bfw.writeDataStruct(ds1); } } }
void processor(const std::string& ifname, const std::string& ofname) { binFileReader bfr(ifname); if (!bfr.fileOk){ return; } binFileWriter bfw(ofname); if (!bfw.fileOk) { return; } uint32_t messageSize; uint32_t currentTime = 0; uint32_t secondsCount = 0; static const int buffSize = 2048; counting_map_t buffersSizes; counting_map_t messagesCount; dataStruct1_t ds1; //input while (bfr.readDataStruct(ds1)) { //new second if (currentTime != ds1.time) { currentTime = ds1.time; secondsCount++; buffersSizes.clear(); } messageSize = sizeof ds1.type + sizeof ds1.time + sizeof ds1.len + (sizeof(char)) * ds1.len; if (!buffersSizes.count(ds1.type)) { buffersSizes[ds1.type] = buffSize - messageSize; if(buffersSizes[ds1.type] > 0){ messagesCount[ds1.type] += 1; } } else { buffersSizes[ds1.type] = buffersSizes[ds1.type] - messageSize; if (buffersSizes[ds1.type] > 0) { messagesCount[ds1.type] += 1; } } } //output double avgMsg; for (counting_map_t::const_iterator it = messagesCount.begin(); it != messagesCount.end(); ++it) { bfw.writeRawValue(it->first); avgMsg = (double) it->second / secondsCount; bfw.writeRawValue(avgMsg); } }
void writeCompressedOutput(const char* inFile, const char *outFile, const std::map<unsigned,BitString> &theMap ){ BitFileWriter bfw(outFile); writeHeader(&bfw,theMap); //WRITE YOUR CODE HERE! //open the input file for reading //You need to read the input file, lookup the characters in the map, //and write the proper bit string with the BitFileWriter //dont forget to lookup 256 for the EOF marker, and write it out. //BitFileWriter will close the output file in its destructor //but you probably need to close your input file. }