replaced illegal STL

This commit is contained in:
2024-05-01 03:08:31 +00:00
parent 27ed3f9a55
commit 6c20530cc8
5 changed files with 16 additions and 13 deletions

View File

@ -1,12 +1,9 @@
#ifndef BPT_HPP
#define BPT_HPP
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <queue>
#include <shared_mutex>
#include <vector>
#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<std::pair<BasicPageGuard, in_page_key_count_t>> path;
sjtu::vector<std::pair<BasicPageGuard, in_page_key_count_t>> path;
bool is_end{false};
};
PositionSignType FindPosition(const KeyType &key) { // Finish Design

View File

@ -1,11 +1,11 @@
#ifndef BUFFER_POOL_MANAGER_H
#define BUFFER_POOL_MANAGER_H
#include <cstddef>
#include <list>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <unordered_map>
#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_id_t, frame_id_t> page_table_;
std::list<frame_id_t> free_list_;
sjtu::map<page_id_t, frame_id_t> page_table_;
sjtu::list<frame_id_t> free_list_;
};
#endif

View File

@ -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<int>(i));
free_list_.push_back(static_cast<frame_id_t>(i));
}
}
BufferPoolManager::~BufferPoolManager() {

View File

@ -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,

View File

@ -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<decltype(alloc)>::construct(alloc, raw_end, value);
std::allocator_traits<decltype(alloc)>::construct(alloc, raw_end, std::move(value));
raw_end++;
current_length++;
}