Skip to content
Snippets Groups Projects
Commit 435e1584 authored by Nicholas Yang's avatar Nicholas Yang
Browse files

more simplified implementation

parent 321f73d2
No related branches found
No related tags found
1 merge request!1Add makefile for everyone and tests for the indexer
#include "Indexer.h"
Indexer::Indexer() {
indexedCount = 0;
currentFile = 0;
}
void Indexer::run() {
while(pointerToDictionaries.Size() != 0) {
unordered_map<string, vector<int>>* dictionary = pointerToDictionaries.Pop();
for(auto it : *dictionary) {
for(auto location : it.second) {
cout << location << endl;
if(indexedCount > 50000000) {
save();
reset();
}
unordered_map<string, vector<int>> dictionary = *pointerToDictionaries.Pop();
for(auto word : dictionary) {
for(auto location : word.second) {
indexedCount++;
masterDictionary[word.first].push_back(location);
}
}
}
}
\ No newline at end of file
save();
}
void Indexer::save() {
map<string, vector<int> > maps(masterDictionary.begin(), masterDictionary.end());
ofstream file("index" + to_string(currentFile) + ".txt");
for(auto word : maps) {
file << word.first << endl;
for(auto location : word.second) {
file << location << " ";
}
file << endl;
}
file.close();
currentFile++;
}
void Indexer::reset() {
masterDictionary.clear();
indexedCount = 0;
}
#include "../ProducerConsumerQueue.h"
#include "../ProducerConsumerQueue.cpp"
#include <unordered_map>
#include <map>
#include <vector>
#include <iostream>
#include <fstream>
/*
......@@ -18,5 +20,10 @@ class Indexer {
Indexer();
void run();
ProducerConsumerQueue<unordered_map<string, vector<int> >*> pointerToDictionaries;
private:
private:
void save();
void reset();
unordered_map<string, vector<int> > masterDictionary;
size_t indexedCount;
size_t currentFile;
};
\ No newline at end of file
......@@ -12,7 +12,9 @@ int main() {
Indexer indexer = Indexer();
unordered_map<string, vector<int>> test1;
test1["cat"] = { 12, 15, 17 };
test1["whale"] = { 3, 6, 12 };
test1["dog"] = { 1, 5, 15 };
test1["agouti"] = {2, 8, 41 };
indexer.pointerToDictionaries.Push(&test1);
indexer.run();
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment