mirror of
https://github.com/YuhangQ/InvoDB.git
synced 2025-01-28 23:50:59 +00:00
34 lines
729 B
C++
34 lines
729 B
C++
//
|
|
// Created by YuhangQ on 2021/9/24.
|
|
//
|
|
|
|
#include "page_manager.h"
|
|
|
|
int PageManager::loadDatabase(const char *filename) {
|
|
Instance().stream.open(filename);
|
|
return 0;
|
|
}
|
|
|
|
StoragePage PageManager::getPage(const int &index) {
|
|
StoragePage page(index);
|
|
// 调整指针位置
|
|
stream.clear();
|
|
stream.seekg(index * 1024);
|
|
stream.read(page, 1024);
|
|
return page;
|
|
}
|
|
|
|
void PageManager::setPage(const int &index, const StoragePage &page) {
|
|
stream.clear();
|
|
stream.seekg(index * 1024);
|
|
stream.write(page, 1024);
|
|
stream.flush();
|
|
}
|
|
|
|
int PageManager::allocate() {
|
|
stream.seekp(0, std::ios::end);
|
|
int index = stream.tellp() / 1024;
|
|
setPage(index, StoragePage(index));
|
|
return index;
|
|
}
|