This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (62 loc) · 1.94 KB
/
Copy pathmain.cpp
File metadata and controls
78 lines (62 loc) · 1.94 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
#include "B_plus_tree.h"
#include <iostream>
#include <cstring>
#include "snapshot.h"
class KEY {
public:
char key[65];
KEY(const char key_[]) { strcpy(key, key_); }
KEY() {}
bool operator<(const KEY &obj) const { return strcmp(key, obj.key) < 0; }
};
class VALUE {
public:
int value;
VALUE(int value_) { value = value_; }
VALUE() {}
bool operator<(const VALUE &obj) const { return value < obj.value; }
};
class find_operator {
public:
class VALUE find_value;
void find(VALUE find_value_) {
find_value = find_value_;
std::cout << find_value.value << ' ';
}
void not_find() { std::cout << "null"; }
void modify(VALUE &value) { find_value = value; }
};
const int MAX_SIZE = 4096 * 5;
int main() {
B_plus_snapshot_tree<KEY, VALUE, MAX_SIZE, find_operator> a("data", "ID", "father");
char tmp[64];
int value;
while (true) {
scanf("%s", tmp);
try {
if (strcmp("insert", tmp) == 0) {
scanf("%s%d", tmp, &value);
a.insert(KEY(tmp), VALUE{value});
} else if (strcmp("delete", tmp) == 0) {
scanf("%s%d", tmp, &value);
a.erase(KEY(tmp), VALUE{value});
} else if (strcmp("find", tmp) == 0) {
scanf("%s", tmp);
a.find(KEY(tmp));
std::cout << std::endl;
} else if (strcmp("create_snapshot", tmp) == 0) {
scanf("%s", tmp);
a.create_snapshot(tmp);
} else if (strcmp("erase_snapshot", tmp) == 0) {
scanf("%s", tmp);
a.erase_snapshot(tmp);
} else if (strcmp("restore_snapshot", tmp) == 0) {
scanf("%s", tmp);
a.restore_snapshot(tmp);
} else if (strcmp("exit", tmp) == 0) { break; }
} catch (exception &e) {
std::cout << e.what() << std::endl;
}
}
return 0;
}