#include #include #include #include #include #include "storage/bpt.hpp" #include "storage/buffer_pool_manager.h" typedef uint64_t hash_t; inline hash_t Hash(std::string str) noexcept { constexpr static char salt1[10] = "mL;]-=eT"; constexpr static char salt2[10] = "9B(str.c_str() + i); ret ^= *reinterpret_cast(inner_salt + (i & 15)); ret += 0x9e3779b97f4a7c15; ret = (ret ^ (ret >> 30)) * 0xbf58476d1ce4e5b9; ret = (ret ^ (ret >> 27)) * 0x94d049bb133111eb; ret ^= ret >> 31; } for (; i < str.length(); ++i) { ret ^= str[i]; ret ^= inner_salt[i & 15]; ret += 0x9e3779b97f4a7c15; ret = (ret ^ (ret >> 30)) * 0xbf58476d1ce4e5b9; ret = (ret ^ (ret >> 27)) * 0x94d049bb133111eb; ret ^= ret >> 31; } return ret; } typedef std::pair ValType; const int kIntMin = std::numeric_limits::min(); int main() { DiskManager *disk_manager = new DiskManager("data.db"); BufferPoolManager *buffer_pool_manager = new BufferPoolManager(100, 10, disk_manager); { BPlusTreeIndexer> bpt(buffer_pool_manager); int n; // freopen("/workspaces/BH-TicketSystem/build/pro.in", "r", stdin); // freopen("/workspaces/BH-TicketSystem/build/pro.out", "w", stdout); std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); std::string op, index; int val; std::cin >> n; int opt_cnt = 0; while (n-- > 0) { ++opt_cnt; std::cin >> op; if (op[0] == 'i') { std::cin >> index >> val; hash_t hsh = Hash(index); bpt.Put({hsh, val}, 1); } else if (op[0] == 'd') { std::cin >> index >> val; hash_t hsh = Hash(index); bpt.Remove({hsh, val}); } else if (op[0] == 'f') { std::cin >> index; hash_t hsh = Hash(index); ValType marker = {hsh, kIntMin}; auto it = bpt.lower_bound_const(marker); bool has_value = false; while (true) { if (it == bpt.end_const()) break; if (it.GetKey().first != hsh) break; has_value = true; std::cout << it.GetKey().second << ' '; ++it; } if (!has_value) std::cout << "null"; std::cout << '\n'; } else throw std::runtime_error("Invalid operation"); // if (opt_cnt >= 133768) { // bpt.CheckIndex(); // } } } delete buffer_pool_manager; delete disk_manager; return 0; }