-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (76 loc) · 2.2 KB
/
main.cpp
File metadata and controls
79 lines (76 loc) · 2.2 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <set>
#include "LsmTree.h"
void checkOperations(LsmTree& db, int CountOfTest) {
std::string value = "Some text", key = db.insert(value);
std::vector<std::string> keys;
keys.push_back(key);
for(int i = 0; i < CountOfTest; i++) {
key = db.insert(value);
keys.push_back(key);
}
for(auto& it : keys)
if(db.get(it).empty()) {
std::cout << "Fail get " << it << "\n";
db.get(it);
}
value = "other text";
for(auto& it : keys)
db.update(it, value);
for(auto& it : keys)
if(db.get(it) != value)
std::cout << "Fail update " << it << "\n";
for(auto& it : keys)
db.erase(it);
for(auto& it : keys)
if(!db.get(it).empty())
std::cout << "Fail erase " << it << "\n";
}
void interactive(LsmTree& db) {
std::cout << "Comands:\n";
std::cout << "add [enter] value //return key\n";
std::cout << "get key // return value for key\n";
std::cout << "update key [enter] value\n";
std::cout << "erase key\n";
std::cout << "stop\n";
while(1) {
std::string command;
std::cin >> command;
if(command == "add") {
std::string value;
getline(std::cin, value);
getline(std::cin, value);
std::cout << "Key = " << db.insert(value) << "\n";
}
else if(command == "get") {
std::string key;
std::cin >> key;
if(db.get(key).empty())
std::cout << "No " << key << " in tree\n";
else
std::cout << "Value = " << db.get(key) << "\n";
}
else if(command == "update") {
std::string key, value;
std::cin >> key;
getline(std::cin, value);
getline(std::cin, value);
db.update(key, value);
}
else if(command == "erase") {
std::string key;
std::cin >> key;
db.erase(key);
}
else if(command == "stop")
break;
else
std::cout << "Bad command\n";
}
}
int main() {
LsmTree db;
// checkOperations(db, 1000);
interactive(db);
return 0;
}