MCPcopy Create free account
hub / github.com/Tencent/phxqueue / main

Function main

phxqueue/test/test_consistent_hash_main.cpp:21–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19using namespace std;
20
21int main(int argc, char **argv) {
22
23 comm::utils::ConsistenHash<int, int> consisten_hash;
24
25 std::list<comm::utils::ConsistenHash<int, int>::NodeScale> node_scale_list;
26 node_scale_list.push_back(std::pair<int, int>(1, 10));
27 node_scale_list.push_back(std::pair<int, int>(2, 10));
28
29 bool ret;
30 ret = consisten_hash.Init(node_scale_list,
31 [](const int &key)->uint64_t {
32 uint64_t h = 0;
33 h = comm::utils::MurmurHash64(&key, sizeof(int), h);
34 return h;
35 },
36 [](const int &node, int scale)->uint64_t {
37 uint64_t h = 0;
38 h = comm::utils::MurmurHash64(&node, sizeof(int), h);
39 h = comm::utils::MurmurHash64(&scale, sizeof(int), h);
40 return h;
41 });
42 printf("Init ret %d\n", ret);
43
44
45 for (int i{0}; i < 100; ++i) {
46 int key = 5564925 + i;
47 int node = 0;
48 ret = consisten_hash.PickNodeByKey(key, node);
49 printf("i %d ret %d node %d\n", i, ret, node);
50 }
51 return 0;
52}
53

Callers

nothing calls this directly

Calls 3

MurmurHash64Function · 0.85
PickNodeByKeyMethod · 0.80
InitMethod · 0.45

Tested by

no test coverage detected