-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage_node.h
More file actions
60 lines (51 loc) · 1.85 KB
/
storage_node.h
File metadata and controls
60 lines (51 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef STORAGE_NODE
#define STORAGE_NODE
#include <bits/stdc++.h>
using namespace std;
class StorageNode{
map<int, set<int> > dataPoints; // the collision is resolved by chaining, although duplicate dataPoints are not allowed
string nodeName;
string ip;
public:
StorageNode(string nodeName, string allotedIP){
this->nodeName = nodeName;
this->ip = allotedIP;
}
void printData(){
cout << "\t\tPrinting data in node " << nodeName << " : " << ip << endl;
for(map<int, set<int> >::iterator it=dataPoints.begin(); it!=dataPoints.end(); it++){
cout << "\t\t\tHash value: " << it->first << ", DataPoints: ";
for(set<int>::iterator it2=(it->second).begin(); it2!=(it->second).end(); it2++){
cout << (*it2) << " ";
}
cout << endl;
}
cout << endl;
}
void AddDataToNode(int hashValue, int data){
dataPoints[hashValue].insert(data);
cout << "Added data=" << data << " to node " << nodeName << endl;
return;
}
void RemoveDataFromNode(int hashValue, int data){
if(dataPoints.find(hashValue)==dataPoints.end())
cout << "Data=" << data << " not present in node " << nodeName << endl;
else {
dataPoints[hashValue].erase(data);
if(dataPoints[hashValue].size() == 0)
dataPoints.erase(hashValue);
cout << "Data=" << data << " removed from node " << nodeName << endl;
}
return;
}
map<int, set<int> > & GetDataPoints(){
return dataPoints;
}
string GetName(){
return nodeName;
}
string GetIp(){
return ip;
}
};
#endif