-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
159 lines (156 loc) · 6.41 KB
/
main.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
#include"RingDHT.h"
using namespace std;
int main()
{
int IdentifierSpaceBit, Machine, chioce;
bool Con1 = true;
char Con2;
cout << "___________________________________________________" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "###################################################" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "% Distributed Hash Table Search %" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "###################################################" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "___________________________________________________" << endl;
cout << "Specify the number of Bit in Identifer Space ::";
cin >> IdentifierSpaceBit;
cout << "Enter the number of machine in the Space ::";
cin >> Machine;
cout << "___________________________________________________" << endl;
cout << "Press(Any-Key) to Assign ID Manually to Machines\n";
cout << "Press(0) to Assign ID for Automically Assignment\n";
cout << "___________________________________________________" << endl;
cin >> Con2;
cout << "___________________________________________________" << endl;
bool valid;
Con2 == '0' ? valid = false : valid = true;
DHT<string> obj(Machine, IdentifierSpaceBit, valid);
do
{
cout << "___________________________________________________" << endl;
cout << " Choice the desired Option from the Manu Given " << endl;
cout << "___________________________________________________" << endl;
cout << "1- Press Option(1) to Add the key Value Pair" << endl;
cout << "2- Press Option(2) to Delete a value from a Machine" << endl;
cout << "3- Press Option(3) to Display the IDS in the DHT" << endl;
cout << "4- Press Option(4) to Print the Rounting table " << endl;
cout << "5- Press Option(5) to Print the AVL tree Maintained" << endl;
cout << "6- Press Option(6) to Add new machine to the System" << endl;
cout << "7- Press Option(7) to delete a machine from System" << endl;
cout << "8- Press Option(8) to Search a Value Using Key" << endl;
cout << "9- Press Option(9) to delete machines and terminate" << endl;
cout << "___________________________________________________" << endl;
cin >> chioce;
cout << "___________________________________________________" << endl;
switch (chioce)
{
case 1:
{
int ID;
string key;
string value;
cout << "###################################################" << endl;
cout << "Enter the Machine ID form insertion take place::";
cin >> ID;
cout << "Enter the Key to Insert on the Machine::";
cin >> key;
cout << "Enter the Value to Insert on the Machine::";
cin >> value;
cout << "###################################################" << endl;
obj.InsertKeyValuePair(ID, key, value);
cout << "###################################################" << endl;
break;
}
case 2:
{
int MId;
string key;
cout << "###################################################" << endl;
cout << "Enter Machine-ID from where Deletion Takes Place ::";
cin >> MId;
cout << "Enter the key to be removed from the System ::";
cin >> key;
obj.deleteValue(MId, key);
cout << "###################################################" << endl;
break;
}
case 3:
{
cout << "###################################################" << endl;
obj.Display();
cout << "###################################################" << endl;
break;
}
case 4:
{
int mn;
cout << "###################################################" << endl;
cout << "Enter machine ID whose Routing table to be Printed :: ";
cin >> mn;
obj.displayRoutingTable(mn);
cout << "###################################################" << endl;
break;
}
case 5:
{
int mn;
cout << "###################################################" << endl;
cout << "Enter Machine-ID whose AVL you want to Printed::";
cin >> mn;
obj.displayAVLTree(mn);
cout << "###################################################" << endl;
break;
}
case 6:
{
int mId;
cout << "###################################################" << endl;
cout << "Enter Machine ID, which you want to Insert :: ";
cin >> mId;
obj.InsertMachine(mId);
cout << "###################################################" << endl;
break;
}
case 7:
{
int mn;
cout << "###################################################" << endl;
cout << "Enter Machine ID, Which you want to delete :: ";
cin >> mn;
obj.DeleteMachine(mn);
cout << "###################################################" << endl;
break;
}
case 8:
{
string k;
int mID;
cout << "###################################################" << endl;
cout << "Enter Key you wanted to search in DHT Ring ::";
cin >> k;
cout << "Enter the machine ID from where you want Search::";
cin >> mID;
obj.searchNode(k, mID);
cout << "###################################################" << endl;
break;
}
case 9:
{
//The destructor will be atumatically called on return 0 call
return 0;
}
default:
{
cout << "Enter the Correct Choice from the Given Manu" << endl;
cout << "___________________________________________________" << endl;
}
}
} while (true);
return 0;
}