InvoDB/invodb/io/page_manager.cpp

37 lines
726 B
C++
Raw Normal View History

2021-10-05 14:41:15 +08:00
//
// Created by YuhangQ on 2021/9/24.
//
#include "page_manager.h"
int PageManager::loadDatabase(const char *filename) {
stream.open(filename);
stream.flush();
return 0;
}
StoragePage& PageManager::getPage(const int &index) {
2021-10-05 16:02:01 +08:00
2021-10-05 14:41:15 +08:00
StoragePage page;
// 调整指针位置
2021-10-05 16:02:01 +08:00
stream.clear();
stream.seekg(index * 4096);
2021-10-05 14:41:15 +08:00
stream.read(page, 4096);
return page;
2021-10-05 16:02:01 +08:00
}
void PageManager::setPage(const int &index, const StoragePage &page) {
stream.clear();
stream.seekg(index * 4096);
stream.write(page, 4096);
}
void StoragePage::print() {
for(int i=0; i<16; i++) {
for(int j=0; j<256; j++) {
printf("%u ", page[i * 16 + j]);
}
printf("\n");
}
}