diff --git a/indexer/Indexer.cpp b/indexer/Indexer.cpp index 25f59c054d130e252d6b6ac0d77e624ec1973e57..1f4cbd42383b23ddfa24c37bf119d8f34701d721 100644 --- a/indexer/Indexer.cpp +++ b/indexer/Indexer.cpp @@ -11,8 +11,8 @@ void Indexer::run() { save(); reset(); } - unordered_map<string, vector<int>> dictionary = *pointerToDictionaries.Pop(); - for(auto word : dictionary) { + unordered_map<string, vector<int>>* dictionary = pointerToDictionaries.Pop(); + for(auto word : *dictionary) { for(auto location : word.second) { indexedCount++; masterDictionary[word.first].push_back(location); @@ -23,15 +23,18 @@ void Indexer::run() { void Indexer::save() { map<string, vector<int> > maps(masterDictionary.begin(), masterDictionary.end()); - ofstream file("index" + to_string(currentFile) + ".txt"); + string fileName = "index" + to_string(currentFile) + ".txt"; + int file = open(fileName.c_str(), O_CREAT | O_WRONLY, S_IRWXU); for(auto word : maps) { - file << word.first << endl; + string wordBreak = word.first + "\n"; + write(file, wordBreak.c_str(), strlen(wordBreak.c_str())); for(auto location : word.second) { - file << location << " "; + string locationSpace = to_string(location) + " "; + write(file, locationSpace.c_str(), strlen(locationSpace.c_str())); } - file << endl; + write(file, "\n", 1); } - file.close(); + close(file); currentFile++; } diff --git a/indexer/Indexer.h b/indexer/Indexer.h index b40b48f3fc89835ae19ffb3db5ba5a2a16308399..7b0c74883a4b5337fcd039f3b97d82227b8806d3 100644 --- a/indexer/Indexer.h +++ b/indexer/Indexer.h @@ -5,6 +5,8 @@ #include <vector> #include <iostream> #include <fstream> +#include <fcntl.h> +#include <unistd.h> /*