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

seek dictionary workss !!!

parent 5ae3d6b1
No related branches found
No related tags found
No related merge requests found
......@@ -68,16 +68,33 @@ void Indexer::save() {
write(file, numberWords.c_str(), strlen(numberWords.c_str()));
write(file, numberDocs.c_str(), strlen(numberDocs.c_str()));
write(file, footer.c_str(), strlen(footer.c_str()));
// REALLY GROSS HACK
int seekOffset = strlen(header.c_str()) +
strlen(numberDocs.c_str()) +
strlen(numberWords.c_str()) +
strlen(uniqueWords.c_str()) +
strlen(footer.c_str());
bool first = true;
for(auto word : maps) {
if(first) { //REALLY BAD HACKK
first = false;
seeker[word.first] = seekOffset;
} else {
seeker[word.first] = seekOffset;
}
string wordBreak = word.first + "\n";
write(file, wordBreak.c_str(), strlen(wordBreak.c_str()));
seekOffset += strlen(wordBreak.c_str());
for(auto location : word.second) {
string locationSpace = to_string(location) + " ";
write(file, locationSpace.c_str(), strlen(locationSpace.c_str()));
seekOffset += strlen(locationSpace.c_str());
}
seeker[word.first] = 013;
write(file, "\n", 1);
seekOffset += 1;
}
string docEndingHeader = "===Document Endings===\n";
......
......@@ -39,6 +39,7 @@ class Indexer {
void reset();
unordered_map<string, vector<size_t> > masterDictionary;
map<string, size_t> seekDictionary;
unordered_map<string, vector<size_t> > lastOne;
vector<DocumentEnding> docEndings;
......
......@@ -9,12 +9,13 @@
using namespace std;
int main() {
int index1 = open("index0.txt", O_CREAT|O_WRONLY, S_IRWXU);
lseek(index1, 25, SEEK_SET);
string fs = "hello";
if(write(index1, fs.c_str(), strlen(fs.c_str())) != strlen(fs.c_str())) {
int index1 = open("index0.txt", O_CREAT|O_RDWR, S_IRWXU);
lseek(index1, 129545, SEEK_SET);
char buffer[10];
if(read(index1, buffer, 20) != 20) {
cout << "ERROR" << endl;
}
cout << buffer << endl;
close(index1);
return 0;
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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