-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
72 lines (71 loc) · 1.53 KB
/
Copy pathmain.cpp
File metadata and controls
72 lines (71 loc) · 1.53 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
#include <iostream>
#include <cstring>
#include <ctime>
#include <iomanip>
#include "vector.hpp"
#include "BPlusTree.hpp"
void print_(sjtu::vector<int> & res) {
for (auto t = res.rbegin(); t != res.rend(); ++t) {
std::cout << *t << " ";
}
std::cout<<"\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
struct Key {
char key_[66] = {};
Key() {
memset(key_, 0, sizeof(key_));
}
Key(const char* key) {
std::strcpy(key_, key);
key_[strlen(key)] = '\0';
}
bool operator<(const Key &other) const {
return strcmp(key_, other.key_) < 0;
}
bool operator==(const Key &other) const {
return strcmp(key_, other.key_) == 0;
}
};
BPlusTree<int,Key,25> tree("data");
std::string op;
char key[66];
Key t;
sjtu::vector<int> res;
int n,tmp;
std::cin >> n;
for (int i = 1; i<= n; i++) {
std::cin >> op;
if (op[0] == 'i') {
std::cin >> key;
std::cin >> tmp;
tree.Insert(Key(key),tmp);
}
else if (op[0] == 'd') {
int tmp;
std::cin >> key >> tmp;
bool find = false;
if (tree.Remove(Key(key),tmp)) {
}
}
else if (op[0] == 'f') {
std::cin >> key;
bool find = false;
res = tree.Search(Key(key), find);
if (find) {
print_(res);
}
else {
std::cout << "null\n";
}
}else if (op == "update"){
int tmp;
std::cin >> key ;
std::cin >> tmp;
std::cout << tree.Update(Key(key), tmp) <<"\n";
}
}
return 0;
}