-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
114 lines (105 loc) · 3.66 KB
/
main.cpp
File metadata and controls
114 lines (105 loc) · 3.66 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
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
#include <iostream>
#include "bplustree.hpp"
#include "record.hpp"
void displayMenu() {
std::cout << "\n\n*****************************************" << std::endl;
std::cout << " B+ TREE MENU " << std::endl;
std::cout << "*****************************************" << std::endl;
std::cout << "[1] Insert" << std::endl;
std::cout << "[2] Key Search" << std::endl;
std::cout << "[3] Range Search" << std::endl;
std::cout << "[4] Above-Key Search" << std::endl;
std::cout << "[5] Below-Key Search" << std::endl;
std::cout << "[6] Remove" << std::endl;
std::cout << "[0] Exit" << std::endl;
std::cout << "*****************************************" << std::endl;
std::cout << "Enter your choice: ";
}
auto main() -> int {
int choice;
const Property props(
"./index/record/",
"metadata_index_by_id_1",
"index_by_id_1",
get_expected_index_page_capacity<std::int32_t>(),
get_expected_data_page_capacity<Record>(),
true
);
const std::function<std::int32_t(Record &)> index_by_id = [](Record &record) -> std::int32_t {
return record.id;
};
BPlusTree<std::int32_t, Record> bPlusTree(props, index_by_id);
do {
displayMenu();
std::cin >> choice;
switch (choice) {
case 1: {
Record record;
std::cout << "Enter record to insert: ";
std::cin >> record;
std::cout << "Read record: " << record;
bPlusTree.insert(record);
break;
}
case 2: {
int key;
std::cout << "Enter key to search: ";
std::cin >> key;
std::vector<Record> recovered = bPlusTree.search(key);
for (Record &record: recovered) {
std::cout << record << "\n";
}
break;
}
case 3: {
int l, u;
std::cout << "Enter lower bound: ";
std::cin >> l;
std::cout << "Enter upper bound: ";
std::cin >> u;
std::vector<Record> recovered = bPlusTree.between(l, u);
std::cout << "Recovered records:\n";
for (Record &record: recovered) {
std::cout << record << "\n";
}
break;
}
case 4: {
int key;
std::cout << "Enter lower bound: ";
std::cin >> key;
std::vector<Record> recovered = bPlusTree.above(key);
for (Record &record: recovered) {
std::cout << record << "\n";
}
break;
}
case 5: {
int key;
std::cout << "Enter upper bound: ";
std::cin >> key;
std::vector<Record> recovered = bPlusTree.below(key);
for (Record &record: recovered) {
std::cout << record << "\n";
}
break;
}
case 6: {
int key;
std::cout << "Enter key to remove: ";
std::cin >> key;
bPlusTree.remove(key);
break;
}
case 0: {
std::cout << "Exiting the program." << std::endl;
break;
}
default: {
std::cout << "Invalid choice. Please enter a valid option." << std::endl;
break;
}
}
} while (choice != 0);
return 0;
}