Commit 68222a12 authored by Mayank Manoj's avatar Mayank Manoj

Merge branch 'mayank' into 'master'

final. running perfectly

See merge request !9
parents afb42e10 36a3cde3
......@@ -26,7 +26,7 @@ public:
{
return;
}
virtual string getKeyValuePairs(int new_id,int id)
virtual string getKeyValuePairs(int new_id,int id,int pred_id)
{
return "This will never run";
}
......@@ -75,9 +75,9 @@ public:
mycache.pushAll();
}
string getKeyValuePairs(int new_id,int id)
string getKeyValuePairs(int new_id,int id,int pred_id)
{
return mycache.getKeyValuePairs(new_id,id);
return mycache.getKeyValuePairs(new_id,id,pred_id);
}
};
......@@ -124,8 +124,8 @@ public:
}
// key1;key2;key3;;value1;value2;value3;
string getKeyValuePairs(int new_id,int id)
string getKeyValuePairs(int new_id,int id,int pred_id)
{
return mycache.getKeyValuePairs(new_id,id);
return mycache.getKeyValuePairs(new_id,id,pred_id);
}
};
\ No newline at end of file
......@@ -334,7 +334,7 @@ public:
{
return (((int)s.at(0)) << 8) + ((int)s.at(1));
}
string getKeyValuePairs(int newId, int id)
string getKeyValuePairs(int newId, int id,int pred_id)
{
unordered_map<string, string> flush;
string keyValPairs = "";
......@@ -353,7 +353,34 @@ public:
{
fileName.erase(n - 4);
fileName = fileName.substr(2);
if (hash(fileName) <= newId || hash(fileName) > id)
if (newId > id) { //wrapAround
if(hash(fileName) <=newId&&hash(fileName)>id) {
ifstream fin;
fin.open(fName);
string _key, val;
do {
getline(fin, _key);
if(_key.size() == 0)
break;
getline(fin, val);
if (val != deleted)
flush[_key] = val;
else
flush.erase(_key);
if (fin.eof())
break;
} while (fin);
fin.close();
const char *c = fName.c_str();
remove(c);
}
}
else {
if (hash(fileName) <= newId||(pred_id>id&&hash(fileName)>pred_id))
{
ifstream fin;
fin.open(fName);
......@@ -380,6 +407,7 @@ public:
}
}
}
}
closedir(dirFile);
}
......@@ -387,7 +415,7 @@ public:
for (int i = 0; i <= curr_pos; i++)
{
if (hash(cacheHeap[i]->key) <= newId || hash(cacheHeap[i]->key) > id)
if ((newId>id&&hash(cacheHeap[i]->key)<=newId&&hash(cacheHeap[i]->key)>id)||(newId<id&&hash(cacheHeap[i]->key)<=newId)||(pred_id>id&&hash(cacheHeap[i]->key)>pred_id))
{
toBeDeleted.push_back(cacheHeap[i]->key);
flush[cacheHeap[i]->key] = cacheHeap[i]->value;
......
......@@ -126,19 +126,21 @@ public:
} while (fin);
fin.close();
unordered_map<string, string>::iterator itr;
for (itr = flush.begin(); itr != flush.end() && cache.size() < capacity - 1; itr++)
{
this->put(itr->first, itr->second);
flush[itr->first] = deleted;
}
if (flush.find(key) != flush.end())
{
this->put(key, flush[key]);
flush[key] = deleted;
}
unordered_map<string, string>::iterator itr;
for (itr = flush.begin(); itr != flush.end() && cache.size() < capacity; itr++)
{
if (itr->second == deleted)
continue;
this->put(itr->first, itr->second);
flush[itr->first] = deleted;
}
const char *c = fileName.c_str();
remove(c);
......@@ -263,7 +265,7 @@ public:
}
// key1;key2;key3;;value1;value2;value3;
string getKeyValuePairs(int newId, int id)
string getKeyValuePairs(int newId, int id,int pred_id)
{
unordered_map<string, string> flush;
string keyValPairs = "";
......@@ -282,7 +284,34 @@ public:
{
fileName.erase(n - 4);
fileName = fileName.substr(2);
if (hash(fileName) <= newId && hash(fileName) > id)
if (newId > id) { //wrapAround
if(hash(fileName) <=newId&&hash(fileName)>id) {
ifstream fin;
fin.open(fName);
string _key, val;
do {
getline(fin, _key);
if(_key.size() == 0)
break;
getline(fin, val);
if (val != deleted)
flush[_key] = val;
else
flush.erase(_key);
if (fin.eof())
break;
} while (fin);
fin.close();
const char *c = fName.c_str();
remove(c);
}
}
else {
if (hash(fileName) <= newId||(pred_id>id&&hash(fileName)>pred_id))
{
ifstream fin;
fin.open(fName);
......@@ -309,13 +338,14 @@ public:
}
}
}
}
closedir(dirFile);
}
Node *temp = head->next;
while (temp->next)
{
if (hash(temp->key) <= newId && hash(temp->key) > id)
if ((newId>id&&hash(temp->key)<=newId&&hash(temp->key)>id)||((hash(temp->key)<=newId&&newId<id)||(pred_id>id&&hash(temp->key)>pred_id)))
{
flush[temp->key] = temp->payload;
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment