-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmy_hash.h
More file actions
65 lines (44 loc) · 1.23 KB
/
my_hash.h
File metadata and controls
65 lines (44 loc) · 1.23 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
61
62
63
64
65
#ifndef LEETCODE_MY_HASH_H
#define LEETCODE_MY_HASH_H
#include <string>
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
class virtual_node {
public:
string ip;
unsigned int hash_value;
map<unsigned int, string> data;
virtual_node();
virtual_node(string ip, unsigned int hash_value);
~virtual_node();
};
class real_node {
public:
string ip;
unsigned int virtual_node_num;
vector<unsigned int> virtual_node_hash_list;
unsigned int cur_max_port;
real_node();
real_node(string ip);
~real_node();
};
class consistent_hash {
public:
unsigned int real_node_sum;
unsigned int virtual_node_sum;
map<string, real_node> real_node_map;
map<unsigned int, virtual_node> virtual_node_map;
vector<unsigned int> sorted_node_hash_list;
consistent_hash();
~consistent_hash();
unsigned int find_nearest_node(unsigned int hash_value);
unsigned int put(string data_id);
void add_real_node(string ip, unsigned int virtual_node_num);
void drop_real_node(string ip);
void print_real_node(string ip);
void print();
};
#endif //LEETCODE_MY_HASH_H