-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsistentHashRing.h
More file actions
38 lines (31 loc) · 890 Bytes
/
ConsistentHashRing.h
File metadata and controls
38 lines (31 loc) · 890 Bytes
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
#ifndef RING_H
#define RING_H
#include <map>
#include <unordered_map>
#include <mutex>
#include <vector>
#include "Node.h"
using namespace std;
class ConsistentHashRing {
private:
map<int, Node> nodeRing;
unordered_map<string, Node> nodesHashTable;
Node selfNode;
mutable std::mutex mtx;
public:
ConsistentHashRing();
void addNode(Node node);
void removeNode(Node node);
Node getPrimaryNodeForFile(int hash);
Node getNode(int hash);
Node getNode(string nodeId);
Node getSelfNode();
// overload << operator
friend ostream& operator<<(ostream& os, const ConsistentHashRing& ring);
bool isPredecessor(string nodeId);
vector<int> getKPredecessors(int k);
vector<int> getListOfNodes();
vector<int> getKSuccessorsOf(int k, int hash);
};
ostream& operator<<(ostream& os, const ConsistentHashRing& ring);
#endif // RING_H