From 6bf9fa1ded9bc149c0606c6d9b25d5be29454357 Mon Sep 17 00:00:00 2001
From: Nicholas Yang <parablank@gmail.com>
Date: Tue, 13 Feb 2018 18:17:44 -0500
Subject: [PATCH] non stl writing to blocks

---
 indexer/Indexer.cpp | 17 ++++++++++-------
 indexer/Indexer.h   |  2 ++
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/indexer/Indexer.cpp b/indexer/Indexer.cpp
index 25f59c0..1f4cbd4 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 b40b48f..7b0c748 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>
 
 /*
 
-- 
GitLab