diff --git a/bpt/include/bpt/bpt.hpp b/bpt/include/bpt/bpt.hpp index b4d35e4..671e51d 100644 --- a/bpt/include/bpt/bpt.hpp +++ b/bpt/include/bpt/bpt.hpp @@ -1,12 +1,9 @@ #ifndef BPT_HPP #define BPT_HPP -#include #include -#include #include -#include #include -#include +#include "vector.hpp" #include "bpt/bpt_page.hpp" #include "bpt/buffer_pool_manager.h" #include "bpt/config.h" @@ -25,7 +22,7 @@ class BPlusTreeIndexer { private: struct PositionSignType { - std::vector> path; + sjtu::vector> path; bool is_end{false}; }; PositionSignType FindPosition(const KeyType &key) { // Finish Design diff --git a/bpt/include/bpt/buffer_pool_manager.h b/bpt/include/bpt/buffer_pool_manager.h index 715825c..24703e6 100644 --- a/bpt/include/bpt/buffer_pool_manager.h +++ b/bpt/include/bpt/buffer_pool_manager.h @@ -1,11 +1,11 @@ #ifndef BUFFER_POOL_MANAGER_H #define BUFFER_POOL_MANAGER_H #include -#include #include #include #include -#include +#include "map.hpp" +#include "list.hpp" #include "bpt/config.h" #include "bpt/disk_manager.h" #include "bpt/replacer.h" @@ -395,7 +395,7 @@ class BufferPoolManager { std::mutex latch; #endif Page *pages_; - std::unordered_map page_table_; - std::list free_list_; + sjtu::map page_table_; + sjtu::list free_list_; }; #endif \ No newline at end of file diff --git a/bpt/src/buffer_pool_manager.cpp b/bpt/src/buffer_pool_manager.cpp index f24b4ad..3ff02b0 100644 --- a/bpt/src/buffer_pool_manager.cpp +++ b/bpt/src/buffer_pool_manager.cpp @@ -102,7 +102,7 @@ BufferPoolManager::BufferPoolManager(size_t pool_size, size_t replacer_k, DiskMa // Initially, every page is in the free list. for (size_t i = 0; i < pool_size; ++i) { - free_list_.emplace_back(static_cast(i)); + free_list_.push_back(static_cast(i)); } } BufferPoolManager::~BufferPoolManager() { diff --git a/stlite/map.hpp b/stlite/map.hpp index 59366a0..1856d15 100644 --- a/stlite/map.hpp +++ b/stlite/map.hpp @@ -711,6 +711,12 @@ class map { RedBlackTreeNodeType::DeleteNode(pos.raw_pointer, tree_root); --node_count; } + void erase(const Key &key) { + RedBlackTreeNodeType *result = tree_root->Find(key); + if (result == nullptr) return; + RedBlackTreeNodeType::DeleteNode(result, tree_root); + --node_count; + } /** * Returns the number of elements with key * that compares equivalent to the specified argument, diff --git a/stlite/vector.hpp b/stlite/vector.hpp index be66fbf..23e32f9 100644 --- a/stlite/vector.hpp +++ b/stlite/vector.hpp @@ -339,7 +339,7 @@ class vector { * access the last element. * throw container_is_empty if size == 0 */ - const T &back() const { + T &back() const { if (current_length == 0) [[unlikely]] throw container_is_empty(); return raw_end[-1]; @@ -494,7 +494,7 @@ class vector { /** * adds an element to the end. */ - void push_back(const T &value) { + void push_back(T value) { if (current_length == allocated_length) [[unlikely]] { size_t new_allocated_length = allocated_length * 2; T *new_raw_beg = alloc.allocate(new_allocated_length); @@ -507,7 +507,7 @@ class vector { raw_end = raw_beg + current_length; allocated_length = new_allocated_length; } - std::allocator_traits::construct(alloc, raw_end, value); + std::allocator_traits::construct(alloc, raw_end, std::move(value)); raw_end++; current_length++; }