Commit 118641b9 authored by Vishal Saha's avatar Vishal Saha

modified LRU.h for wrap around

parent afb42e10
......@@ -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);
......@@ -282,30 +284,58 @@ public:
{
fileName.erase(n - 4);
fileName = fileName.substr(2);
if (hash(fileName) <= newId && hash(fileName) > id)
{
ifstream fin;
fin.open(fName);
string _key, val;
do
if (newId > id) { //wrapAround
if(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)
{
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);
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);
}
}
}
}
......
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