InvoDB/invodb/file/page_manager.cpp

34 lines
729 B
C++
Raw Normal View History

2021-10-11 22:05:45 +08:00
//
// 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) {
2021-10-23 16:28:57 +08:00
StoragePage page(index);
2021-10-11 22:05:45 +08:00
// 调整指针位置
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);
2021-10-26 12:29:59 +08:00
stream.flush();
2021-10-11 22:05:45 +08:00
}
2021-10-23 16:28:57 +08:00
int PageManager::allocate() {
stream.seekp(0, std::ios::end);
int index = stream.tellp() / 1024;
setPage(index, StoragePage(index));
return index;
2021-10-11 22:05:45 +08:00
}