btree benchmark

This commit is contained in:
YuhangQ 2021-10-28 23:44:50 +08:00
parent 7e59c8a421
commit db7b2bf33e
9 changed files with 32 additions and 11 deletions

View File

@ -3,6 +3,7 @@ project(InvoDB)
set(CMAKE_CXX_STANDARD 14)
include_directories(.)
include_directories(./invodb)

View File

@ -11,6 +11,9 @@ NodeUUID *NodeUUID::getNode(const int &address) {
delete map[address];
map[address] = new NodeUUID(address);
}
// if(map.count(address) == 0) {
// map[address] = new NodeUUID(address);
// }
return map[address];
}

View File

@ -29,7 +29,7 @@ public:
void clear();
void save();
//static const int m = 27;
static const int m = 3;
static const int m = 27;
static const int maxCount = m - 1;
static const int minLeafCount = m / 2;
static const int minLinkCount = (m - 1) / 2;

View File

@ -243,7 +243,7 @@ void BTreeUUID::remove(const std::string &uuid) {
}
void BTreeUUID::removeEntry(int curAddr, const std::string& uuid, const int& pointer) {
printf("---removeEntry: %d %s %d\n", curAddr, uuid.c_str(), pointer);
//printf("---removeEntry: %d %s %d\n", curAddr, uuid.c_str(), pointer);
NodeUUID* cur = NodeUUID::getNode(curAddr);
int pos = cur->findPos(uuid);
@ -270,7 +270,7 @@ void BTreeUUID::removeEntry(int curAddr, const std::string& uuid, const int& poi
if(cur->enough() || cur->address == root) return;
printf("em %d %d\n", cur->address, cur->size);
//printf("em %d %d\n", cur->address, cur->size);
if(canCoalesce(cur->address, cur->left)) {
@ -297,7 +297,7 @@ bool BTreeUUID::canCoalesce(int curAddr, int sibAddr) {
void BTreeUUID::coalesce(int curAddr, int sibAddr) {
printf("coalesce %d and %d\n", curAddr, sibAddr);
//printf("coalesce %d and %d\n", curAddr, sibAddr);
NodeUUID* cur = NodeUUID::getNode(curAddr);
NodeUUID* sib = NodeUUID::getNode(sibAddr);
@ -364,7 +364,7 @@ bool BTreeUUID::canRedistribute(int curAddr, int sibAddr) {
void BTreeUUID::redistribute(int curAddr, int sibAddr) {
printf("redistribute %d from %d\n", curAddr, sibAddr);
//printf("redistribute %d from %d\n", curAddr, sibAddr);
NodeUUID* cur = NodeUUID::getNode(curAddr);
NodeUUID* sib = NodeUUID::getNode(sibAddr);

View File

@ -7,6 +7,7 @@
#include <iostream>
#include <fstream>
#include <map>
#include "storage_page.h"
@ -22,6 +23,7 @@ public:
int allocate();
void free(const int &index);
private:
std::map<int, StoragePage> map;
std::fstream stream;
// 私有化实现单例
PageManager() {}

View File

@ -57,3 +57,7 @@ int StoragePage::getAddress() {
return address;
}
StoragePage::StoragePage() {
}

View File

@ -13,6 +13,7 @@ class PageManager;
class StoragePage {
public:
StoragePage();
void print();
int next();
void setNext(const int& nextPage);

View File

@ -11,7 +11,7 @@ void benchmark() {
std::vector<std::pair<std::string, int>> v;
const int n = 1000000;
const int n = 100000;
for(int i=0; i<n; i++) {
generateUUID(uuid);
@ -20,17 +20,29 @@ void benchmark() {
btree->insert(uuid, addr);
}
for(int i=0; i<1000000; i++) {
for(int i=0; i<100000; i++) {
std::swap(v[rand()%v.size()], v[rand()%v.size()]);
}
for(int i=0; i<v.size(); i++) {
int addr = btree->find(v[0].first);
if(addr != v[0].second) {
int addr = btree->find(v[i].first);
if(addr != v[i].second) {
printf("fuck\n");
exit(0);
}
}
for(int i=0; i<v.size(); i++) {
if(i < v.size() / 2) {
btree->remove(v[i].first);
} else {
int addr = btree->find(v[i].first);
if(addr != v[i].second) {
printf("fuck\n");
exit(0);
}
}
}
}
int main() {

View File

@ -70,8 +70,6 @@ Collection& Collection::createCollection(const std::string &name) {
page.print();
page.save();
Collection *col = new Collection(name, collectionPage);
map.insert(make_pair(name, col));