-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample.cc
More file actions
45 lines (42 loc) · 1.07 KB
/
sample.cc
File metadata and controls
45 lines (42 loc) · 1.07 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
// Copyright (c) 2017 Mirants Lu. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdio.h>
#include <iostream>
#include "conhash.h"
int main() {
ConHash conhash;
Node n1("spanner", 12);
Node n2("bigtable", 16);
Node n3("mapreduce", 14);
Node n4("chubby", 15);
Node n5("gfs", 10);
conhash.AddNode(n1);
conhash.AddNode(n2);
conhash.AddNode(n3);
conhash.AddNode(n4);
conhash.AddNode(n5);
for (int i = 0; i < 20; ++i) {
char buf[32];
snprintf(buf, sizeof(buf), "megastore#%d", i);
Node node;
if (conhash.Lookup(buf, &node)) {
std::cout << node.identify << std::endl;
} else {
std::cout << "No server" << std::endl;
}
}
std::cout << "\n";
conhash.RemoveNode(n3);
for (int i = 0; i < 20; ++i) {
char buf[32];
snprintf(buf, sizeof(buf), "megastore#%d", i);
Node node;
if (conhash.Lookup(buf, &node)) {
std::cout << node.identify << std::endl;
} else {
std::cout << "No server" << std::endl;
}
}
return 0;
}