Commit 503288eb authored by Vishal Saha's avatar Vishal Saha

implemented , on sharing of keys cache keys from old server deleted

parent 27fec107
...@@ -330,6 +330,10 @@ public: ...@@ -330,6 +330,10 @@ public:
cout << endl; cout << endl;
} }
int hash(string s)
{
return (((int)s.at(0)) << 8) + ((int)s.at(1));
}
string getKeyValuePairs(int id) string getKeyValuePairs(int id)
{ {
unordered_map<string, string> flush; unordered_map<string, string> flush;
...@@ -379,14 +383,20 @@ public: ...@@ -379,14 +383,20 @@ public:
closedir(dirFile); closedir(dirFile);
} }
Node *temp = head->next; vector<string> toBeDeleted;
while (temp->next)
for (int i = 0; i <= curr_pos; i++)
{ {
if (hash(temp->key) <= id) if (hash(cacheHeap[i]->key) <= id)
{ {
flush[temp->key] = temp->payload; toBeDeleted.push_back(cacheHeap[i]->key);
flush[cacheHeap[i]->key] = cacheHeap[i]->value;
} }
temp = temp->next; }
for (string key : toBeDeleted)
{
this->deleteNodeByKey(key);
} }
unordered_map<string, string>::iterator itr; unordered_map<string, string>::iterator itr;
......
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