File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ static constexpr int HEADER_PAGE_ID = 0; // the header page id
3737static constexpr int PAGE_SIZE = 4096 ; // size of a data page in byte 4KB
3838static constexpr int BUFFER_POOL_SIZE = 1024 * 256 / 8 ; // size of buffer pool 256MB
3939// static constexpr int BUFFER_POOL_SIZE = 1024 * 256 / 4; // size of buffer pool 4GB
40- static constexpr int BUFFER_POOL_INSTANCE_SIZE = 8 ; // size of buffer pool instance
40+ static constexpr int BUFFER_POOL_INSTANCE_SIZE = 1 ; // size of buffer pool instance
4141static constexpr int LOG_BUFFER_SIZE = (1024 * PAGE_SIZE); // size of a log buffer in byte
4242static constexpr int BUCKET_SIZE = 50 ; // size of extendible hash bucket
4343
Original file line number Diff line number Diff line change @@ -13,9 +13,7 @@ See the Mulan PSL v2 for more details. */
1313extern DiskManager disk_manager;
1414
1515size_t BufferPoolManager::get_instance_no (const PageId& page_id) const {
16- // return hasher_(page_id) % BUFFER_POOL_INSTANCE_SIZE;
17- // ! 八个缓冲区的
18- return hasher_ (page_id) & 0x7 ;
16+ return std::hash<PageId>{}(page_id) % BUFFER_POOL_INSTANCE_SIZE;
1917}
2018
2119/* *
Original file line number Diff line number Diff line change @@ -32,13 +32,6 @@ class BufferPoolManager {
3232 private:
3333 size_t pool_size_; // 缓冲池大小(帧数)
3434 BufferPoolInstance* buffer_pool_instances_[BUFFER_POOL_INSTANCE_SIZE]; // 缓冲池实例数组
35-
36- struct PageIdHash {
37- size_t operator ()(const PageId &pid) const {
38- return static_cast <size_t >(pid.fd ) * 131 + static_cast <size_t >(pid.page_no );
39- }
40- };
41- PageIdHash hasher_; // 哈希函数,用于计算PageId的哈希值
4235
4336 public:
4437 BufferPoolManager (size_t pool_size) : pool_size_(pool_size) {
Original file line number Diff line number Diff line change @@ -177,9 +177,7 @@ void TransactionManager::abort(Context* context) {
177177}
178178
179179auto TransactionManager::GetVersionInfoShard (const PageId& page_id) -> PageVersionInfoShard& {
180- // return version_info_shards_[hasher_(page_id) % VERSION_INFO_SHARDS];
181- // 256个分片,使用哈希函数计算页ID的哈希值并取模
182- return version_info_shards_[hasher_ (page_id) & 0xFF ];
180+ return version_info_shards_[std::hash<PageId>{}(page_id) % VERSION_INFO_SHARDS];
183181}
184182
185183/* *
Original file line number Diff line number Diff line change @@ -42,13 +42,6 @@ class TransactionManager {
4242 // 保护事务表的读写锁
4343 std::shared_mutex txn_map_mutex_;
4444
45- struct PageIdHash {
46- size_t operator ()(const PageId &pid) const {
47- return static_cast <size_t >(pid.fd ) * 131 + static_cast <size_t >(pid.page_no );
48- }
49- };
50- PageIdHash hasher_; // 哈希函数,用于计算PageId的哈希值
51-
5245 // std::mutex commit_mutex_; // 用于提交事务时的互斥锁
5346
5447 /* *
You can’t perform that action at this time.
0 commit comments