1extern crate hash_ring;
2
3use hash_ring::HashRing;
4use hash_ring::NodeInfo;
5
6fn main() {
7 let mut nodes: Vec<NodeInfo> = Vec::new();
8 nodes.push(NodeInfo {
9 host: "localhost",
10 port: 15324,
11 });
12 nodes.push(NodeInfo {
13 host: "localhost",
14 port: 15325,
15 });
16 nodes.push(NodeInfo {
17 host: "localhost",
18 port: 15326,
19 });
20 nodes.push(NodeInfo {
21 host: "localhost",
22 port: 15327,
23 });
24 nodes.push(NodeInfo {
25 host: "localhost",
26 port: 15328,
27 });
28 nodes.push(NodeInfo {
29 host: "localhost",
30 port: 15329,
31 });
32
33 let mut hash_ring: HashRing<NodeInfo> = HashRing::new(nodes, 10);
34
35 println!(
36 "Key: '{}', Node: {}",
37 "hello",
38 hash_ring.get_node(("hello").to_string()).unwrap()
39 );
40
41 println!(
42 "Key: '{}', Node: {}",
43 "dude",
44 hash_ring.get_node(("dude").to_string()).unwrap()
45 );
46
47 println!(
48 "Key: '{}', Node: {}",
49 "martian",
50 hash_ring.get_node(("martian").to_string()).unwrap()
51 );
52
53 println!(
54 "Key: '{}', Node: {}",
55 "tardis",
56 hash_ring.get_node(("tardis").to_string()).unwrap()
57 );
58
59 hash_ring.remove_node(&NodeInfo {
60 host: "localhost",
61 port: 15329,
62 });
63
64 println!(
65 "Key: '{}', Node: {}",
66 "hello",
67 hash_ring.get_node(("hello").to_string()).unwrap()
68 );
69
70 hash_ring.add_node(&NodeInfo {
71 host: "localhost",
72 port: 15329,
73 });
74
75 println!(
76 "Key: '{}', Node: {}",
77 "hello",
78 hash_ring.get_node(("hello").to_string()).unwrap()
79 );
80}